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.
There are two ways to install the MCP Command Executor:
go install github.com/cnosuke/mcp-command-exec
git clone https://github.com/cnosuke/mcp-command-exec.git
cd mcp-command-exec
make build
The server is configured via a YAML file (default: config.yml).
# 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'
You can override configurations using environment variables:
LOG_PATH
: Path to log fileDEBUG
: Enable debug mode (true/false)ALLOWED_COMMANDS
: Comma-separated list of allowed commandsFor example:
ALLOWED_COMMANDS=git,ls,cat,echo mcp-command-exec server
Start the server with:
./bin/mcp-command-exec server [options]
--config
, -c
: Path to the configuration file (default: "config.yml")The server implements the command_exec
tool for the MCP protocol.
command
: The command to execute (string)working_dir
: Optional working directory for command executionenv
: Optional environment variables for this command execution (object){
"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"
}
}
}
}
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"
}
}
}
}
The MCP Command Executor implements several security measures:
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.
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.
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"
}
}
}
}
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.
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.
To add this MCP server to Claude Desktop:
1. Find your configuration file:
~/Library/Application Support/Claude/claude_desktop_config.json
%APPDATA%\Claude\claude_desktop_config.json
~/.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