Skip to main content
Glama
Sunwood-ai-labs

Command Executor MCP Server

execute_command

Executes pre-approved commands on the user's system, enabling AI assistants to perform secure system interactions.

Instructions

事前に許可されたコマンドを実行します

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
commandYes実行するコマンド

Implementation Reference

  • src/index.ts:69-87 (registration)
    Registration of the 'execute_command' tool via ListToolsRequestSchema handler. Defines the tool name, description, and inputSchema (expects a 'command' string).
    private setupToolHandlers() {
      this.server.setRequestHandler(ListToolsRequestSchema, async () => ({
        tools: [
          {
            name: 'execute_command',
            description: '事前に許可されたコマンドを実行します',
            inputSchema: {
              type: 'object',
              properties: {
                command: {
                  type: 'string',
                  description: '実行するコマンド',
                },
              },
              required: ['command'],
            },
          },
        ],
      }));
  • Main handler for executing the 'execute_command' tool. Validates the tool name, checks if the command is allowed via isCommandAllowed(), runs it via execAsync (promisified child_process.exec), and returns stdout/stderr.
    this.server.setRequestHandler(CallToolRequestSchema, async (request) => {
      if (request.params.name !== 'execute_command') {
        throw new McpError(
          ErrorCode.MethodNotFound,
          `Unknown tool: ${request.params.name}`
        );
      }
    
      const { command } = request.params.arguments as { command: string };
    
      // コマンドが許可されているか確認
      if (!this.isCommandAllowed(command)) {
        throw new McpError(
          ErrorCode.InvalidParams,
          `Command not allowed: ${command}. Allowed commands: ${this.allowedCommands.join(', ')}`
        );
      }
    
      try {
        const { stdout, stderr } = await execAsync(command);
        return {
          content: [
            {
              type: 'text',
              text: stdout || stderr,
            },
          ],
        };
      } catch (error: any) {
        return {
          content: [
            {
              type: 'text',
              text: `Command execution failed: ${error.message}`,
            },
          ],
          isError: true,
        };
      }
    });
  • Helper function isCommandAllowed that checks whether the command's prefix (first space-separated word) is in the allowed commands list.
    private isCommandAllowed(command: string): boolean {
      // コマンドの最初の部分(スペース区切りの最初の単語)を取得
      const commandPrefix = command.split(' ')[0];
      return this.allowedCommands.some(allowed => commandPrefix === allowed);
    }
  • Helper function getAllowedCommands that reads comma-separated allowed commands from the ALLOWED_COMMANDS environment variable, falling back to a default list (git, ls, mkdir, cd, npm, npx, python).
    const getAllowedCommands = (): string[] => {
      const envCommands = process.env.ALLOWED_COMMANDS;
      if (!envCommands) {
        return DEFAULT_ALLOWED_COMMANDS;
      }
      return envCommands.split(',').map(cmd => cmd.trim());
    };
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

Without annotations, the description carries the full burden. It mentions 'pre-authorized commands' implying an authorization check, but does not disclose what happens if unauthorized, potential side effects, or return values. This is insufficient for a command execution tool.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single sentence that is front-loaded and efficient. Every word earns its place with no redundancy or fluff.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the simplicity (1 parameter, no output schema), the description is minimal. It fails to cover important behavioral aspects like success/failure modes, authorization details, or examples. For a potentially powerful tool, it leaves significant gaps.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema coverage is 100% with a single parameter 'command' described as '実行するコマンド' (command to execute). The tool description adds the constraint that commands must be pre-authorized, which adds meaning beyond the schema. Baseline of 3 is appropriate as the description adds some value but not extensive detail.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the verb 'execute' and the resource 'pre-authorized commands', distinguishing it well. It is specific about the pre-authorization constraint, which adds clarity, though no siblings exist to differentiate from.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives, nor any when-not or prerequisites. It merely states what it does without context for appropriate usage.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other 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/Sunwood-ai-labs/command-executor-mcp-server'

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