MCP Command Server
A server for securely executing commands on the host system, requiring Java 21 or higher.
MCP Command Server
A Model Context Protocol (MCP) server that enables secure command execution on the host system. This server allows AI assistants like Claude to run shell commands with optional working directory and stdin support.
The project is now modularized to support multiple transport methods: stdio, HTTP, and Server-Sent Events (SSE).
Features
- Command Execution: Run any shell command on the host system
- Working Directory Support: Execute commands in specific directories
- STDIN Support: Pipe input data to commands
- Cross-Platform: Works on macOS, Linux, and Windows
- Timeout Protection: Commands timeout after 60 seconds to prevent hanging
- Special Fish Shell Support: Enhanced handling for the Fish shell
- Advanced Logging: Powered by Logback with configurable log levels (ERROR, WARN, INFO, DEBUG, TRACE), optional file logging, and rolling file support
Prerequisites
- Java 25 or higher
- Gradle (for building from source)
- Claude Desktop app (for integration)
Installation
Building from Source
- Clone the repository:
git clone <repository-url>
cd mcp-server-command
- Build the project:
./gradlew build
This will create JAR files for each module:
stdio/build/libs/stdio-1.0.0.jar- Standard I/O transport (recommended for Claude Desktop)http/build/libs/http-1.0.0.jar- HTTP transportsse/build/libs/sse-1.0.0.jar- Server-Sent Events transport
Native Binary (Optional)
For better performance, you can build a native binary using GraalVM:
./gradlew stdio:nativeCompile
This creates a native executable at stdio/build/native/nativeCompile/mcp-server-command
Pre-built JAR
If you have a pre-built JAR, skip the building step and proceed to configuration.
Configuration
Claude Desktop Integration
-
Locate your Claude Desktop configuration:
- macOS:
~/Library/Application Support/Claude/claude_desktop_config.json - Windows:
%APPDATA%\Claude\claude_desktop_config.json - Linux:
~/.config/Claude/claude_desktop_config.json
- macOS:
-
Add the MCP server configuration:
Option A: Java JAR (Recommended)
{
"mcpServers": {
"mcp-server-command": {
"command": "java",
"args": [
"-jar",
"/absolute/path/to/stdio-1.0.0.jar"
],
"env":{
"LOG_DIR":"/Users/<username>/Library/Logs/Claude",
"LOG_LEVEL":"DEBUG"
}
}
}
}
Option B: Native Binary
{
"mcpServers": {
"mcp-server-command": {
"command": "/absolute/path/to/stdio/build/native/nativeCompile/mcp-server-command",
"env":{
"LOG_DIR":"/Users/<username>/Library/Logs/Claude",
"LOG_LEVEL":"DEBUG"
}
}
}
}
- Restart Claude Desktop to load the new server
Usage
Once configured, Claude can use the run_command tool to execute commands on your system.
Basic Examples
Simple command execution:
Run the command: ls -la
Command with working directory:
Run 'git status' in the directory /Users/username/my-project
Command with stdin:
Create a new file called hello.txt with the content "Hello, World!" using the cat command
Python script execution:
Run this Python script:
print("Hello from Python")
for i in range(5):
print(f"Count: {i}")
API Reference
Tool: run_command
Executes a command on the host system.
Parameters:
command(string, required): The command to execute with argumentsworkdir(string, optional): The working directory for command executionstdin(string, optional): Text to pipe into the command's STDIN
Returns:
stdout: Standard output from the commandstderr: Standard error output from the commandmessage: Error message if command failsisError: Boolean indicating if the command failed
Example Request:
{
"jsonrpc": "2.0",
"method": "tools/call",
"id": 1,
"params": {
"name": "run_command",
"arguments": {
"command": "echo Hello World",
"workdir": "/tmp",
"stdin": "Input data"
}
}
}
Development
Project Structure
mcp-server-command/
├── stdio/ # Standard I/O transport module
│ ├── src/main/java/com/brunorozendo/mcp/
│ │ └── McpServer.java # Main server entry point
│ └── build.gradle
├── http/ # HTTP transport module
│ ├── src/main/java/com/brunorozendo/mcp/
│ │ └── McpServer.java # HTTP server implementation
│ └── build.gradle
├── sse/ # Server-Sent Events transport module
│ ├── src/main/java/com/brunorozendo/mcp/
│ │ └── McpServer.java # SSE server implementation
│ └── build.gradle
├── tools/ # Shared command execution logic
│ ├── src/main/java/com/brunorozendo/mcp/
│ │ ├── CommandExecutor.java # Command execution logic
│ │ ├── CommandResult.java # Result data structure
│ │ ├── ExecCommandTool.java # Tool implementation
│ │ ├── Transport.java # Transport configuration
│ │ └── ToolSchemas.java # Tool schema definitions
│ └── build.gradle
├── settings.gradle # Multi-module configuration
└── docs/ # Documentation
Running Tests
Execute the test script to verify functionality:
./test_server.sh
Building a Distribution
Create distribution archives (ZIP and TAR):
./gradlew distZip distTar
Security Considerations
⚠️ WARNING: This server executes commands with the same privileges as the user running the Java process.
Security Best Practices:
- Only install this server if you trust the AI assistant
- Run the server with minimal necessary privileges
- Consider using a restricted user account for the server
- Be cautious when sharing your screen or command outputs
- Regularly review which commands are being executed
- Consider implementing command whitelisting for production use
Potential Risks:
- File system access and modification
- Network operations
- Process execution
- Access to environment variables and system information
Troubleshooting
Server not appearing in Claude
- Verify the configuration file path is correct
- Ensure the JAR file path is absolute, not relative
- Check that Java 25+ is installed:
java -version - Restart Claude Desktop after configuration changes
Commands failing
- Set log level to DEBUG or TRACE to see detailed error messages
- Check file permissions for the working directory
- Verify the command syntax is correct for your shell
- Test commands directly in terminal first
Timeout errors
- Commands timeout after 60 seconds
- For long-running commands, consider breaking them into smaller steps
- Use background processes with caution
Advanced Usage
Creating Files
# Using cat with stdin
echo "File content" | cat > newfile.txt
# Or directly with stdin parameter
cat > newfile.txt
# with stdin: "File content"
Running Scripts
# Python
python3 -c "print('Hello')"
# Or with stdin for longer scripts
python3
# with stdin: <your script content>
Fish Shell Support
The server includes special handling for Fish shell to properly handle stdin:
fish -c "echo $USER"
Version History
- 1.0.0 - Current version with modular architecture
- Modular design with stdio, HTTP, and SSE transport support
- Command execution with timeout protection
- Working directory support
- STDIN support
- Special Fish shell handling
- Advanced Logback-based logging with file rotation support
- Updated to MCP SDK 0.17.0
- Java 25 support
- GraalVM native compilation support
Custom Logback Configuration
For advanced users, you can provide your own logback.xml configuration file:
- Create your custom
logback.xml - Place it in the classpath or specify its location with
-Dlogback.configurationFile=/path/to/logback.xml
License
[Add your license information here]
Contributing
[Add contribution guidelines if applicable]
Support
For issues and questions:
- Check the troubleshooting section
- Set appropriate log level for debugging
- [Add support contact/repository issues link]
Verwandte Server
Alpha Vantage MCP Server
SponsorAccess financial market data: realtime & historical stock, ETF, options, forex, crypto, commodities, fundamentals, technical indicators, & more
Script Generator Server
A simple note storage system with tools for adding notes and generating scripts from them.
Semgrep
Static code analysis using Semgrep for security vulnerability detection and code quality improvements.
Text-To-GraphQL
MCP server for text-to-graphql, integrates with Claude Desktop and Cursor.
Console Automation
Production-ready MCP server for AI-driven console automation and monitoring. 40+ tools for session management, SSH, testing, and background jobs.
Structurize-MCP
Generates structured CSV files from natural language descriptions using Google Gemini AI.
Chronos Protocol
A robust MCP server that eliminates temporal blindness in AI coding agents through intelligent time tracking, persistent memory, and complete session traceability.
LambdaTest MCP Server
LambdaTest MCP Servers ranging from Accessibility, SmartUI, Automation, and HyperExecute allows you to connect AI assistants with your testing workflow, streamlining setup, analyzing failures, and generating fixes to speed up testing and improve efficiency.
Remote MCP Server (Authless)
An example of a remote MCP server deployable on Cloudflare Workers without authentication.
Pprof Analyzer
Analyze Go pprof performance profiles (CPU, heap, goroutine, etc.) and generate flamegraphs.
OpenAI Image Generation
Generate and edit images using OpenAI's DALL-E models via the official Python SDK.