fix: async/await, eslint directive, and promise rejection in mcp-server.ts

This commit is contained in:
2025-12-16 13:38:37 -05:00
parent b520a20444
commit 0fe118f9e6

View File

@@ -38,9 +38,9 @@ export class MCPServer {
try { try {
switch (request.method) { switch (request.method) {
case 'initialize': case 'initialize':
return this.createSuccessResponse(request.id, await this.handleInitialize(request.params ?? {})); return this.createSuccessResponse(request.id, this.handleInitialize(request.params ?? {}));
case 'tools/list': case 'tools/list':
return this.createSuccessResponse(request.id, await this.handleListTools()); return this.createSuccessResponse(request.id, this.handleListTools());
case 'tools/call': case 'tools/call':
return this.createSuccessResponse(request.id, await this.handleCallTool(request.params ?? {})); return this.createSuccessResponse(request.id, await this.handleCallTool(request.params ?? {}));
case 'ping': case 'ping':
@@ -54,7 +54,7 @@ export class MCPServer {
} }
} }
private async handleInitialize(_params: JSONRPCParams): Promise<InitializeResult> { private handleInitialize(_params: JSONRPCParams): InitializeResult {
return { return {
protocolVersion: "2024-11-05", protocolVersion: "2024-11-05",
capabilities: { capabilities: {
@@ -67,15 +67,14 @@ export class MCPServer {
}; };
} }
private async handleListTools(): Promise<ListToolsResult> { private handleListTools(): ListToolsResult {
return { return {
tools: this.toolRegistry.getToolDefinitions() tools: this.toolRegistry.getToolDefinitions()
}; };
} }
private async handleCallTool(params: JSONRPCParams): Promise<CallToolResult> { private async handleCallTool(params: JSONRPCParams): Promise<CallToolResult> {
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Tool arguments come from JSON-RPC and need runtime validation const paramsObj = params as { name: string; arguments: Record<string, unknown> };
const paramsObj = params as { name: string; arguments: any };
return await this.toolRegistry.callTool(paramsObj.name, paramsObj.arguments); return await this.toolRegistry.callTool(paramsObj.name, paramsObj.arguments);
} }
@@ -114,7 +113,7 @@ export class MCPServer {
} }
}); });
} catch (error) { } catch (error) {
reject(error); reject(error instanceof Error ? error : new Error(String(error)));
} }
}); });
} }