Skip to content

Commit 7b755b2

Browse files
authored
Update index.ts
1 parent 80e2058 commit 7b755b2

File tree

1 file changed

+131
-93
lines changed

1 file changed

+131
-93
lines changed

src/index.ts

Lines changed: 131 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -1,109 +1,147 @@
11
// src/index.ts
22
import { Server } from "@modelcontextprotocol/sdk/server/index.js";
3-
import { tools } from "@modelcontextprotocol/sdk/server/tools";
43
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
4+
5+
import {
6+
ListToolsRequestSchema,
7+
CallToolRequestSchema,
8+
CallToolRequest,
9+
ListToolsResponse,
10+
} from "@modelcontextprotocol/sdk/types.js";
11+
512
import { z } from "zod";
613

7-
import { vibeCheckTool, VibeCheckInput } from "./tools/vibeCheck.js";
8-
import { vibeDistillTool, VibeDistillInput } from "./tools/vibeDistill.js";
9-
import { vibeLearnTool, VibeLearnInput } from "./tools/vibeLearn.js";
10-
import { initializeGemini } from "./utils/gemini.js";
14+
import {
15+
vibeCheckTool,
16+
VibeCheckInput,
17+
VibeCheckOutput
18+
} from "./tools/vibeCheck.js";
19+
20+
import {
21+
vibeDistillTool,
22+
VibeDistillInput,
23+
VibeDistillOutput
24+
} from "./tools/vibeDistill.js";
1125

