Command Executor MCP server

Enables secure remote command execution with robust security controls like command allowlisting, direct command invocation without shell access, and strict environment management for controlled system interactions.
Back to servers
Setup instructions
Provider
Shinnosuke Takeda
Release date
Mar 26, 2025
Language
Go
Stats
1 star

MCP Command Executor is a server implementation that allows safe execution of system commands via the MCP protocol. It works by only executing commands that are registered in an allowlist, providing a secure way to run system commands through the Model Context Protocol.

Installation

There are two ways to install the MCP Command Executor:

Option 1: Using Go Install

go install github.com/cnosuke/mcp-command-exec

Option 2: Manual Build

git clone https://github.com/cnosuke/mcp-command-exec.git
cd mcp-command-exec
make build

Configuration

The server is configured via a YAML file (default: config.yml).

Sample Configuration

# Logging configuration
log: 'log/mcp-command-exec.log'
debug: false

command_exec:
  allowed_commands:
    - git
    - ls
    - mkdir
    - cd
    - npm
    - npx
    - python
  # Working directory settings
  default_working_dir: '/home/user'
  allowed_dirs:
    - '/home/user/projects'
    - '/tmp'
  # Path search settings
  search_paths:
    - '/usr/local/bin'
    - '/usr/bin'
  path_behavior: 'prepend' # prepend, replace, append
  # Global environment variables
  environment:
    HOME: '/home/user'
    GOPATH: '/home/user/go'
    GOMODCACHE: '/home/user/go/pkg/mod'
    LANG: 'en_US.UTF-8'

Using Environment Variables

You can override configurations using environment variables:

  • LOG_PATH: Path to log file
  • DEBUG: Enable debug mode (true/false)
  • ALLOWED_COMMANDS: Comma-separated list of allowed commands

For example:

ALLOWED_COMMANDS=git,ls,cat,echo mcp-command-exec server

Running the Server

Start the server with:

./bin/mcp-command-exec server [options]

Command-Line Options

  • --config, -c: Path to the configuration file (default: "config.yml")

Using the MCP Tool

Command Execution

The server implements the command_exec tool for the MCP protocol.

Parameters

  • command: The command to execute (string)
  • working_dir: Optional working directory for command execution
  • env: Optional environment variables for this command execution (object)

Example Request

{
  "method": "tool",
  "id": "1",
  "params": {
    "name": "command_exec",
    "input": {
      "command": "ls -la",
      "working_dir": "/home/user/project",
      "env": {
        "DEBUG": "1",
        "LANG": "en_US.UTF-8"
      }
    }
  }
}

Integration with Claude Desktop

To use with Claude Desktop, add an entry to your claude_desktop_config.json file:

{
  "mcpServers": {
    "command": {
      "command": "./bin/mcp-command-exec",
      "args": ["server"],
      "env": {
        "LOG_PATH": "mcp-command-exec.log",
        "DEBUG": "false",
        "ALLOWED_COMMANDS": "git,ls,cat,echo,find"
      }
    }
  }
}

Security Features

The MCP Command Executor implements several security measures:

  • Only executes commands in the allowlist
  • Executes commands directly without using a shell
  • Validates commands by prefix
  • Safely handles environment variables
  • Implements strict error handling

How to install this MCP server

For Claude Code

To add this MCP server to Claude Code, run this command in your terminal:

claude mcp add-json "command" '{"command":"./bin/mcp-command-exec","args":["server"],"env":{"LOG_PATH":"mcp-command-exec.log","DEBUG":"false","ALLOWED_COMMANDS":"git,ls,cat,echo,find"}}'

See the official Claude Code MCP documentation for more details.

For Cursor

There are two ways to add an MCP server to Cursor. The most common way is to add the server globally in the ~/.cursor/mcp.json file so that it is available in all of your projects.

If you only need the server in a single project, you can add it to the project instead by creating or adding it to the .cursor/mcp.json file.

Adding an MCP server to Cursor globally

To add a global MCP server go to Cursor Settings > Tools & Integrations and click "New MCP Server".

When you click that button the ~/.cursor/mcp.json file will be opened and you can add your server like this:

{
    "mcpServers": {
        "command": {
            "command": "./bin/mcp-command-exec",
            "args": [
                "server"
            ],
            "env": {
                "LOG_PATH": "mcp-command-exec.log",
                "DEBUG": "false",
                "ALLOWED_COMMANDS": "git,ls,cat,echo,find"
            }
        }
    }
}

Adding an MCP server to a project

To add an MCP server to a project you can create a new .cursor/mcp.json file or add it to the existing one. This will look exactly the same as the global MCP server example above.

How to use the MCP server

Once the server is installed, you might need to head back to Settings > MCP and click the refresh button.

The Cursor agent will then be able to see the available tools the added MCP server has available and will call them when it needs to.

You can also explicitly ask the agent to use the tool by mentioning the tool name and describing what the function does.

For Claude Desktop

To add this MCP server to Claude Desktop:

1. Find your configuration file:

  • macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
  • Windows: %APPDATA%\Claude\claude_desktop_config.json
  • Linux: ~/.config/Claude/claude_desktop_config.json

2. Add this to your configuration file:

{
    "mcpServers": {
        "command": {
            "command": "./bin/mcp-command-exec",
            "args": [
                "server"
            ],
            "env": {
                "LOG_PATH": "mcp-command-exec.log",
                "DEBUG": "false",
                "ALLOWED_COMMANDS": "git,ls,cat,echo,find"
            }
        }
    }
}

3. Restart Claude Desktop for the changes to take effect

Want to 10x your AI skills?

Get a free account and learn to code + market your apps using AI (with or without vibes!).

Nah, maybe later