Securely execute whitelisted shell commands remotely with timeout and input support
The MCP Shell Server is a secure and robust implementation of the Model Context Protocol (MCP), designed to facilitate reliable command execution over remote connections while ensuring security through command whitelisting. This server forms a critical component in enabling AI applications like Claude Desktop, Continue, Cursor, and others to interact with various data sources and tools seamlessly via a standardized protocol.
The MCP Shell Server offers several key features that align with the core capabilities of the Model Context Protocol:
;
, &&
, ||
, and <|
are also thoroughly validated before execution to prevent injection vulnerabilities.The architecture of the MCP Shell Server is designed around the principles outlined by the Model Context Protocol, ensuring seamless integration with various AI applications and tools. The server leverages Python's ecosystem for development and implements a robust command execution mechanism.
The following Mermaid diagram illustrates the interaction between an AI application (MCP Client), the MCP Shell Server, and external data sources or tools:
graph TD
A[AI Application] -->|MCP Client| B[MCP Protocol]
B --> C[MCP Server]
C --> D[Data Source/Tool]
style A fill:#e1f5fe
style C fill:#f3e5f5
style D fill:#e8f5e8
The data architecture leverages the Model Context Protocol's standardized approach to ensure consistent behavior across different MCP clients. The server is configured to handle command requests, validate inputs, execute commands, and return outputs in a structured manner.
To get started with the MCP Shell Server, developers need to configure their environment correctly. Here’s how you can install and set up the server:
Clone the Repository
git clone https://github.com/yourusername/mcp-shell-server.git
cd mcp-shell-server
Install Dependencies Including Test Requirements
pip install -e ".[test]"
Run the Server With Whitelisted Commands
ALLOW_COMMANDS="ls,cat,echo" uvx mcp-shell-server
# Or using the alias
ALLOWED_COMMANDS="ls,cat,echo" uvx mcp-shell-server
In scenarios where an AI application needs to interact with files on a remote server for data analysis or preprocessing, the MCP Shell Server can be configured to allow commands like cat
, ls
, and grep
:
{
"mcpServers": {
"fileOpsShell": {
"command": "uvx",
"args": ["mcp-shell-server"],
"env": {
"ALLOW_COMMANDS": "cat, ls, grep"
}
}
}
}
For AI applications that require running custom scripts or managing environments on remote servers, the MCP Shell Server supports more complex commands including long-running-process
and find
:
{
"mcpServers": {
"scriptShell": {
"command": "uvx",
"args": ["mcp-shell-server"],
"env": {
"ALLOW_COMMANDS": "ls, cat, echo, find"
}
}
}
}
To integrate the MCP Shell Server with various AI applications, follow these configuration steps:
For a published version of Claude Desktop:
code ~/Library/Application\ Support/Claude/claude_desktop_config.json
Configure as follows:
{
"mcpServers": {
"shell": {
"command": "uvx",
"args": [
"mcp-shell-server"
],
"env": {
"ALLOW_COMMANDS": "ls,cat,pwd,grep,wc,touch,find"
}
},
}
}
For a local version of the server:
code ~/Library/Application\ Support/Claude/claude_desktop_config.json
Configure as follows:
{
"mcpServers": {
"shell": {
"command": "uv",
"args": [
"--directory",
".",
"run",
"mcp-shell-server"
],
"env": {
"ALLOW_COMMANDS": "ls,cat,pwd,grep,wc,touch,find"
}
},
}
}
The following table outlines the MCP Client compatibility and feature support matrix:
MCP Client | Resources | Tools | Prompts |
---|---|---|---|
Claude Desktop | ✅ | ✅ | ✅ |
Continue | ✅ | ✅ | ✅ |
Cursor | ❌ | ✅ | ❌ |
To restrict commands that can be executed, specify the ALLOW_COMMANDS
environment variable. Valid formats include:
ALLOW_COMMANDS="ls ,cat ,echo " # Spaces between commands are allowed
Example request format aligns with MCP protocol specifications as follows:
# 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
}
Successful response structure:
{
"stdout": "command output",
"stderr": "",
"status": 0,
"execution_time": 0.123
}
Error response includes detail on the failure:
{
"error": "Command not allowed: rm", # Error message
"status": 1,
"stdout": "", # Stdout remains empty if error occurs
"stderr": "Command not allowed: rm",
"execution_time": 0 # Time since execution started
}
The server restricts command execution to a predefined set listed in ALLOW_COMMANDS
, verifying commands against this list. Additionally, shell operators (;
, &&
, ||
, <|
) are parsed and validated.
No, the server enforces strict whitelisting. Only explicitly allowed commands can be executed to prevent unauthorized or potentially harmful actions.
If an unapproved command is attempted, it will fail and receive an error message indicating that the command was not allowed.
Yes, developers can set timeouts using the timeout
parameter to limit execution duration of commands and prevent command executions from hanging indefinitely.
Yes, dynamically updating ALLOW_COMMANDS
allows administrators to adapt command sets on-the-fly without restarting the server.
If you’re interested in contributing to this project or enhancing its functionality:
The Model Context Protocol ecosystem includes multiple clients like Claude Desktop, Continue, Cursor, among others. The MCP Shell Server is compatible with all of these platforms, providing a common ground for interacting with various data sources and tools.
For further details, refer to the official MCP documentation or explore additional resources on GitHub for collaboration and community support.
This comprehensive documentation aims to provide clear guidance on using the MCP Shell Server as part of an AI application stack. By facilitating secure and consistent command execution across different environments, it significantly enhances the capabilities of AI applications that integrate with the Model Context Protocol.
RuinedFooocus is a local AI image generator and chatbot image server for seamless creative control
Simplify MySQL queries with Java-based MysqlMcpServer for easy standard input-output communication
Learn to set up MCP Airflow Database server for efficient database interactions and querying airflow data
Build stunning one-page websites track engagement create QR codes monetize content easily with Acalytica
Explore CoRT MCP server for advanced self-arguing AI with multi-LLM inference and enhanced evaluation methods
Set up MCP Server for Alpha Vantage with Python 312 using uv and MCP-compatible clients