Secure Shell Executor MCP server

Provides a secure way to execute shell commands with robust validation, whitelisting, and timeout handling through an asyncio-powered Python implementation.
Back to servers
Setup instructions
Provider
Diego Fornalha
Release date
Mar 17, 2025
Language
Python

The MCP Shell Server provides a secure environment for remote shell command execution through the Model Context Protocol (MCP). It allows only authorized commands to be executed with support for stdin input, making it ideal for integrating shell capabilities with AI assistants.

Installation

Standard Installation

You can install the MCP Shell Server using pip:

pip install mcp-shell-server

Using with Claude Desktop App

To integrate the MCP Shell Server with your Claude Desktop application, you need to configure the Claude Desktop config file:

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

Add the following configuration:

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

Local Development Configuration

If you're working with a local version, use this configuration instead:

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

Usage

Starting the Server

You can start the server by specifying which commands are allowed to be executed:

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

You can also use the alias ALLOWED_COMMANDS:

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

The environment variable format supports various spacing styles:

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 requests in the following formats:

# 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 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 security measures:

  • Command Whitelist: 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

API 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 of the command
stderr string Error output of the command
status integer Exit status code
execution_time float Time spent executing (in seconds)
error string Error message (present only 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