Navigation
MCP Command Server: Secure Execution & Enterprise Deployment - MCP Implementation

MCP Command Server: Secure Execution & Enterprise Deployment

MCP Command Server delivers secure, containerized remote command execution with pattern-based validation, enterprise-grade deployment, and full API docs for seamless ops workflows.

โœจ Developer Tools
4.6(88 reviews)
132 saves
61 comments

This tool saved users approximately 5447 hours last month!

About MCP Command Server

What is MCP Command Server: Secure Execution & Enterprise Deployment?

MCP Command Server is a secure, enterprise-ready command execution platform developed in Rust, designed to isolate and validate system commands within a Dockerized environment. It enforces strict security policies to prevent unauthorized operations such as file system modifications, privilege escalation, and network interactions, while providing a standardized interface for programmatic command execution. The server leverages YAML-configurable exclusion rules and regex-based validation to block high-risk commands, ensuring compliance with organizational security standards.

How to use MCP Command Server: Secure Execution & Enterprise Deployment?

Deployment follows a three-step process: configure exclusion rules via exclude.yaml, initialize the Docker container with non-root privileges using docker-compose up, and execute commands via JSON-RPC endpoints. Users send validated commands through HTTP POST requests specifying method, parameters, and ID, with responses containing execution outputs or error details. Postman collections and CLI tools like curl provide testing frameworks for verifying operational integrity and security constraints.

MCP Command Server Features

Key Features of MCP Command Server: Secure Execution & Enterprise Deployment?

  • Granular command validation: Blocks over 200 predefined dangerous operations using configurable exclusion patterns
  • Containerized hardening: Runs in minimal Docker images with restricted capabilities and read-only file systems
  • Comprehensive audit logging: Captures command metadata, execution results, and validation outcomes in structured format
  • Production-ready tooling: Includes Prometheus metrics endpoints and readiness/liveness probes for Kubernetes integration
  • Extensible validation pipeline: Supports custom middleware for organization-specific security policies

Use cases of MCP Command Server: Secure Execution & Enterprise Deployment?

Primary use cases include:

  • Automating infrastructure provisioning in air-gapped environments
  • Securing CI/CD pipelines executing sensitive operations
  • Centralized command orchestration for multi-tenant platforms
  • Compliance-driven command execution in regulated industries
  • API gateways for legacy command-line tools requiring modern security controls

MCP Command Server FAQ

FAQ from MCP Command Server: Secure Execution & Enterprise Deployment?

  • How are exclusion rules enforced? Validation occurs in three phases: syntax analysis, regex pattern matching against exclusion lists, and capability checks against the container's runtime restrictions
  • Can I customize the Docker configuration? Yes, through environment variables controlling resource limits, network policies, and SELinux/AppArmor profiles
  • What's the performance overhead? Benchmarks show <0.5ms validation latency with typical command payloads, negligible compared to actual command execution time
  • Is Windows support available? The server runs natively in Windows containers, though some Linux-specific security features require WSL2 integration
  • How are updates handled? Rolling upgrades via Docker allow zero-downtime updates with automatic configuration synchronization

Content

MCP Command Server

Command Line Icon

Secure JSON-RPC API for Remote Command Execution

License: MIT Built with Rust Docker JSON-RPC

MCP Command Server provides a secure, containerized interface for remote command execution with built-in pattern-based security validation, comprehensive API documentation, and enterprise-ready deployment configurations.

๐Ÿ“‹ Table of Contents

  • ๐Ÿ” Overview
  • โœจ Features
  • ๐Ÿ—๏ธ Architecture
  • ๐Ÿš€ Installation
  • ๐Ÿงฐ Usage
  • ๐Ÿ“š API Documentation
  • ๐Ÿ”’ Security
  • ๐Ÿ’ป Development
  • ๐Ÿงช Testing
  • ๐Ÿ‘ฅ Contributing
  • ๐Ÿ“„ License

๐Ÿ” Overview

MCP Command Server provides a JSON-RPC 2.0 compliant API for executing shell commands on the server. It's designed with security in mind, featuring command pattern exclusion to prevent potentially harmful operations. The server is fully containerized with Docker and includes comprehensive API documentation accessible directly through the API.

