Shell Command MCP server

Execute whitelisted shell commands on the host system via asyncio.
Back to servers
Setup instructions
Provider
tumf
Release date
Dec 10, 2024
Language
Python
Package
Stats
22.3K downloads
131 stars

MCP Shell Server is a secure command execution tool implementing the Model Context Protocol (MCP), allowing you to execute whitelisted shell commands remotely. It provides security through command whitelisting while supporting standard input and delivering comprehensive execution output.

Installation Options

Using Smithery (Recommended)

The easiest way to install the Shell Server for Claude Desktop:

npx -y @smithery/cli install mcp-shell-server --client claude

Manual Installation

You can install the server directly using pip:

pip install mcp-shell-server

Configuration

Claude Desktop Configuration

To set up the MCP Shell Server with Claude Desktop, you need to edit the configuration file:

code ~/Library/Application\ Support/Claude/claude_desktop_config.json

Published Version Configuration

Add the following to your Claude Desktop configuration file:

{
  "mcpServers": {
    "shell": {
      "command": "uvx",
      "args": [
        "mcp-shell-server"
      ],
      "env": {
        "ALLOW_COMMANDS": "ls,cat,pwd,grep,wc,touch,find"
      }
    }
  }
}

Local Version Configuration

For local development:

{
  "mcpServers": {
    "shell": {
      "command": "uv",
      "args": [
        "--directory",
        ".",
        "run",
        "mcp-shell-server"
      ],
      "env": {
        "ALLOW_COMMANDS": "ls,cat,pwd,grep,wc,touch,find"
      }
    }
  }
}

Usage

Starting the Server

Launch the server with a comma-separated list of allowed commands:

ALLOW_COMMANDS="ls,cat,echo" uvx mcp-shell-server

You can also use the alternative environment variable:

ALLOWED_COMMANDS="ls,cat,echo" uvx mcp-shell-server

The command list format is flexible:

ALLOW_COMMANDS="ls,cat,echo"          # Basic format
ALLOWED_COMMANDS="ls ,echo, cat"      # With spaces (using alias)
ALLOW_COMMANDS="ls,  cat  , echo"     # Multiple spaces

Request Format

The server accepts JSON requests with the following structure:

# 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
}

Response Format

Successful Execution

{
    "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
}

Security Features

The server implements several important security measures:

  • Command Whitelisting: Only explicitly permitted commands can be executed
  • Shell Operator Validation: Commands after shell operators (;, &&, ||, |) are validated against the whitelist
  • No Shell Injection: Commands execute directly without shell interpretation
  • Timeout Control: Limits maximum execution time for commands

API Reference

Request Parameters

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

Response Fields

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)

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 "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.

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": {
        "shell": {
            "command": "uvx",
            "args": [
                "mcp-shell-server"
            ],
            "env": {
                "ALLOW_COMMANDS": "ls,cat,pwd,grep,wc,touch,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": {
        "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

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