MCP Exec Server

April 2, 2025 · View on GitHub

License: MIT Version Python Docker

A powerful MCP server enabling AI assistants like Claude to execute commands and run code across multiple programming languages in secure, isolated environments. This server provides a complete development toolkit with pre-configured language environments, intelligent package management, and comprehensive process control.

Table of Contents

Overview

The MCP Exec Server serves as a powerful bridge between AI assistants and command-line environments. It enables capabilities ranging from simple command execution to running complex scripts in multiple programming languages. By providing a secure, containerized environment with pre-installed development tools, this server allows AI assistants to help with coding, data analysis, and system management tasks. It's designed to be easily integrated with Claude and other AI assistants through the Model Context Protocol (MCP).

Features

Command Execution

  • Flexible Command Execution: Run shell commands with configurable timeouts
  • Multi-Language Support: Execute scripts in Python, JavaScript, Rust, Go, and Solidity
  • Output Control: Capture and redirect output streams (stdout, stderr)
  • Process Management: Asynchronous execution with monitoring capabilities

Package Management

  • Smart Dependency Installation: Auto-detect appropriate package managers (apt, pip, npm, cargo)
  • Bulk Configuration: Set up multiple tools across different package managers simultaneously
  • Environment Discovery: List installed tools and available commands
  • Cross-Language Integration: Seamlessly mix dependencies from different ecosystems

Development Environments

  • Pre-configured Stacks: Ready-to-use environments for multiple programming languages
  • Full Tool Suites: Complete development toolchains including compilers, linters, and utilities
  • Data Science Tools: Python environment with analytical and visualization libraries
  • Web Development: Complete JavaScript/TypeScript environment with Node.js

Available Tools

Command Execution

ToolDescriptionParameters
execute_commandRun shell commands with timeout and output capturecommand: Command to execute
timeout: Maximum time in seconds (default: 30)
output_type: Output streams to return ("stdout", "stderr", "both")
shell: Whether to use shell (default: True)
execute_scriptRun code in various languagesscript: Code content to execute
script_type: Language ("bash", "python", "js", "rust", "go")
timeout: Maximum time in seconds (default: 30)
output_type: Output streams to return
read_outputRead output from a running processsession_id: ID returned by execute_command
output_type: Output streams to read
force_terminateKill a running processsession_id: ID returned by execute_command
list_sessionsShow all active command sessionsNone
list_processesShow all running processesNone
kill_processTerminate a process by PIDpid: Process ID to kill

Package Management

ToolDescriptionParameters
list_installed_commandsList all available tools and commandsNone
install_commandInstall a specific packagecommand: Package name to install
package_manager: Optional override (apt, pip, npm, etc.)
configure_packagesInstall multiple packages across package managersconfig: Dictionary mapping managers to package lists
Example: {"apt": ["git", "curl"], "pip": ["requests"]}
block_commandBlock specific commands from executioncommand: Command to block
unblock_commandAllow previously blocked commandscommand: Command to unblock
list_blocked_commandsShow all blocked commandsNone

Requirements

Software Requirements

  • Python: Version 3.12 or newer
  • Docker: For containerized deployment (recommended)

Python Dependencies

  • System Interaction: psutil, subprocess
  • API Framework: fastapi, uvicorn
  • MCP Protocol: mcp[cli]

Installation

Option 1: Local Installation

# Clone the repository
git clone https://github.com/0kenx/mcp-servers.git
cd mcp-servers/exec

# Build the Docker image
docker build -t mcp/exec .

Configuration with Claude

Add the MCP Exec Server to your Claude configuration file:

{
  "mcpServers": {
    "exec": {
      "command": "docker",
      "args": [
        "run",
        "-p",
        "3006:3006",
        "-i",
        "--rm",
        "mcp/exec"
      ]
    }
  }
}

How It Works

The MCP Exec Server acts as a bridge between Claude (or other AI assistants) and a command-line environment. When Claude invokes one of the MCP tools:

  1. The server receives the request with parameters (like commands, scripts, or package installations)
  2. It executes the requested operation in a secure, containerized environment
  3. For asynchronous operations, it manages the process lifecycle and captures outputs
  4. The results are returned to Claude, which can then incorporate them into its response

MCP Tools

The following tools are exposed via Model Context Protocol (MCP) for AI assistants to use:

Command Execution

ToolDescriptionParameters
execute_commandRun shell commands with timeout and output capturecommand: Command to execute
timeout: Maximum time in seconds (default: 30)
output_type: Output streams to return ("stdout", "stderr", "both")
execute_scriptRun code in various languagesscript: Code content to execute
script_type: Language ("bash", "python", "js", "rust", "go")
timeout: Maximum time in seconds (default: 30)
output_type: Output streams to return
read_outputRead output from a running processsession_id: ID returned by execute_command
output_type: Output streams to read
force_terminateKill a running processsession_id: ID returned by execute_command
list_sessionsShow all active command sessionsNone
list_processesShow all running processesNone
kill_processTerminate a process by PIDpid: Process ID to kill

