Fire in da houseTop Tip:Paying $100+ per month for Perplexity, MidJourney, Runway, ChatGPT and other tools is crazy - get all your AI tools in one site starting at $15 per month with Galaxy AI Fire in da houseCheck it out free

command-executor-mcp-server

MCP.Pizza Chef: Sunwood-ai-labs

The command-executor-mcp-server is a secure Model Context Protocol server designed to execute only pre-approved commands. It ensures safe command execution by enforcing a configurable whitelist of allowed commands, set via environment variables. Built with TypeScript and the MCP SDK, it communicates through stdio for seamless integration with MCP clients. The server supports real-time streaming of command outputs and robust error handling, making it ideal for controlled automation workflows where security and command validation are critical.

Use This MCP server To

Execute pre-approved shell commands securely Stream real-time output of executed commands Integrate command execution in AI workflows Validate commands against a whitelist Automate system tasks with strict security Enable safe remote command execution Monitor command execution status in real-time

README

command-executor MCP Server

Command Executor MCP Server

EN doc JA doc

A Model Context Protocol server for executing pre-approved commands securely.

🎥 Demo

Timeline.116.mp4

✨ Features

  • Secure command execution with pre-approved command list
  • Configurable allowed commands through environment variables
  • Built with TypeScript and MCP SDK
  • Communication via stdio for seamless integration
  • Error handling and security validations
  • Real-time command output streaming

🚀 Installation

Install dependencies:

npm install

Build the server:

npm run build

For development with auto-rebuild:

npm run watch

⚙️ Configuration

🔒 Allowed Commands

By default, the following commands are allowed:

  • git
  • ls
  • mkdir
  • cd
  • npm
  • npx
  • python

You can customize the allowed commands by setting the ALLOWED_COMMANDS environment variable:

export ALLOWED_COMMANDS=git,ls,mkdir,python

🔌 Claude Desktop Integration

To use with Claude Desktop, add the server config:

On MacOS:

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

On Windows:

%APPDATA%/Claude/claude_desktop_config.json

Configuration example:

{
  "mcpServers": {
    "command-executor": {
      "command": "/path/to/command-executor/build/index.js"
    }
  }
}

🛡️ Security Considerations

The command-executor server implements several security measures:

  1. Pre-approved Command List

    • Only explicitly allowed commands can be executed
    • Default list is restrictive and security-focused
    • Commands are validated by prefix to prevent injection
  2. Command Validation

    • Command prefix validation prevents command injection
    • No shell execution for improved security
    • Environment variables are properly sanitized
  3. Error Handling

    • Comprehensive error handling for unauthorized commands
    • Clear error messages for debugging
    • Failed commands don't crash the server
  4. Environment Isolation

    • Server runs in its own environment
    • Environment variables can be controlled
    • Limited system access

💻 Development

📁 Project Structure

command-executor/
├─ src/
│  └─ index.ts      # Main server implementation
├─ build/
│  └─ index.js      # Compiled JavaScript
├─ assets/
│  └─ header.svg    # Project header image
└─ package.json     # Project configuration

🐛 Debugging

Since MCP servers communicate over stdio, debugging can be challenging. We recommend using the MCP Inspector:

npm run inspector

The Inspector will provide a URL to access debugging tools in your browser.

🛠️ Tool API

The server provides a single tool:

execute_command

Executes a pre-approved command.

Parameters:

  • command (string, required): The command to execute

Example Request:

{
  "name": "execute_command",
  "arguments": {
    "command": "git status"
  }
}

Example Response:

{
  "content": [
    {
      "type": "text",
      "text": "On branch main\nNothing to commit, working tree clean"
    }
  ]
}

Error Response:

{
  "content": [
    {
      "type": "text",
      "text": "Command execution failed: Command not allowed"
    }
  ],
  "isError": true
}

❌ Error Handling

The server provides detailed error messages for various scenarios:

  1. Unauthorized Commands

    {
      "code": "InvalidParams",
      "message": "Command not allowed: [command]. Allowed commands: git, ls, mkdir, cd, npm, npx, python"
    }
  2. Execution Failures

    {
      "content": [
        {
          "type": "text",
          "text": "Command execution failed: [error message]"
        }
      ],
      "isError": true
    }

🤝 Contributing

  1. Fork the repository
  2. Create your feature branch
  3. Commit your changes
  4. Push to the branch
  5. Create a new Pull Request

📄 License

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

command-executor-mcp-server FAQ

How does the command-executor-mcp-server ensure security?
It restricts execution to a pre-approved list of commands configured via environment variables, preventing unauthorized command runs.
Can I customize which commands are allowed?
Yes, allowed commands are configurable through environment variables to fit your specific security policies.
How does the server communicate with MCP clients?
It uses standard input/output (stdio) streams for seamless and efficient communication.
Does the server support real-time output streaming?
Yes, it streams command output in real-time to provide immediate feedback during execution.
What programming language is the server built with?
The server is developed in TypeScript using the MCP SDK for robust and type-safe implementation.
How does the server handle errors during command execution?
It includes comprehensive error handling and security validations to ensure safe operation.
Is this server compatible with multiple LLM providers?
Yes, it is designed to work with any MCP client, supporting models like OpenAI, Claude, and Gemini.
How do I install and build the command-executor-mcp-server?
Install dependencies with 'npm install' and follow the build instructions in the README.