This MCP Shell Server allows secure execution of whitelisted shell commands remotely, implementing the Model Context Protocol (MCP). It provides controlled command execution with comprehensive output handling and security features.
You can install the MCP Shell Server using different methods:
pip install mcp-shell-server
Install Shell Server for Claude Desktop automatically via Smithery:
npx -y @smithery/cli install mcp-shell-server --client claude
The server requires a list of allowed commands specified through environment variables:
ALLOW_COMMANDS="ls,cat,pwd,grep,wc,touch,find" uvx mcp-shell-server
Alternatively, you can use the alias ALLOWED_COMMANDS
:
ALLOWED_COMMANDS="ls,cat,echo" uvx mcp-shell-server
Valid formats for specifying commands:
ALLOW_COMMANDS="ls,cat,echo" # Basic format
ALLOWED_COMMANDS="ls ,echo, cat" # With spaces (using alias)
ALLOW_COMMANDS="ls, cat , echo" # Multiple spaces
For Claude Desktop, you need to modify the configuration file:
code ~/Library/Application\ Support/Claude/claude_desktop_config.json
{
"mcpServers": {
"shell": {
"command": "uvx",
"args": [
"mcp-shell-server"
],
"env": {
"ALLOW_COMMANDS": "ls,cat,pwd,grep,wc,touch,find"
}
}
}
}
{
"mcpServers": {
"shell": {
"command": "uv",
"args": [
"--directory",
".",
"run",
"mcp-shell-server"
],
"env": {
"ALLOW_COMMANDS": "ls,cat,pwd,grep,wc,touch,find"
}
}
}
}
The server accepts JSON requests with the following structure:
{
"command": ["ls", "-l", "/tmp"]
}
{
"command": ["cat"],
"stdin": "Hello, World!"
}
{
"command": ["long-running-process"],
"timeout": 30 # Maximum execution time in seconds
}
{
"command": ["grep", "-r", "pattern"],
"directory": "/path/to/search",
"timeout": 60
}
{
"stdout": "command output",
"stderr": "",
"status": 0,
"execution_time": 0.123
}
{
"error": "Command not allowed: rm",
"status": 1,
"stdout": "",
"stderr": "Command not allowed: rm",
"execution_time": 0
}
The server implements several important security measures:
Field | Type | Required | Description |
---|---|---|---|
command | string[] | Yes | Command and its arguments as array elements |
stdin | string | No | Input to be passed to the command |
directory | string | No | Working directory for command execution |
timeout | integer | No | Maximum execution time in seconds |
Field | Type | Description |
---|---|---|
stdout | string | Standard output from the command |
stderr | string | Standard error output from the command |
status | integer | Exit status code |
execution_time | float | Time taken to execute (in seconds) |
error | string | Error message (only present if failed) |
To add this MCP server to Claude Code, run this command in your terminal:
claude mcp add-json "shell" '{"command":"uvx","args":["mcp-shell-server"],"env":{"ALLOW_COMMANDS":"ls,cat,pwd,grep,wc,touch,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": {
"shell": {
"command": "uvx",
"args": [
"mcp-shell-server"
],
"env": {
"ALLOW_COMMANDS": "ls,cat,pwd,grep,wc,touch,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": {
"shell": {
"command": "uvx",
"args": [
"mcp-shell-server"
],
"env": {
"ALLOW_COMMANDS": "ls,cat,pwd,grep,wc,touch,find"
}
}
}
}
3. Restart Claude Desktop for the changes to take effect