โœจ Features

  • JSON-RPC 2.0 API : Standardized interface for command execution
  • Command Security : Pattern-based command filtering to block potentially harmful operations
  • Self-Documenting : Built-in /context endpoint serving markdown documentation
  • Containerized : Ready-to-use Docker configuration
  • Production-Ready : Security-focused design with non-root execution
  • Developer-Friendly : Complete Postman collection for testing

๐Ÿ—๏ธ Architecture

flowchart TB
    Client[Client] -->|HTTP POST JSON-RPC| Server[MCP Command Server]
    Client -->|HTTP GET| Context["/context" Documentation]
    
    subgraph Server["MCP Command Server (Port 3030)"]
        API[JSON-RPC API] --> Validator[Command Validator]
        Validator -->|if safe| Executor[Command Executor]
        Validator -->|if unsafe| Reject[Reject Command]
        Context
    end
    
    Validator --> ExcludeYAML[exclude.yaml]
    Context --> ContextMD[.context]
    
    Executor -->|execute| Shell[Shell]
    Shell --> Results[Command Results]
    Results --> API
    
    classDef container fill:#326ce5,stroke:#fff,stroke-width:1px,color:#fff;
    classDef component fill:#fff,stroke:#000,stroke-width:1px,color:#000;
    classDef config fill:#f9f,stroke:#333,stroke-width:1px,color:#333;
    
    class Server,Shell container;
    class API,Validator,Executor,Context,Reject,Results component;
    class ExcludeYAML,ContextMD config;

Component Flow

sequenceDiagram
    participant Client
    participant Server as MCP Command Server
    participant Validator
    participant Executor
    participant Shell
    
    Client->>Server: POST / {JSON-RPC Request}
    Server->>Validator: Validate command
    
    alt Command matches exclusion pattern
        Validator->>Server: Reject (Security violation)
        Server->>Client: Error response
    else Command is safe
        Validator->>Executor: Execute command
        Executor->>Shell: Run shell command
        Shell->>Executor: Command output
        Executor->>Server: Process results
        Server->>Client: JSON-RPC Response
    end
    
    Client->>Server: GET /context
    Server->>Client: Markdown documentation

๐Ÿš€ Installation

Prerequisites

  • Docker and Docker Compose
  • Git (for cloning the repository)

Using Docker (Recommended)

  1. Clone the repository:

    git clone https://github.com/yourusername/mcp_command_server.git

cd mcp_command_server
  1. Start the server using Docker Compose:

    docker-compose up -d

  2. The server will be available at http://localhost:3030

Building from Source

  1. Ensure you have Rust installed (1.74+ recommended):

    curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

  2. Clone and build the project:

    git clone https://github.com/yourusername/mcp_command_server.git

cd mcp_command_server
cargo build --release
  1. Run the server:

    ./target/release/mcp_command_server

๐Ÿงฐ Usage

Basic Commands

Execute a simple command:

curl -X POST -H "Content-Type: application/json" -d '{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "command/get",
  "params": {
    "command": "echo \"Hello World\""
  }
}' http://localhost:3030/

Response:

{
  "jsonrpc": "2.0",
  "id": 1,
  "result": {
    "stdout": "Hello World\n"
  }
}

Access API Documentation

Get the API documentation in markdown format:

curl http://localhost:3030/context

๐Ÿ“š API Documentation

The MCP Command Server provides comprehensive documentation via the /context endpoint. This documentation is served as markdown and includes:

  • API overview
  • Available methods
  • Request/response formats
  • Error codes
  • Usage examples
  • Security considerations

JSON-RPC Specification

The API follows the JSON-RPC 2.0 specification:

  • Endpoint : http://localhost:3030/

  • Method : POST

  • Content-Type : application/json

  • Body Format :

    {
    "jsonrpc": "2.0",
    "id": "",
    "method": "command/get",
    "params": {
    "command": ""
    }
    }

Available Methods

Method Description Parameters
command/get Executes a shell command command: string

