execute-tool
Run a specific tool on an MCP server by providing the server ID, tool name, and required arguments to automate tasks or processes.
Instructions
Execute a tool on a server
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| args | No | The arguments to pass to the tool | |
| serverId | Yes | The ID of the server | |
| toolName | Yes | The name of the tool to execute |
Implementation Reference
- index.ts:615-637 (handler)Main handler implementation in ServerManager class. Retrieves the connected server by ID and proxies the tool call to it using the MCP client.callTool method.async executeToolOnServer( serverId: string, toolName: string, args: Record<string, any> ): Promise<any> { const server = this.servers.get(serverId); if (!server) { throw new Error(`Server ${serverId} not found`); } try { // Call the tool on the server using the MCP client const result = await server.client.callTool({ name: toolName, arguments: args, }); return result; } catch (error) { console.error(`Error executing tool on server ${serverId}:`, error); throw error; } }
- index.ts:1106-1129 (handler)Dispatcher handler in the main CallToolRequest handler. Validates arguments and calls ServerManager.executeToolOnServer.case "execute-tool": { const args = request.params .arguments as unknown as ExecuteToolArgs; if (!args.serverId || !args.toolName) { throw new Error( "Missing required arguments: serverId and toolName" ); } const result = await serverManager.executeToolOnServer( args.serverId, args.toolName, args.args || {} ); return { content: [ { type: "text", text: JSON.stringify(result), }, ], }; }
- index.ts:909-930 (schema)Tool object definition including name, description, and input schema for 'execute-tool'.const executeToolTool: Tool = { name: "execute-tool", description: "Execute a tool on a server", inputSchema: { type: "object", properties: { serverId: { type: "string", description: "The ID of the server", }, toolName: { type: "string", description: "The name of the tool to execute", }, args: { type: "object", description: "The arguments to pass to the tool", }, }, required: ["serverId", "toolName"], }, };
- index.ts:31-35 (schema)TypeScript interface defining the input arguments for the execute-tool.interface ExecuteToolArgs { serverId: string; toolName: string; args: Record<string, any>; }
- index.ts:1011-1022 (registration)Registration of the tool in the ListToolsRequest handler, where executeToolTool is included in the returned tools list.server.setRequestHandler(ListToolsRequestSchema, async () => { console.error("Received ListToolsRequest"); return { tools: [ createServerFromTemplateTool, executeToolTool, getServerToolsTool, deleteServerTool, listServersTool, ], }; });