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
13.1K downloads
109 stars

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.

Installation

You can install the MCP Shell Server using different methods:

Using pip

pip install mcp-shell-server

Using Smithery (Automated Installation)

Install Shell Server for Claude Desktop automatically via Smithery:

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

Configuration

Basic Configuration

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

Claude Desktop Configuration

For Claude Desktop, you need to modify the configuration file:

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

Published Version Configuration

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

Local Version Configuration

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

Usage

Request Format

The server accepts JSON requests with the following structure:

Basic Command Execution

{
    "command": ["ls", "-l", "/tmp"]
}

Command with Input via stdin

{
    "command": ["cat"],
    "stdin": "Hello, World!"
}

Command with Timeout Limit

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

Security Features

The server implements several important security measures:

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

Request and Response Reference

Request Arguments

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