execute_command
Execute terminal commands with timeout control, allowing background continuation for long-running operations.
Instructions
Execute a terminal command with timeout. Command will continue running in background if it doesn't complete within timeout.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| command | Yes | ||
| timeout_ms | No |
Implementation Reference
- src/tools/execute.ts:5-28 (handler)The core handler function for the 'execute_command' tool. Parses input arguments, validates the command, executes via terminalManager, and formats the response with PID and initial output.export async function executeCommand(args: unknown) { const parsed = ExecuteCommandArgsSchema.safeParse(args); if (!parsed.success) { throw new Error(`Invalid arguments for execute_command: ${parsed.error}`); } if (!commandManager.validateCommand(parsed.data.command)) { throw new Error(`Command not allowed: ${parsed.data.command}`); } const result = await terminalManager.executeCommand( parsed.data.command, parsed.data.timeout_ms ); return { content: [{ type: "text", text: `Command started with PID ${result.pid}\nInitial output:\n${result.output}${ result.isBlocked ? '\nCommand is still running. Use read_output to get more output.' : '' }` }], }; }
- src/tools/schemas.ts:4-7 (schema)Zod schema for execute_command input: 'command' (string, required), 'timeout_ms' (number, optional).export const ExecuteCommandArgsSchema = z.object({ command: z.string(), timeout_ms: z.number().optional(), });
- src/server.ts:60-65 (registration)Tool registration in the MCP server's listTools response, defining name, description, and input schema.{ name: "execute_command", description: "Execute a terminal command with timeout. Command will continue running in background if it doesn't complete within timeout.", inputSchema: zodToJsonSchema(ExecuteCommandArgsSchema), },
- src/server.ts:216-219 (registration)Dispatch logic in callTool handler that routes 'execute_command' calls to the handler function after parsing arguments.case "execute_command": { const parsed = ExecuteCommandArgsSchema.parse(args); return executeCommand(parsed); }