Package Management

ToolDescriptionParameters
list_installed_commandsList all available tools and commandsNone
install_commandInstall a specific packagecommand: Package name to install
package_manager: Optional override (apt, pip, npm, etc.)
configure_packagesInstall multiple packages across package managersconfig: Dictionary mapping managers to package lists
Example: {"apt": ["git", "curl"], "pip": ["requests"]}
block_commandBlock specific commands from executioncommand: Command to block
unblock_commandAllow previously blocked commandscommand: Command to unblock
list_blocked_commandsShow all blocked commandsNone

Preinstalled Development Environments

The MCP Exec server provides ready-to-use development environments for multiple programming languages and paradigms:

EnvironmentComponentsFeatures
System Utilitiesbash, curl, wget, vim, nano, git, jq, zip, unzipCore system tools for file management and data processing
Python 3.12pip, ipython, venv
pandas, numpy, matplotlib, seaborn
black, flake8, mypy, pytest
Complete data science stack with visualization libraries and development tools
JavaScript/TypeScriptNode.js v20, npm, yarn
TypeScript, ts-node
Modern JavaScript environment with TypeScript support and package managers
Rustrustup, cargo, rustc
rustfmt, clippy, rust-analyzer
cargo-watch, cargo-edit, cargo-generate
Full Rust development environment with code formatting, linting tools, and useful extensions
Go 1.22.1Standard Go toolchainCore Go compiler and development tools
SolidityFoundry suite: forge, cast, anvilComplete Ethereum smart contract development environment

Usage Examples

Execute a Command

execute_command("ls -la", timeout=5, output_type="both")

Run a Python Script

execute_script("""
import numpy as np
import matplotlib.pyplot as plt

# Generate some data
x = np.linspace(0, 10, 100)
y = np.sin(x)

# Print the data
print(f"Max value: {y.max()}")
print(f"Min value: {y.min()}")
""", script_type="python", timeout=10)

Compile and Run a Rust Program

execute_script("""
fn main() {
    println!("Hello from Rust!");
    
    // Simple fibonacci calculation
    let n = 10;
    let mut a = 0;
    let mut b = 1;
    
    for _ in 0..n {
        let temp = a;
        a = b;
        b = temp + b;
    }
    
    println!("Fibonacci number {} is {}", n, a);
}
""", script_type="rust", timeout=10)

Install a New Tool

install_command("tensorflow")

Configure Multiple Tools

configure_packages({
    "apt": ["imagemagick", "ffmpeg"],
    "pip": ["pytorch", "transformers"],
    "npm": ["typescript", "webpack"]
})

When to Use Each Tool

The MCP Exec Server provides several tools for different execution scenarios:

  • execute_command: Use when you need to run simple shell commands or Linux utilities. Ideal for file operations, system information retrieval, and basic command-line operations.

  • execute_script: Best for running multi-line code in specific programming languages. Particularly useful for complex operations, algorithms, or when you need language-specific functionality.

  • read_output and force_terminate: Use with long-running operations to monitor output and control execution when needed.

  • list_processes and kill_process: Helpful for managing system resources and terminating runaway processes.

  • install_command: Use when you need a package that isn't pre-installed in the environment. Check available commands first with list_installed_commands.

  • configure_packages: Ideal for setting up complex environments that require multiple packages across different package managers.

  • block_command and unblock_command: Use these for security control when you want to prevent certain commands from being executed.

Security Considerations

Potential Risks

The Exec MCP Server allows arbitrary command execution, which inherently carries security risks:

  • Code Execution: AI assistants can run arbitrary code in multiple languages
  • System Modification: Commands could potentially modify the container environment
  • Resource Consumption: Intensive operations could consume excessive resources
  • Network Access: By default, the container has network connectivity

Security Measures

Built-in Protections

  • Command Blocking: Block dangerous commands via the block_command tool
  • Timeouts: All executions have configurable timeouts to prevent infinite loops
  • Process Management: Monitor and terminate long-running processes
  • Containerization: All execution happens within an isolated Docker container
  • Resource Limits: Restrict CPU, memory, and disk usage using Docker's resource controls

    docker run --cpus=2 --memory=2g --storage-opt size=10G mcp/exec
    
  • Read-Only Filesystem: Mount sensitive directories as read-only

    docker run --mount type=bind,src=/data,dst=/data,readonly mcp/exec
    
  • Capabilities Reduction: Remove unnecessary Linux capabilities

    docker run --cap-drop=ALL --cap-add=NET_BIND_SERVICE mcp/exec
    

Operational Security

  • Review execution logs regularly for suspicious activity
  • Use Docker security scanning tools to verify container security
  • Update the image regularly to incorporate security patches
  • Consider implementing API authentication for the MCP server

Contributing

Contributions are welcome! If you'd like to improve this project, please feel free to submit pull requests or open issues on the repository.

License

This project is licensed under the MIT License - see the LICENSE file for details.