execute
Execute MCP tools from 100+ services through a unified gateway by specifying service, tool, and parameters for integrated operations.
Instructions
execute tool
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| service | Yes | ||
| tool | Yes | ||
| parameters | Yes |
Implementation Reference
- src/tools/execute.ts:11-60 (handler)The async handler function that implements the core logic of the 'execute' tool: validates tool existence, calls the target tool via GatewayClient, formats results, and handles errors.handler: async (args: any, client: GatewayClient) => { try { // Validate that tool exists const tools = await client.listTools(); const tool = tools.find(t => t.name === args.tool_name); if (!tool) { return { content: [{ type: 'text' as const, text: `Tool "${args.tool_name}" not found. Use the "search" tool to discover available tools.`, }], isError: true, }; } // Execute the tool const result = await client.callTool(args.tool_name, args.arguments || {}); // Format the result if (result.content) { // MCP standard response format return result; } else if (typeof result === 'object') { // Convert object result to text return { content: [{ type: 'text' as const, text: JSON.stringify(result, null, 2), }], }; } else { // Simple value result return { content: [{ type: 'text' as const, text: String(result), }], }; } } catch (error) { return { content: [{ type: 'text' as const, text: `Error executing tool "${args.tool_name}": ${error instanceof Error ? error.message : 'Unknown error'}`, }], isError: true, }; } },
- src/tools/execute.ts:7-10 (schema)The Zod input schema defining parameters for the 'execute' tool: required 'tool_name' and optional 'arguments'.inputSchema: z.object({ tool_name: z.string().describe('Name of the tool to execute (use the search tool to discover available tools)'), arguments: z.record(z.any()).optional().describe('Tool-specific parameters as a JSON object. Each tool has different required and optional parameters.'), }),
- src/tools/execute.ts:4-61 (registration)The complete tool definition object exported as 'executeTool', registering the tool's metadata, schema, and handler for use in an MCP-compatible framework.export const executeTool = { name: 'execute', description: 'Execute any tool from any connected MCP server. First use the "search" tool to discover available tools and their parameters.', inputSchema: z.object({ tool_name: z.string().describe('Name of the tool to execute (use the search tool to discover available tools)'), arguments: z.record(z.any()).optional().describe('Tool-specific parameters as a JSON object. Each tool has different required and optional parameters.'), }), handler: async (args: any, client: GatewayClient) => { try { // Validate that tool exists const tools = await client.listTools(); const tool = tools.find(t => t.name === args.tool_name); if (!tool) { return { content: [{ type: 'text' as const, text: `Tool "${args.tool_name}" not found. Use the "search" tool to discover available tools.`, }], isError: true, }; } // Execute the tool const result = await client.callTool(args.tool_name, args.arguments || {}); // Format the result if (result.content) { // MCP standard response format return result; } else if (typeof result === 'object') { // Convert object result to text return { content: [{ type: 'text' as const, text: JSON.stringify(result, null, 2), }], }; } else { // Simple value result return { content: [{ type: 'text' as const, text: String(result), }], }; } } catch (error) { return { content: [{ type: 'text' as const, text: `Error executing tool "${args.tool_name}": ${error instanceof Error ? error.message : 'Unknown error'}`, }], isError: true, }; } }, };