execute
Execute commands in MCP, RPC, or RUN contexts to analyze Node.js applications via Chrome Debug Protocol for runtime type validation.
Instructions
Execute a command in the specified context (MCP, RPC, or RUN)
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| context | Yes | Execution context: MCP (local), RPC (remote/CDP), or RUN (VS Code HTTP) | |
| command | Yes | Command name to execute | |
| message | Yes | Command Message or string of arguments, or empty string |
Implementation Reference
- src/server.ts:32-83 (handler)This function handles the execution logic for commands, either by requiring them (if they export a 'run' function) or by evaluating them as an IIFE within a context.
async function executeCommand ( filePath: string, args: unknown ): Promise<unknown> { if (!fs.existsSync(filePath)) { throw new Error(`Command file not found: ${filePath}`); } // Read the code first to check pattern const code = fs.readFileSync(filePath, 'utf-8'); // Build context - passed to command // eslint-disable-next-line @typescript-eslint/no-explicit-any const g = global as Record<string, any>; const ctx: any = { require, store: g.StrategyMCP, args, } as unknown; // If it has module.exports with run function, use require if (isLocalCommand(code)) { // Clear require cache to allow reloading delete require.cache[require.resolve(filePath)]; // Require the module // eslint-disable-next-line @typescript-eslint/no-var-requires const commandModule = require(filePath); if (typeof commandModule.run === 'function') { return await commandModule.run(ctx); } throw new Error(`Command does not export a 'run' function`); } // Otherwise, treat as remote-style IIFE command // Wrap it to capture the result - always wrap in async IIFE const wrappedBody = ` return (async function() { ${code} })(); `; // Execute in a sandbox-like way using Function with ctx parameter // eslint-disable-next-line @typescript-eslint/no-var-requires const fn = new Function('ctx', wrappedBody); const result = fn(ctx); // Always await the result since we wrap in async IIFE return await result; } - src/server.ts:125-147 (registration)Registration of the 'execute' tool within the MCP server.
{ name: 'execute', description: 'Execute a command in the specified context (MCP, RPC, or RUN)', inputSchema: { type: 'object', properties: { context: { type: 'string', enum: ['MCP', 'RPC', 'RUN'], description: 'Execution context: MCP (local), RPC (remote/CDP), or RUN (VS Code HTTP)', }, command: { type: 'string', description: 'Command name to execute', }, message: { type: 'string', description: 'Command Message or string of arguments, or empty string', }, }, required: ['context', 'command', 'message'], }, }, - src/server.ts:189-226 (handler)The handler logic for the 'execute' tool inside the CallToolRequest switch statement.
case 'execute': { console.error('[SERVER DEBUG] request.params:', JSON.stringify(request.params)); const { context, command } = args as { context: CommandContext; command: string; } & unknown; if (!context || !command) { return { content: [{ type: 'text', text: 'Error: context and command are required' }], isError: true, }; } // Get command file path const filePath = getCommandPath(context, command); if (!filePath) { return { content: [{ type: 'text', text: `Error: Command '${command}' not found in context '${context}'` }], isError: true, }; } // Execute command try { const result = await executeCommand(filePath, args); const text = result !== undefined ? JSON.stringify(result, null, 2) : 'Command executed (no return value)'; return { content: [{ type: 'text', text }], }; } catch (e) { return { content: [{ type: 'text', text: `Error executing command: ${e instanceof Error ? e.message : String(e)}` }], isError: true, }; } }