A secure shell command execution server implementing the Model Context Protocol (MCP)
The Model Context Protocol (MCP) is revolutionizing how Large Language Models (LLMs) interact with the external world. By providing a standardized interface for connecting LLMs to data sources and tools, MCP empowers developers to build more intelligent and context-aware AI applications. The mcp-shell-server
is a powerful example of this, offering a secure and controlled way for LLMs to execute shell commands.
;
, &&
, ||
, and |
are validated against the whitelist.stdin
, allowing for more complex interactions.stdout
, stderr
, exit status, and execution time for thorough monitoring and debugging.To integrate the mcp-shell-server
with Claude.app, you'll need to modify the claude_desktop_config.json
file. Here's how to configure both published and local versions:
Locate the Configuration File:
code ~/Library/Application\ Support/Claude/claude_desktop_config.json
Add the MCP Server Configuration:
{ "mcpServers": { "shell": { "command": "uvx", "args": [ "mcp-shell-server" ], "env": { "ALLOW_COMMANDS": "ls,cat,pwd,grep,wc,touch,find" } }, } }
Locate the Configuration File:
code ~/Library/Application\ Support/Claude/claude_desktop_config.json
Add the MCP Server Configuration:
{ "mcpServers": { "shell": { "command": "uv", "args": [ "--directory", ".", "run", "mcp-shell-server" ], "env": { "ALLOW_COMMANDS": "ls,cat,pwd,grep,wc,touch,find" } }, } }
Installation:
pip install mcp-shell-server
The mcp-shell-server
is initiated using the uvx
command, with the ALLOW_COMMANDS
environment variable defining the permitted commands.
ALLOW_COMMANDS="ls,cat,echo" uvx mcp-shell-server # Or using the alias ALLOWED_COMMANDS="ls,cat,echo" uvx mcp-shell-server
Important: The ALLOW_COMMANDS
(or ALLOWED_COMMANDS
) environment variable is crucial for security. It dictates which commands the server is authorized to execute.
Valid Formats:
ALLOW_COMMANDS="ls,cat,echo" # Basic format ALLOWED_COMMANDS="ls ,echo, cat" # With spaces (using alias) ALLOW_COMMANDS="ls, cat , echo" # Multiple spaces
The server communicates using JSON-based requests and responses.
# Basic command execution { "command": ["ls", "-l", "/tmp"] } # Command with stdin input { "command": ["cat"], "stdin": "Hello, World!" } # Command with timeout { "command": ["long-running-process"], "timeout": 30 # Maximum execution time in seconds } # Command with working directory and timeout { "command": ["grep", "-r", "pattern"], "directory": "/path/to/search", "timeout": 60 }
Successful Response:
{ "stdout": "command output", "stderr": "", "status": 0, "execution_time": 0.123 }
Error Response:
{ "error": "Command not allowed: rm", "status": 1, "stdout": "", "stderr": "Command not allowed: rm", "execution_time": 0 }
To contribute to the mcp-shell-server
project, follow these steps:
Clone the Repository:
git clone https://github.com/yourusername/mcp-shell-server.git cd mcp-shell-server
Install Dependencies:
pip install -e ".[test]"
Run Tests:
pytest
| Field | Type | Required | Description be passed to the command | | stdin | string | No | Input to be passed to the command
๐ ๐ Autonomous shell execution, computer control and coding agent. (Mac)
๐ MCP server that can execute commands such as keyboard input and mouse movement
๐ ๐ ๐ฆ Analyzes your codebase identifying important files based on dependency relationships. Generates diagrams and importance scores, helping AI assistants understand the codebase.
๐ ๐ An MCP Server and VS Code Extension which enables (language agnostic) automatic debugging via breakpoints and expression evaluation.