Skip to content

Commit b9a631c

Browse files
authored
Update index.ts (Docker fixing logs)
1 parent 8850fa5 commit b9a631c

File tree

1 file changed

+87
-35
lines changed

1 file changed

+87
-35
lines changed

src/index.ts

Lines changed: 87 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,38 @@
11
// src/index.ts
22
import { Server } from "@modelcontextprotocol/sdk/server/index.js";
33
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
4-
import { ListToolsRequestSchema, CallToolRequestSchema, CallToolRequest, InitializeRequest } from "@modelcontextprotocol/sdk/types.js"; // Added InitializeRequest
4+
import {
5+
ListToolsRequestSchema,
6+
CallToolRequestSchema,
7+
CallToolRequest,
8+
InitializeRequest,
9+
InitializeRequestSchema, // <-- Import InitializeRequestSchema
10+
ToolDefinition // <-- Import ToolDefinition
11+
} from "@modelcontextprotocol/sdk/types.js";
512
import { vibeCheckTool } from "./tools/vibeCheck.js";
613
import { vibeDistillTool } from "./tools/vibeDistill.js";
714
import { vibeLearnTool, VibeLearnOutput } from "./tools/vibeLearn.js";
815
import { MistakeEntry } from "./utils/storage.js";
9-
import { initializeGemini } from "./utils/gemini.js"; // Import gemini initializer
16+
import { initializeGemini } from "./utils/gemini.js";
1017

11-
console.error("MCP Server: Script starting..."); // Log to stderr
18+
console.error("MCP Server: Script starting...");
1219

1320
// --- Explicitly Initialize Gemini ---
1421
try {
15-
const apiKey = process.env.GEMINI_API_KEY; // Read from env var
22+
const apiKey = process.env.GEMINI_API_KEY;
1623
if (!apiKey) {
17-
console.error("MCP Server: ERROR - GEMINI_API_KEY environment variable not found!");
18-
// Optionally exit if the key is absolutely required at startup
19-
// process.exit(1);
24+
console.error("MCP Server: WARNING - GEMINI_API_KEY environment variable not found!");
25+
// Continue without Gemini if key is missing, tools might fail later
2026
} else {
2127
initializeGemini(apiKey);
22-
console.error("MCP Server: Gemini client potentially initialized (check gemini.ts logs).");
28+
console.error("MCP Server: Gemini client potentially initialized.");
2329
}
2430
} catch (err: any) {
2531
console.error("MCP Server: ERROR initializing Gemini client -", err);
26-
// Optionally exit
27-
// process.exit(1);
32+
// Continue anyway, tools using it will fail
2833
}
2934
// ------------------------------------
3035

