Skip to main content
Glama

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
NameRequiredDescriptionDefault
commandYesThe command to execute (e.g., 'npm install', 'ls -la')
cwdNoWorking directory for the command (defaults to current directory)

Implementation Reference

  • 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}` : ""}`, }, ], }; }
  • 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"], }, },
  • 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); }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/AbdurRaahimm/mcp-git-terminal-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server