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]
관련 서버
Scout Monitoring MCP
스폰서Put performance and error data directly in the hands of your AI assistant.
Alpha Vantage MCP Server
스폰서Access financial market data: realtime & historical stock, ETF, options, forex, crypto, commodities, fundamentals, technical indicators, & more
MCP Android Agent
Automate Android devices using the uiautomator2 library, requiring adb and a connected device.
Kali AI Pentest MCP Tools
An AI penetration testing tool that uses natural language to operate various security tools like nmap, sqlmap, and metasploit.
Flutter MCP
Provides real-time Flutter/Dart documentation and pub.dev package information to AI assistants, supporting all packages on demand.
SpecBridge
Automatically generates MCP tools from OpenAPI specifications by scanning a folder for spec files. No configuration is needed and it supports authentication via environment variables.
Gemini CLI
Integrates with the unofficial Google Gemini CLI, allowing file access within configured directories.
UML-MCP
A diagram generation server supporting multiple UML and other diagram types, with various output formats. It integrates with rendering services like Kroki and PlantUML.
Vercel v0
Generate beautiful UI components using Vercel's v0 generative UI system.
LAML MCP Server
Loads and validates LAML (YAML-based markup language) documents via the Model Context Protocol.
MetaTrader 4
Integrate with the MetaTrader 4 trading platform to access trading functions and data via an HTTP bridge and Expert Advisor.
Arch Tools
53 production-ready AI tools via MCP with x402 USDC payments on Base L2 — web scraping, crypto data, AI generation, OCR, and more.