The Command Executor MCP Server securely executes pre-approved commands with robust security measures.
Execute Pre-Approved Commands: Run commands like
git
,ls
,mkdir
,cd
,npm
,npx
, andpython
securely.Customizable Allowlist: Configure allowed commands via the
ALLOWED_COMMANDS
environment variable.Secure Execution: Implements validation, pre-approved command lists, and environment isolation.
Real-Time Output: Streams command output in real-time.
Error Handling: Provides detailed error messages for unauthorized commands and execution failures.
Usage: Offers a single tool named
execute_command
with acommand
parameter to trigger execution.
command-executor MCP Server
A Model Context Protocol server for executing pre-approved commands securely.
🎥 Demo
https://github.com/user-attachments/assets/ed763a12-b685-4e0b-b9a5-bc948a590f51
✨ 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:
Build the server:
For development with auto-rebuild:
⚙️ 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:
🔌 Claude Desktop Integration
To use with Claude Desktop, add the server config:
On MacOS:
On Windows:
Configuration example:
🛡️ Security Considerations
The command-executor server implements several security measures:
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
Command Validation
Command prefix validation prevents command injection
No shell execution for improved security
Environment variables are properly sanitized
Error Handling
Comprehensive error handling for unauthorized commands
Clear error messages for debugging
Failed commands don't crash the server
Environment Isolation
Server runs in its own environment
Environment variables can be controlled
Limited system access
💻 Development
📁 Project Structure
🐛 Debugging
Since MCP servers communicate over stdio, debugging can be challenging. We recommend using the MCP 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:
Example Response:
Error Response:
❌ Error Handling
The server provides detailed error messages for various scenarios:
Unauthorized Commands
{ "code": "InvalidParams", "message": "Command not allowed: [command]. Allowed commands: git, ls, mkdir, cd, npm, npx, python" }Execution Failures
{ "content": [ { "type": "text", "text": "Command execution failed: [error message]" } ], "isError": true }
🤝 Contributing
Fork the repository
Create your feature branch
Commit your changes
Push to the branch
Create a new Pull Request
📄 License
This project is licensed under the MIT License - see the LICENSE file for details.
A Model Context Protocol server that allows secure execution of pre-approved commands, enabling AI assistants to safely interact with the user's system.
- 🎥 Demo
- ✨ Features
- 🚀 Installation
- ⚙️ Configuration
- 🛡️ Security Considerations
- 💻 Development
- 🛠️ Tool API
- ❌ Error Handling
- 🤝 Contributing
- 📄 License
Related Resources
Related MCP Servers
- -securityFlicense-qualityA comprehensive Model Context Protocol server implementation that enables AI assistants to interact with file systems, databases, GitHub repositories, web resources, and system tools while maintaining security and control.Last updated -331
- AsecurityAlicenseAqualityA secure Model Context Protocol server that allows AI models to safely interact with Windows command-line functionality, enabling controlled execution of system commands, project creation, and system information retrieval.Last updated -87MIT License
- -securityFlicense-qualityA Model Context Protocol server that provides secure curl command execution capabilities, allowing AI assistants to make HTTP requests with configurable parameters and built-in security protections.Last updated -1
- AsecurityAlicenseAqualityA Model Context Protocol server that enables AI assistants to communicate with each other using Inter-Process Communication, featuring natural language commands and cross-platform compatibility.Last updated -9104MIT License