Command Executor
Execute pre-approved shell commands securely on a server.
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:
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:
-
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
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:
-
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.
Related Servers
Scout Monitoring MCP
sponsorPut performance and error data directly in the hands of your AI assistant.
Alpha Vantage MCP Server
sponsorAccess financial market data: realtime & historical stock, ETF, options, forex, crypto, commodities, fundamentals, technical indicators, & more
Dify Workflows
An MCP server for executing Dify workflows, configured via environment variables or a config file.
MCP RAG Server
A Python server providing Retrieval-Augmented Generation (RAG) functionality. It indexes various document formats and requires a PostgreSQL database with pgvector.
IDA Pro
Interact with IDA Pro for reverse engineering and binary analysis tasks.
Remote MCP Server (Authless)
An example of a remote MCP server deployable on Cloudflare Workers without authentication.
Second Opinion MCP Server
An AI-powered coding assistant that combines insights from Gemini, Stack Overflow, and Perplexity AI to help solve programming problems.
Verilator MCP Server
An MCP server for Verilator providing RTL simulation, automatic testbench generation, and natural language query capabilities.
Remote MCP Server (Authless)
An example remote MCP server deployable on Cloudflare Workers without authentication.
CC Token Saver
Use a local LLM for smaller or specialized tasks within Claude to save tokens.
Postman MCP Server
Interact with the Postman API via an MCP server. Requires a Postman API key.
Remote MCP Server (Authless)
A template for deploying a remote MCP server on Cloudflare Workers without authentication.