execute_command
Run system commands locally on the MCP Terminal Server, specifying the command, arguments, and working directory for secure and controlled execution in the operating system environment.
Instructions
Execute a command in the local system
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| args | No | Command arguments | |
| command | Yes | Command to execute | |
| cwd | No | Working directory for command execution |
Implementation Reference
- src/index.ts:66-95 (handler)Handler function that parses input using ExecuteCommandSchema and executes the command using execa, returning stdout/stderr or error.if (name === "execute_command") { const { command, args: cmdArgs = [], cwd } = ExecuteCommandSchema.parse(args); try { const result = await execa(command, cmdArgs, { cwd, shell: true, }); return { content: [ { type: "text", text: result.stdout || result.stderr || 'Command executed successfully with no output', }, ], isError: false, }; } catch (execaError: any) { return { content: [ { type: "text", text: execaError?.message || 'Command execution failed', }, ], isError: true, }; } }
- src/index.ts:15-19 (schema)Zod schema for validating the input parameters of the execute_command tool: command (required), args (optional array), cwd (optional).const ExecuteCommandSchema = z.object({ command: z.string(), args: z.array(z.string()).optional(), cwd: z.string().optional(), });
- src/index.ts:37-56 (registration)Tool registration in the listTools response, including name, description, and JSON schema mirroring the Zod schema.{ name: "execute_command", description: "Execute a command in the local system", inputSchema: { type: "object", properties: { command: { type: "string", description: "Command to execute" }, args: { type: "array", items: { type: "string" }, description: "Command arguments" }, cwd: { type: "string", description: "Working directory for command execution" } }, required: ["command"], }, }