Skip to content

Commit 265e251

Browse files
authored
Update index.ts
1 parent 2ac96b4 commit 265e251

File tree

1 file changed

+40
-34
lines changed

1 file changed

+40
-34
lines changed

src/index.ts

Lines changed: 40 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
1-
// src/index.ts --------------------------------------------------------------
21
import { Server } from "@modelcontextprotocol/sdk/server/index.js";
32
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
4-
53
import {
64
InitializeRequestSchema,
75
ListToolsRequestSchema,
86
CallToolRequestSchema,
97
CallToolRequest
108
} from "@modelcontextprotocol/sdk/types.js";
11-
129
import { z } from "zod";
1310

1411
import {
@@ -21,21 +18,23 @@ import {
2118
vibeLearnTool, VibeLearnInput, VibeLearnOutput
2219
} from "./tools/vibeLearn.js";
2320

24-
/* --------------------------------------------------------------------- */
25-
/* 0. optional Gemini startup */
26-
/* --------------------------------------------------------------------- */
21+
// ────────────────────────────────
22+
// 0. optional Gemini startup
23+
// ────────────────────────────────
2724
if (process.env.GEMINI_API_KEY) {
2825
try {
2926
// initializeGemini(process.env.GEMINI_API_KEY);
3027
console.error("[LOG] Gemini initialised");
3128
} catch (e) {
3229
console.error("[ERR] Gemini init failed:", e);
3330
}
31+
} else {
32+
console.error("[WARN] GEMINI_API_KEY not set – Gemini tools will fail");
3433
}
3534

36-
/* --------------------------------------------------------------------- */
37-
/* 1. Zod schemas (single source of truth) */
38-
/* --------------------------------------------------------------------- */
35+
// ────────────────────────────────
36+
// 1. Zod schemas
37+
// ────────────────────────────────
3938
const vibeCheckSchema = z.object({
4039
plan: z.string(),
4140
userRequest: z.string(),
@@ -52,71 +51,78 @@ const vibeLearnSchema = z.object({
5251
solution: z.string()
5352
});
5453

55-
/* --------------------------------------------------------------------- */
56-
/* 2. create Server with tools capability */
57-
/* --------------------------------------------------------------------- */
54+
// ────────────────────────────────
55+
// 2. Server with tools capability
56+
// ────────────────────────────────
5857
const server = new Server({
5958
name: "vibe-check-mcp",
6059
version: "0.2.0",
6160
capabilities: { tools: {} }
6261
});
6362

64-
/* --------------------------------------------------------------------- */
65-
/* 3. initialize handler – MUST reply within 30 s */
66-
/* --------------------------------------------------------------------- */
63+
// ────────────────────────────────
64+
// 3. initialize handler
65+
// ────────────────────────────────
6766
server.setRequestHandler(InitializeRequestSchema, async req => ({
6867
protocolVersion: req.params.protocolVersion,
6968
serverInfo: { name: "vibe-check-mcp", version: "0.2.0" },
70-
capabilities: server.capabilities // echoes { tools: {} }
69+
capabilities: { tools: {} } // ← fixed line
7170
}));
7271

73-
/* --------------------------------------------------------------------- */
74-
/* 4. tools/list handler – static descriptors */
75-
/* --------------------------------------------------------------------- */
72+
// ────────────────────────────────
73+
// 4. tools/list handler
74+
// ────────────────────────────────
7675
const toolList = [
7776
{ name: "vibe_check", description: "Metacognitive check …", inputSchema: vibeCheckSchema },
7877
{ name: "vibe_distill",description: "Distils a plan …", inputSchema: vibeDistillSchema },
7978
{ name: "vibe_learn", description: "Logs mistake patterns", inputSchema: vibeLearnSchema }
8079
];
8180
server.setRequestHandler(ListToolsRequestSchema, async () => ({ tools: toolList }));
8281

83-
/* --------------------------------------------------------------------- */
84-
/* 5. tools/call dispatcher */
85-
/* --------------------------------------------------------------------- */
82+
// ────────────────────────────────
83+
// 5. tools/call dispatcher
84+
// ────────────────────────────────
8685
server.setRequestHandler(CallToolRequestSchema, async (req: CallToolRequest) => {
8786
const { name, arguments: raw = {} } = req.params;
8887

8988
switch (name) {
9089
case "vibe_check": {
9190
const args: VibeCheckInput = vibeCheckSchema.parse(raw);
9291
const out: VibeCheckOutput = await vibeCheckTool(args);
93-
return { content:[{ type:"text",
94-
text: out.questions + (out.patternAlert ? `\n\n**Pattern Alert:** ${out.patternAlert}` : "")
95-
}]};
92+
return {
93+
content:[{ type:"text",
94+
text: out.questions +
95+
(out.patternAlert ? `\n\n**Pattern Alert:** ${out.patternAlert}` : "")
96+
}]
97+
};
9698
}
9799
case "vibe_distill": {
98100
const args: VibeDistillInput = vibeDistillSchema.parse(raw);
99101
const out: VibeDistillOutput = await vibeDistillTool(args);
100-
return { content:[{ type:"markdown",
101-
markdown: `${out.distilledPlan}\n\n**Rationale:** ${out.rationale}`
102-
}]};
102+
return {
103+
content:[{ type:"markdown",
104+
markdown: `${out.distilledPlan}\n\n**Rationale:** ${out.rationale}`
105+
}]
106+
};
103107
}
104108
case "vibe_learn": {
105109
const args: VibeLearnInput = vibeLearnSchema.parse(raw);
106110
const out: VibeLearnOutput = await vibeLearnTool(args);
107111
const summary = out.topCategories.map(c => `- ${c.category} (${c.count})`).join("\n");
108-
return { content:[{ type:"text",
109-
text:`✅ Logged. Current tally: ${out.currentTally}\n\n${summary}`
110-
}]};
112+
return {
113+
content:[{ type:"text",
114+
text:`✅ Logged. Current tally: ${out.currentTally}\n\n${summary}`
115+
}]
116+
};
111117
}
112118
default:
113119
throw new Error(`Unknown tool "${name}"`);
114120
}
115121
});
116122

117-
/* --------------------------------------------------------------------- */
118-
/* 6. connect via STDIO */
119-
/* --------------------------------------------------------------------- */
123+
// ────────────────────────────────
124+
// 6. STDIO transport
125+
// ────────────────────────────────
120126
const transport = new StdioServerTransport();
121127
await server.connect(transport);
122128
console.error("[OK] vibe‑check‑mcp ready (stdio)");

0 commit comments

Comments
 (0)