execute_mcp_client
Execute MCP client commands to offload AI research tasks, fetch data, and facilitate multi-agent interactions through task delegation.
Instructions
Offload certain tasks to AI. Used for research purposes, do not use for code editing or anything code related. Only used to fetch data.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| command | Yes | The MCP client command to execute |
Implementation Reference
- src/index.ts:274-297 (handler)Handler logic for the 'execute_mcp_client' tool. Parses the command argument, executes it via safeCommandPipe using the configured executable, and returns the stdout or stderr as text content, or an error response.case 'execute_mcp_client': { const args = request.params.arguments as { command: string }; try { const { stdout, stderr } = await this.safeCommandPipe(args.command, this.executable); return { content: [ { type: 'text', text: stdout || stderr, }, ], }; } catch (error: any) { return { content: [ { type: 'text', text: `Error executing MCP client command: ${error?.message || 'Unknown error'}`, }, ], isError: true, }; } }
- src/index.ts:207-220 (registration)Registration of the 'execute_mcp_client' tool in the ListTools response, including name, description, and input schema requiring a 'command' string.{ name: 'execute_mcp_client', description: 'Offload certain tasks to AI. Used for research purposes, do not use for code editing or anything code related. Only used to fetch data.', inputSchema: { type: 'object', properties: { command: { type: 'string', description: 'The MCP client command to execute', }, }, required: ['command'], }, },
- src/index.ts:210-219 (schema)Input schema definition for the 'execute_mcp_client' tool, specifying an object with a required 'command' string property.inputSchema: { type: 'object', properties: { command: { type: 'string', description: 'The MCP client command to execute', }, }, required: ['command'], },
- src/index.ts:62-108 (helper)Helper method that spawns the executable command process using spawn('/bin/bash'), pipes the input to stdin, captures stdout and stderr with debug logging, and resolves with output or rejects on error. Used by the tool handler.private async safeCommandPipe(input: string, command: string, forceJson: boolean = false): Promise<{stdout: string, stderr: string}> { return new Promise((resolve, reject) => { // Get the full path to the executable const executablePath = join(this.workingDirectory, this.executable); console.error(`[Debug] Executing: ${executablePath} in ${this.workingDirectory}`); const proc = spawn('/bin/bash', [executablePath], { shell: false, env: process.env, // Pass through environment variables cwd: this.workingDirectory // Use configured working directory }); let stdout = ''; let stderr = ''; proc.stdout.on('data', (data) => { const str = data.toString(); console.error(`[Debug] stdout: ${str}`); stdout += str; }); proc.stderr.on('data', (data) => { const str = data.toString(); console.error(`[Debug] stderr: ${str}`); stderr += str; }); proc.on('error', (err) => { console.error(`[Debug] Process error: ${err.message}`); reject(new Error(`Failed to start process: ${err.message}`)); }); proc.on('close', (code) => { console.error(`[Debug] Process exited with code ${code}`); if (code === 0) { resolve({ stdout, stderr }); } else { reject(new Error(`Command failed with code ${code}. stderr: ${stderr}`)); } }); // Safely write input with newline and close stdin // If forceJson is true, append a directive to return JSON const inputWithDirective = forceJson ? input + ' [RESPOND IN JSON KEY-VALUE PAIRS]' : input; proc.stdin.write(Buffer.from(inputWithDirective + '\n')); proc.stdin.end(); }); }