12-
(async () => {
13-
console.error("MCP Server: Starting…");
26+
import {
27+
vibeLearnTool,
28+
VibeLearnInput,
29+
VibeLearnOutput
30+
} from "./tools/vibeLearn.js";
1431

15-
// — init Gemini if you have an API key
16-
const apiKey = process.env.GEMINI_API_KEY;
17-
if (!apiKey) {
18-
console.error("MCP Server: ⚠️ GEMINI_API_KEY not set; tools may fail");
32+
// ───────────────────────────────────────────────────────────
33+
// 1  Gemini (optional)
34+
// ───────────────────────────────────────────────────────────
35+
try {
36+
if (process.env.GEMINI_API_KEY) {
37+
// your initializeGemini(...) helper here
38+
console.error("[LOG] Gemini initialised");
1939
} else {
20-
try {
21-
initializeGemini(apiKey);
22-
console.error("MCP Server: Gemini initialized");
23-
} catch (e) {
24-
console.error("MCP Server: Error initializing Gemini:", e);
25-
}
40+
console.error("[WARN] GEMINI_API_KEY not set – Gemini‑based tools will fail");
2641
}
42+
} catch (err) {
43+
console.error("[ERR ] Gemini init failed:", err);
44+
}
2745

28-
// — create the lean base server…
29-
const base = new Server({ name: "vibe-check-mcp", version: "0.2.0" });
30-
// — …then enhance it with tools support
31-
const server = tools(base);
46+
// ───────────────────────────────────────────────────────────
47+
// 2  Create Server (+ declare “tools” capability)
48+
// ───────────────────────────────────────────────────────────
49+
const server = new Server({
50+
name: "vibe-check-mcp",
51+
version: "0.2.0",
52+
capabilities: { tools: {} } // ← ■■■ IMPORTANT ■■■
53+
});
3254

33-
// — register your tools…
55+
// ───────────────────────────────────────────────────────────
56+
// 3  tools/list → return static descriptors
57+
// ───────────────────────────────────────────────────────────
58+
const toolList: ListToolsResponse["tools"] = [
59+
{
60+
name: "vibe_check",
61+
description: "Metacognitive check for plan alignment and assumption testing.",
62+
inputSchema: z.object({
63+
plan: z.string(),
64+
userRequest: z.string(),
65+
thinkingLog: z.string().optional(),
66+
phase: z.enum(["planning","implementation","review"]).optional()
67+
})
68+
},
69+
{
70+
name: "vibe_distill",
71+
description: "Distils a plan to its essential core.",
72+
inputSchema: z.object({
73+
plan: z.string(),
74+
userRequest: z.string()
75+
})
76+
},
77+
{
78+
name: "vibe_learn",
79+
description: "Logs mistake patterns for future improvement.",
80+
inputSchema: z.object({
81+
mistake: z.string(),
82+
category: z.string(),
83+
solution: z.string()
84+
})
85+
}
86+
];
3487

35-
server.tool(
36-
"vibe_check",
37-
z
38-
.object({
39-
plan: z.string(),
40-
userRequest: z.string(),
41-
thinkingLog: z.string().optional(),
42-
phase: z.enum(["planning","implementation","review"]).optional(),
43-
})
44-
.required({ plan: true, userRequest: true }),
45-
async (args: VibeCheckInput) => {
46-
console.error("MCP Server: running vibe_check…");
47-
const out = await vibeCheckTool(args);
48-
return {
49-
content: [{
50-
type: "text",
51-
text: out.questions +
52-
(out.patternAlert
53-
? `\n\n**Pattern Alert:** ${out.patternAlert}`
54-
: "")
55-
}]
56-
};
57-
}
58-
);
88+
server.setRequestHandler(ListToolsRequestSchema, async () => ({ tools: toolList }));
5989

60-
server.tool(
61-
"vibe_distill",
62-
z
63-
.object({
64-
plan: z.string(),
65-
userRequest: z.string(),
66-
})
67-
.required({ plan: true, userRequest: true }),
68-
async (args: VibeDistillInput) => {
69-
console.error("MCP Server: running vibe_distill…");
70-
const out = await vibeDistillTool(args);
71-
return {
72-
content: [{
73-
type: "markdown",
74-
markdown: `${out.distilledPlan}\n\n**Rationale:** ${out.rationale}`
75-
}]
76-
};
77-
}
78-
);
90+
// ───────────────────────────────────────────────────────────
91+
// 4  tools/call → dispatch to real implementations
92+
// ───────────────────────────────────────────────────────────
93+
server.setRequestHandler(
94+
CallToolRequestSchema,
95+
async (req: CallToolRequest) => {
96+
const { name, arguments: argsRaw = {} } = req.params;
97+
98+
switch (name) {
99+
case "vibe_check": {
100+
const args = argsRaw as VibeCheckInput;
101+
const out: VibeCheckOutput = await vibeCheckTool(args);
102+
return {
103+
content: [{
104+
type: "text",
105+
text: out.questions +
106+
(out.patternAlert ? `\n\n**Pattern Alert:** ${out.patternAlert}` : "")
107+
}]
108+
};
109+
}
110+
111+
case "vibe_distill": {
112+
const args = argsRaw as VibeDistillInput;
113+
const out: VibeDistillOutput = await vibeDistillTool(args);
114+
return {
115+
content: [{
116+
type: "markdown",
117+
markdown: `${out.distilledPlan}\n\n**Rationale:** ${out.rationale}`
118+
}]
119+
};
120+
}
79121

80-
server.tool(
81-
"vibe_learn",
82-
z
83-
.object({
84-
mistake: z.string(),
85-
category: z.string(),
86-
solution: z.string(),
87-
})
88-
.required({ mistake: true, category: true, solution: true }),
89-
async (args: VibeLearnInput) => {
90-
console.error("MCP Server: running vibe_learn…");
91-
const out = await vibeLearnTool(args);
92-
const summary = out.topCategories
93-
.map(c => `- ${c.category} (${c.count})`)
94-
.join("\n");
95-
return {
96-
content: [{
97-
type: "text",
98-
text: `✅ Logged. Current tally: ${out.currentTally}\n\n${summary}`
99-
}]
100-
};
122+
case "vibe_learn": {
123+
const args = argsRaw as VibeLearnInput;
124+
const out: VibeLearnOutput = await vibeLearnTool(args);
125+
const summary = out.topCategories
126+
.map(c => `- ${c.category} (${c.count})`)
127+
.join("\n");
128+
return {
129+
content: [{
130+
type: "text",
131+
text: `✅ Logged. Current tally: ${out.currentTally}\n\n${summary}`
132+
}]
133+
};
134+
}
135+
136+
default:
137+
throw new Error(`Unknown tool "${name}"`);
101138
}
102-
);
139+
}
140+
);
103141

104-
// — wire up STDIO transport
105-
console.error("MCP Server: connecting transport…");
106-
const transport = new StdioServerTransport();
107-
await server.connect(transport);
108-
console.error("MCP Server: ready (stdio)");
109-
})();
142+
// ───────────────────────────────────────────────────────────
143+
// 5  STDIO transport hookup
144+
// ───────────────────────────────────────────────────────────
145+
const transport = new StdioServerTransport();
146+
await server.connect(transport);
147+
console.error("[OK ] vibe‑check‑mcp ready (stdio)");

0 commit comments

Comments
 (0)