execute_mcp_client
Execute AI-driven commands to fetch data efficiently. Utilized for research purposes, enabling task delegation and context offloading within the MCP Inception MCP Server environment.
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 function for 'execute_mcp_client' tool that executes the provided command using safeCommandPipe and returns stdout or stderr, handling errors appropriately.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:210-219 (schema)Input schema definition for the 'execute_mcp_client' tool, specifying a required 'command' string parameter.inputSchema: { type: 'object', properties: { command: { type: 'string', description: 'The MCP client command to execute', }, }, required: ['command'], },
- src/index.ts:207-221 (registration)Tool registration in the ListTools response, including name, description, and input schema.{ 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:62-108 (helper)Core helper function safeCommandPipe that spawns the executable process, pipes input to stdin, captures stdout/stderr, and handles process lifecycle and errors. This is the actual implementation executing the MCP client.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(); }); }