Skip to main content
Glama
dillip285

MCP Terminal Server

by dillip285

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
NameRequiredDescriptionDefault
argsNoCommand arguments
commandYesCommand to execute
cwdNoWorking directory for command execution

Implementation Reference

  • 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,
        };
      }
    }
  • 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"],
      },
    }
Install Server

Other Tools

Related Tools

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/dillip285/mcp-terminal'

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