fix(mcp): server runCommand not found (#157)

This commit is contained in:
sigoden
2025-01-04 16:49:50 +08:00
committed by GitHub
parent 32225dcf0f
commit e8d5d53f02
+3 -5
View File
@@ -9,9 +9,7 @@ import { Server } from "@modelcontextprotocol/sdk/server/index.js";
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js"; import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
import { import {
CallToolRequestSchema, CallToolRequestSchema,
ErrorCode,
ListToolsRequestSchema, ListToolsRequestSchema,
McpError,
} from "@modelcontextprotocol/sdk/types.js"; } from "@modelcontextprotocol/sdk/types.js";
let [rootDir, agentName] = process.argv.slice(2); let [rootDir, agentName] = process.argv.slice(2);
@@ -74,7 +72,7 @@ server.setRequestHandler(ListToolsRequestSchema, async () => {
server.setRequestHandler(CallToolRequestSchema, async (request) => { server.setRequestHandler(CallToolRequestSchema, async (request) => {
const functionObj = functions.find((f) => f.name === request.params.name); const functionObj = functions.find((f) => f.name === request.params.name);
if (!functionObj) { if (!functionObj) {
throw new McpError(ErrorCode.InvalidRequest, `Unexpected tool '${request.params.name}'`); throw new Error(`Unknown tool '${request.params.name}'`);
} }
let command = request.params.name; let command = request.params.name;
let args = [JSON.stringify(request.params.arguments || {})]; let args = [JSON.stringify(request.params.arguments || {})];
@@ -101,7 +99,7 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
}); });
function runCommand(command, args, env) { function runCommand(command, args, env) {
return new Promise((resolve, reject) => { return new Promise(resolve => {
const child = spawn(command, args, { const child = spawn(command, args, {
stdio: ['ignore', 'ignore', 'pipe'], stdio: ['ignore', 'ignore', 'pipe'],
env, env,
@@ -118,7 +116,7 @@ function runCommand(command, args, env) {
}); });
child.on('error', (err) => { child.on('error', (err) => {
reject(err); resolve({ exitCode: 1, stderr: `Command execution failed: ${err.message}` });
}); });
}); });
} }