Skip to main content

MCP Shell Server - Execute shell commands via MCP protocol

Project description

MCP Shell Server

A secure shell command execution server implementing the Model Context Protocol (MCP). This server allows remote execution of whitelisted shell commands with support for stdin input.

Features

  • Secure Command Execution: Only whitelisted commands can be executed
  • Standard Input Support: Pass input to commands via stdin
  • Comprehensive Output: Returns stdout, stderr, exit status, and execution time
  • Shell Operator Safety: Validates commands after shell operators (; , &&, ||, |)

MCP client setting in your Claude.app

code ~/Library/Application\ Support/Claude/claude_desktop_config.json
{
  "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

Usage

Starting the Server

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

The ALLOW_COMMANDS environment variable specifies which commands are allowed to be executed. Commands can be separated by commas with optional spaces around them.

Valid formats for ALLOW_COMMANDS:

ALLOW_COMMANDS="ls,cat,echo"          # Basic format
ALLOW_COMMANDS="ls ,echo, cat"        # With spaces
ALLOW_COMMANDS="ls,  cat  , echo"     # Multiple spaces

Request Format

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

# Command with stdin input
{
    "command": ["cat"],
    "stdin": "Hello, World!"
}

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

The server implements several security measures:

  1. Command Whitelisting: Only explicitly allowed commands can be executed
  2. Shell Operator Validation: Commands after shell operators (;, &&, ||, |) are also validated against the whitelist
  3. No Shell Injection: Commands are executed directly without shell interpretation

Development

Setting up Development Environment

  1. Clone the repository
git clone https://github.com/yourusername/mcp-shell-server.git
cd mcp-shell-server
  1. Install dependencies including test requirements
pip install -e ".[test]"

Running Tests

pytest

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

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)

Requirements

  • Python 3.11 or higher
  • mcp>=1.1.0

License

MIT License - See LICENSE file for details

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mcp_shell_server-0.1.0.tar.gz (34.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mcp_shell_server-0.1.0-py3-none-any.whl (6.4 kB view details)

Uploaded Python 3

File details

Details for the file mcp_shell_server-0.1.0.tar.gz.

File metadata

  • Download URL: mcp_shell_server-0.1.0.tar.gz
  • Upload date:
  • Size: 34.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.5.7

File hashes

Hashes for mcp_shell_server-0.1.0.tar.gz
Algorithm Hash digest
SHA256 975c7623d66f878ef4d05370cbe28d1c1191397c7781ee2ba721808f8796c7a1
MD5 18443d7b7418ce32d7c5c8146643aa3c
BLAKE2b-256 3eb1e62e01026c8f9b37d38d70600c2f5c285170ccb2e40efc9dd3732d01aae3

See more details on using hashes here.

File details

Details for the file mcp_shell_server-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for mcp_shell_server-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9b417f992f019b251c3fc654b725d8943d13af1599519038909cd2e6bc74be9a
MD5 44a522a17c06136257eb598a110e491d
BLAKE2b-256 edc5aeaf0ae368f1992f9f5a827ec81feaf4baa880b620a10a33f0aa9c829c85

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page