Skip to content

Commit a047aa1

Browse files
authored
Update index.ts
1 parent aa248a6 commit a047aa1

File tree

1 file changed

+77
-20
lines changed

1 file changed

+77
-20
lines changed

src/index.ts

Lines changed: 77 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,105 @@
11
// 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
48

59
// 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
711
name: "vibe-check-mcp",
812
version: "0.2.0"
913
});
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.
1214

15+
// Define tools using ListToolsRequestSchema handler
1316
server.setRequestHandler(ListToolsRequestSchema, async () => ({
1417
tools: [
1518
{
1619
name: "vibe_check",
17-
description: "Quick test tool",
20+
description: "Metacognitive check for plan alignment and assumption testing.",
1821
inputSchema: {
1922
type: "object",
2023
properties: {
2124
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" }
2333
},
2434
required: ["plan", "userRequest"]
2535
}
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+
}
2663
}
27-
// TODO: Add back your actual vibe_check, vibe_distill, vibe_learn tool definitions here
2864
]
2965
}));
3066

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+
};
3998
}
40-
// Add handlers for vibe_distill and vibe_learn
41-
throw new Error(`Tool ${request.toolName} not found or handler not implemented.`);
4299
});
43100

44101
// Use StdioTransport for compatibility
45-
const transport = new StdioTransport(); // Instantiation looks correct
102+
const transport = new StdioTransport();
46103
server.connect(transport);
47104

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

Comments
 (0)