Response Format

Success Response:

{
  "jsonrpc": "2.0",
  "id": "<request_id>",
  "result": {
    "stdout": "<command_output>"
  }
}

Error Response:

{
  "jsonrpc": "2.0",
  "id": "<request_id>",
  "error": {
    "code": "<error_code>",
    "message": "<error_message>"
  }
}

Error Codes

Code Message Description
-32602 Missing 'command' parameter The required 'command' parameter was not provided
-32000 Command execution error The command could not be executed or was rejected
-32601 Method not found The specified method does not exist

๐Ÿ”’ Security

The MCP Command Server implements several security measures:

Command Exclusion System

The server uses a pattern-based exclusion system to prevent potentially harmful commands from being executed. This is configured through the exclude.yaml file, which contains:

  • Plain text patterns (e.g., rm -rf, sudo, apt)

  • Regular expression patterns (e.g., regex:.*\.\.\/.*)

  • Options for case sensitivity and matching behavior

    flowchart LR
    Command[Command Input] --> Validator[Command Validator]
    ExcludeYAML[exclude.yaml] --> Validator

    Validator --> Check{Safe?}
    Check -->|Yes| Execute[Execute Command]
    Check -->|No| Reject[Reject with Error]

    subgraph Patterns
    Plain[Plain Text Patterns]
    Regex[Regular Expression Patterns]
    end

    ExcludeYAML --> Patterns

Blocked Command Categories

The command exclusion system blocks several categories of potentially harmful commands:

  • System modification (apt, yum, etc.)
  • File deletion/modification (rm -rf, etc.)
  • System control (shutdown, reboot, etc.)
  • User/permission changes (chmod, sudo, etc.)
  • Network operations (wget, curl, etc.)
  • Command chaining to bypass filters (&&, |, etc.)
  • Script execution (bash, python, etc.)
  • Filesystem traversal (../, etc.)

Docker Security

The server runs as a non-root user within the Docker container to limit potential damage from security breaches.

๐Ÿ’ป Development

Project Structure

mcp_command_server/
โ”œโ”€โ”€ .context                 # API documentation markdown
โ”œโ”€โ”€ Cargo.toml               # Rust dependencies
โ”œโ”€โ”€ Dockerfile               # Multi-stage Docker build
โ”œโ”€โ”€ exclude.yaml             # Command exclusion patterns
โ”œโ”€โ”€ docker-compose.yml       # Docker Compose configuration
โ”œโ”€โ”€ src/
โ”‚   โ”œโ”€โ”€ main.rs              # Main server code
โ”‚   โ”œโ”€โ”€ command.rs           # Command execution logic
โ”‚   โ”œโ”€โ”€ rpc.rs               # JSON-RPC handling
โ”‚   โ””โ”€โ”€ validator.rs         # Command validation logic
โ””โ”€โ”€ docs/
    โ”œโ”€โ”€ README.md            # Documentation for the Postman collection
    โ””โ”€โ”€ mcp_command_server.postman_collection.json  # Postman collection

Dependencies

  • Rust : Primary programming language
  • tokio : Async runtime for Rust
  • warp : Web server framework
  • serde & serde_json : Serialization/deserialization
  • serde_yaml : YAML parsing for exclusion patterns
  • regex : Regular expression support for command validation

๐Ÿงช Testing

Using the Postman Collection

A comprehensive Postman collection is included in the docs/ directory for testing the API:

  1. Import docs/mcp_command_server.postman_collection.json into Postman
  2. Run individual requests or the entire collection
  3. The collection includes tests for:
    * Basic commands
    * Error handling
    * Command execution
    * File operations
    * Security validation

Manual Testing

Test basic functionality with curl:

# Test the context endpoint
curl http://localhost:3030/context

# Execute a simple command
curl -X POST -H "Content-Type: application/json" -d '{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "command/get",
  "params": {
    "command": "echo \"Hello World\""
  }
}' http://localhost:3030/

๐Ÿ‘ฅ Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

๐Ÿ“„ License

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


Built with โค๏ธ using Rust and Docker.

Related MCP Servers & Clients