31-
3236
// Define the type for the 'cat' parameter explicitly
3337
type CategorySummaryItem = {
3438
category: string;
@@ -44,47 +48,90 @@ const server = new Server({
4448
});
4549
console.error("MCP Server: Server instance created.");
4650

47-
// --- Add an explicit Initialize handler for logging ---
48-
server.setRequestHandler("initialize", async (request: InitializeRequest) => {
49-
console.error(`MCP Server: Received initialize request: ID=${request.id}`);
50-
// Basic response - the SDK might override parts of this, but it confirms handling
51+
// --- Add an explicit Initialize handler ---
52+
// Use the Schema as the first argument, not the string "initialize"
53+
server.setRequestHandler(InitializeRequestSchema, async (request: InitializeRequest) => {
54+
// Cannot reliably log request.id here based on type errors
55+
console.error(`MCP Server: Received initialize request`);
5156
const response = {
52-
protocolVersion: "2024-11-05", // Use the version client sent or latest known
57+
protocolVersion: request.params.protocolVersion, // Echo back client's version
5358
serverInfo: {
5459
name: "vibe-check-mcp",
5560
version: "0.2.0",
5661
},
57-
capabilities: {
58-
// Declare capabilities if needed, e.g., for notifications
59-
}
62+
capabilities: {}
6063
};
61-
console.error(`MCP Server: Sending initialize response for ID=${request.id}`);
64+
console.error(`MCP Server: Sending initialize response`);
6265
return response;
6366
});
6467
// -----------------------------------------------------
6568

66-
6769
// Define tools using ListToolsRequestSchema handler
6870
console.error("MCP Server: Setting ListTools request handler...");
6971
server.setRequestHandler(ListToolsRequestSchema, async () => {
7072
console.error("MCP Server: ListTools request received.");
71-
// Your tool definitions...
72-
const tools = [ /* ... your tool definitions from previous code ... */ ];
73+
// Explicitly type the tools array
74+
const tools: ToolDefinition[] = [
75+
{
76+
name: "vibe_check",
77+
description: "Metacognitive check for plan alignment and assumption testing.",
78+
inputSchema: {
79+
type: "object",
80+
properties: {
81+
plan: { type: "string" },
82+
userRequest: { type: "string" },
83+
thinkingLog: { type: "string" },
84+
availableTools: { type: "array", items: { type: "string" } },
85+
focusAreas: { type: "array", items: { type: "string" } },
86+
sessionId: { type: "string" },
87+
previousAdvice: { type: "string" },
88+
phase: { type: "string", enum: ["planning", "implementation", "review"] },
89+
confidence: { type: "number" }
90+
},
91+
required: ["plan", "userRequest"]
92+
}
93+
},
94+
{
95+
name: "vibe_distill",
96+
description: "Distills a plan to its essential core.",
97+
inputSchema: {
98+
type: "object",
99+
properties: {
100+
plan: { type: "string" },
101+
userRequest: { type: "string" },
102+
sessionId: { type: "string" }
103+
},
104+
required: ["plan", "userRequest"]
105+
}
106+
},
107+
{
108+
name: "vibe_learn",
109+
description: "Logs mistake patterns for future improvement.",
110+
inputSchema: {
111+
type: "object",
112+
properties: {
113+
mistake: { type: "string" },
114+
category: { type: "string" },
115+
solution: { type: "string" },
116+
sessionId: { type: "string" }
117+
},
118+
required: ["mistake", "category", "solution"]
119+
}
120+
}
121+
];
73122
console.error("MCP Server: Returning tool list.");
74-
return { tools };
123+
return { tools }; // Type 'tools' variable here
75124
});
76125
console.error("MCP Server: ListTools request handler set.");
77126

78-
79127
// Handle tool calls using CallToolRequestSchema handler
80128
console.error("MCP Server: Setting CallTool request handler...");
81129
server.setRequestHandler(CallToolRequestSchema, async (request: CallToolRequest) => {
82130
const toolName = request.params.name;
83131
const args = request.params.arguments ?? {};
84132

85-
// Log received request details to stderr
86-
console.error(`MCP Server: CallToolRequest received for tool: ${toolName} with ID: ${request.id}`);
87-
// console.error(`MCP Server: Args: ${JSON.stringify(args)}`); // Be careful logging args if sensitive
133+
// Cannot reliably log request.id here based on type errors
134+
console.error(`MCP Server: CallToolRequest received for tool: ${toolName}`);
88135

89136
try {
90137
let result: any;
@@ -94,7 +141,15 @@ server.setRequestHandler(CallToolRequestSchema, async (request: CallToolRequest)
94141
result = await vibeCheckTool(args as any);
95142
console.error(`MCP Server: Tool ${toolName} executed successfully.`);
96143
return { content: [{ type: "text", text: result.questions + (result.patternAlert ? `\n\n**Pattern Alert:** ${result.patternAlert}`: "") }] };
97-
// ... other cases ...
144+
case 'vibe_distill':
145+
result = await vibeDistillTool(args as any);
146+
console.error(`MCP Server: Tool ${toolName} executed successfully.`);
147+
return { content: [{ type: "markdown", markdown: result.distilledPlan + `\n\n**Rationale:** ${result.rationale}` }] };
148+
case 'vibe_learn':
149+
result = await vibeLearnTool(args as any) as VibeLearnOutput;
150+
console.error(`MCP Server: Tool ${toolName} executed successfully.`);
151+
const summary = result.topCategories.map((cat: CategorySummaryItem) => `- ${cat.category} (${cat.count})`).join('\n');
152+
return { content: [{ type: "text", text: `✅ Pattern logged. Tally for category: ${result.currentTally}.\nTop Categories:\n${summary}` }] };
98153
default:
99154
console.error(`MCP Server: Tool '${toolName}' not found.`);
100155
throw new Error(`Tool '${toolName}' not found.`);
@@ -111,7 +166,6 @@ server.setRequestHandler(CallToolRequestSchema, async (request: CallToolRequest)
111166
});
112167
console.error("MCP Server: CallTool request handler set.");
113168

114-
115169
// Create the transport instance
116170
console.error("MCP Server: Creating StdioServerTransport...");
117171
const transport = new StdioServerTransport();
@@ -122,10 +176,8 @@ console.error("MCP Server: Connecting server to transport...");
122176
server.connect(transport);
123177
console.error("MCP Server: Server connected to transport. Ready for messages.");
124178

125-
// Optional: Add listeners for transport errors/close events
126-
transport.onDidClose(() => {
179+
// Use the corrected event name 'onclose'
180+
transport.onclose(() => { // <-- Corrected event name
127181
console.error("MCP Server: Transport closed event received.");
128182
});
129-
transport.onDidDispose(() => {
130-
console.error("MCP Server: Transport disposed event received.");
131-
});
183+
// Removed listener for non-existent onDidDispose

0 commit comments

Comments
 (0)