execute_command
Execute terminal commands in specific directories to automate development tasks, manage files, and run scripts directly from the MCP Terminal & Git Server interface.
Instructions
Execute a terminal command in a specified directory
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| command | Yes | The command to execute (e.g., 'npm install', 'ls -la') | |
| cwd | No | Working directory for the command (defaults to current directory) |
Implementation Reference
- src/index.ts:235-253 (handler)Handler for the execute_command tool: destructures command and optional cwd from arguments, resolves the working directory, executes the command using execa with shell enabled, and returns stdout/stderr in a text content response.case "execute_command": { const { command, cwd } = args as { command: string; cwd?: string }; const workingDir = cwd ? resolvePath(cwd) : process.cwd(); // Execute command const { stdout, stderr } = await execa(command, { shell: true, cwd: workingDir, }); return { content: [ { type: "text", text: `Command executed successfully:\n\nOutput:\n${stdout}\n${stderr ? `\nErrors/Warnings:\n${stderr}` : ""}`, }, ], }; }
- src/index.ts:80-93 (schema)Input schema for execute_command tool defining properties for 'command' (required string) and optional 'cwd' (string).inputSchema: { type: "object", properties: { command: { type: "string", description: "The command to execute (e.g., 'npm install', 'ls -la')", }, cwd: { type: "string", description: "Working directory for the command (defaults to current directory)", }, }, required: ["command"], },
- src/index.ts:77-94 (registration)Registration of the execute_command tool in the ListTools response, specifying name, description, and input schema.{ name: "execute_command", description: "Execute a terminal command in a specified directory", inputSchema: { type: "object", properties: { command: { type: "string", description: "The command to execute (e.g., 'npm install', 'ls -la')", }, cwd: { type: "string", description: "Working directory for the command (defaults to current directory)", }, }, required: ["command"], }, },
- src/index.ts:26-31 (helper)Helper function resolvePath used in the handler to resolve the cwd parameter, supporting ~ expansion for home directory.function resolvePath(inputPath: string): string { if (inputPath.startsWith("~")) { return path.join(os.homedir(), inputPath.slice(1)); } return path.resolve(inputPath); }