|
1 | 1 | // src/index.ts
|
2 |
| -import { Server, StdioTransport } from "@modelcontextprotocol/sdk/server/index.js"; // <--- Try importing StdioTransport from here |
3 |
| -import { ListToolsRequestSchema, CallToolRequestSchema } from "@modelcontextprotocol/sdk/types.js"; |
| 2 | +import { Server } from "@modelcontextprotocol/sdk/server/index.js"; |
| 3 | +import { StdioTransport } from "@modelcontextprotocol/sdk/server/stdio.js"; // <-- Original path with .js |
| 4 | +import { ListToolsRequestSchema, CallToolRequestSchema, CallToolRequest } from "@modelcontextprotocol/sdk/types.js"; |
| 5 | +import { vibeCheckTool } from "./tools/vibeCheck.js"; // <-- Local import needs .js |
| 6 | +import { vibeDistillTool } from "./tools/vibeDistill.js"; // <-- Local import needs .js |
| 7 | +import { vibeLearnTool } from "./tools/vibeLearn.js"; // <-- Local import needs .js |
4 | 8 |
|
5 | 9 | // Create server with required parameters
|
6 |
| -const server = new Server({ |
| 10 | +const server = new Server({ // Leaving as is for now, hoping TS2554 resolves with other fixes |
7 | 11 | name: "vibe-check-mcp",
|
8 | 12 | version: "0.2.0"
|
9 | 13 | });
|
10 |
| -// Note: If the TS2554 error persists after fixing the import, |
11 |
| -// you might need to check the SDK v0.6.0 docs for the correct Server constructor signature. |
12 | 14 |
|
| 15 | +// Define tools using ListToolsRequestSchema handler |
13 | 16 | server.setRequestHandler(ListToolsRequestSchema, async () => ({
|
14 | 17 | tools: [
|
15 | 18 | {
|
16 | 19 | name: "vibe_check",
|
17 |
| - description: "Quick test tool", |
| 20 | + description: "Metacognitive check for plan alignment and assumption testing.", |
18 | 21 | inputSchema: {
|
19 | 22 | type: "object",
|
20 | 23 | properties: {
|
21 | 24 | plan: { type: "string" },
|
22 |
| - userRequest: { type: "string" } |
| 25 | + userRequest: { type: "string" }, |
| 26 | + thinkingLog: { type: "string" }, |
| 27 | + availableTools: { type: "array", items: { type: "string" } }, |
| 28 | + focusAreas: { type: "array", items: { type: "string" } }, |
| 29 | + sessionId: { type: "string" }, |
| 30 | + previousAdvice: { type: "string" }, |
| 31 | + phase: { type: "string", enum: ["planning", "implementation", "review"] }, |
| 32 | + confidence: { type: "number" } |
23 | 33 | },
|
24 | 34 | required: ["plan", "userRequest"]
|
25 | 35 | }
|
| 36 | + }, |
| 37 | + { |
| 38 | + name: "vibe_distill", |
| 39 | + description: "Distills a plan to its essential core.", |
| 40 | + inputSchema: { |
| 41 | + type: "object", |
| 42 | + properties: { |
| 43 | + plan: { type: "string" }, |
| 44 | + userRequest: { type: "string" }, |
| 45 | + sessionId: { type: "string" } |
| 46 | + }, |
| 47 | + required: ["plan", "userRequest"] |
| 48 | + } |
| 49 | + }, |
| 50 | + { |
| 51 | + name: "vibe_learn", |
| 52 | + description: "Logs mistake patterns for future improvement.", |
| 53 | + inputSchema: { |
| 54 | + type: "object", |
| 55 | + properties: { |
| 56 | + mistake: { type: "string" }, |
| 57 | + category: { type: "string" }, |
| 58 | + solution: { type: "string" }, |
| 59 | + sessionId: { type: "string" } |
| 60 | + }, |
| 61 | + required: ["mistake", "category", "solution"] |
| 62 | + } |
26 | 63 | }
|
27 |
| - // TODO: Add back your actual vibe_check, vibe_distill, vibe_learn tool definitions here |
28 | 64 | ]
|
29 | 65 | }));
|
30 | 66 |
|
31 |
| -// TODO: Add back your CallToolRequestSchema handler for the actual tools |
32 |
| -server.setRequestHandler(CallToolRequestSchema, async (request) => { |
33 |
| - // Replace this placeholder with your actual tool calling logic |
34 |
| - console.log("CallToolRequest:", request); |
35 |
| - if (request.toolName === 'vibe_check') { |
36 |
| - return { |
37 |
| - content: [{ type: "text", text: "✅ Test successful. This is a working vibe_check response." }] |
38 |
| - }; |
| 67 | +// Handle tool calls using CallToolRequestSchema handler |
| 68 | +server.setRequestHandler(CallToolRequestSchema, async (request: CallToolRequest) => { |
| 69 | + const toolName = request.params.name; // <-- Corrected access |
| 70 | + const args = request.params.arguments ?? {}; |
| 71 | + |
| 72 | + console.log(`CallToolRequest received for tool: ${toolName}`); |
| 73 | + |
| 74 | + try { |
| 75 | + let result: any; |
| 76 | + switch (toolName) { |
| 77 | + case 'vibe_check': |
| 78 | + result = await vibeCheckTool(args as any); |
| 79 | + return { content: [{ type: "text", text: result.questions + (result.patternAlert ? `\n\n**Pattern Alert:** ${result.patternAlert}`: "") }] }; |
| 80 | + case 'vibe_distill': |
| 81 | + result = await vibeDistillTool(args as any); |
| 82 | + return { content: [{ type: "markdown", markdown: result.distilledPlan + `\n\n**Rationale:** ${result.rationale}` }] }; |
| 83 | + case 'vibe_learn': |
| 84 | + result = await vibeLearnTool(args as any); |
| 85 | + const summary = result.topCategories.map(cat => `- ${cat.category} (${cat.count})`).join('\n'); |
| 86 | + return { content: [{ type: "text", text: `✅ Pattern logged. Tally for category: ${result.currentTally}.\nTop Categories:\n${summary}` }] }; |
| 87 | + default: |
| 88 | + throw new Error(`Tool '${toolName}' not found.`); |
| 89 | + } |
| 90 | + } catch (error: any) { |
| 91 | + console.error(`Error executing tool ${toolName}:`, error); |
| 92 | + return { |
| 93 | + error: { |
| 94 | + code: "tool_execution_error", |
| 95 | + message: `Error executing tool ${toolName}: ${error.message}` |
| 96 | + } |
| 97 | + }; |
39 | 98 | }
|
40 |
| - // Add handlers for vibe_distill and vibe_learn |
41 |
| - throw new Error(`Tool ${request.toolName} not found or handler not implemented.`); |
42 | 99 | });
|
43 | 100 |
|
44 | 101 | // Use StdioTransport for compatibility
|
45 |
| -const transport = new StdioTransport(); // Instantiation looks correct |
| 102 | +const transport = new StdioTransport(); |
46 | 103 | server.connect(transport);
|
47 | 104 |
|
48 |
| -console.log("Vibe Check MCP Server started using StdioTransport."); // Add a log message |
| 105 | +console.log("Vibe Check MCP Server started using StdioTransport."); |
0 commit comments