mcp terminal
A secure terminal execution server that enables controlled command execution with security features and resource limits via the Model Context Protocol (MCP).
A secure terminal execution server that enables controlled command execution with security features and resource limits via the Model Context Protocol (MCP).
A secure terminal execution server implementing the Model Context Protocol (MCP). This server provides controlled command execution capabilities with security features and resource limits.
# Clone the repository
git clone https://github.com/RinardNick/mcp-terminal.git
cd mcp-terminal
# Create and activate virtual environment using uv
uv venv
source .venv/bin/activate # or .venvScriptsactivate on Windows
# Install development dependencies
uv pip install -e ".[dev]"
# Build the package
uv pip install build
python -m build
# Upload to PyPI
uv pip install twine
python -m twine upload dist/*
The MCP Inspector tool can be used to test the server implementation:
# Install inspector
npm install -g @modelcontextprotocol/inspector
# Test server
npx @modelcontextprotocol/inspector python3 src/mcp_terminal/server.py --allowed-commands "python,pip,git,ls,cd"
# Run all tests
pytest tests/
# Run specific test file
pytest tests/test_terminal.py
# Run with coverage
pytest --cov=mcp_terminal tests/
Once the package is published to PyPI:
pip install uv
uv pip install mcp-terminal
~/Library/Application Support/Claude/claude_desktop_config.json
on macOS):{
"mcpServers": {
"terminal": {
"command": "uv",
"args": [
"pip",
"run",
"mcp-terminal",
"--allowed-commands",
"python,pip,git,ls,cd",
"--timeout-ms",
"30000",
"--max-output-size",
"1048576"
]
}
}
}
The server implements the Model Context Protocol (MCP) with the following capabilities:
{
"protocol": "1.0.0",
"name": "terminal",
"version": "1.1.0",
"capabilities": {
"execute": {
"description": "Execute a terminal command",
"parameters": {
"command": {
"type": "string",
"description": "The command to execute"
}
},
"returns": {
"type": "object",
"properties": {
"exitCode": { "type": "number" },
"stdout": { "type": "string" },
"stderr": { "type": "string" },
"startTime": { "type": "string" },
"endTime": { "type": "string" }
}
}
}
}
}
Request:
{
"type": "execute",
"data": {
"command": "echo 'hello world'"
}
}
Response:
{
"type": "result",
"data": {
"command": "echo 'hello world'",
"exitCode": 0,
"stdout": "hello worldn",
"stderr": "",
"startTime": "2024-01-20T12:34:56.789Z",
"endTime": "2024-01-20T12:34:56.790Z"
}
}
Error:
{
"type": "error",
"data": {
"message": "command not allowed"
}
}
Command Validation:
Only allowed commands can be executed
Command injection attempts are prevented
Resource Protection:
Command timeouts prevent hanging
Error handling for all failure cases
Best Practices:
allowed-commands
in productiongit checkout -b feature/amazing-feature
)git commit -m 'Add some amazing feature'
)git push origin feature/amazing-feature
)This project is licensed under the MIT License - see the LICENSE file for details.
[
{
"description": "Run a terminal command with security controls.",
"inputSchema": {
"properties": {
"allowedCommands": {
"description": "Optional list of allowed command executables",
"items": {
"type": "string"
},
"type": "array"
},
"command": {
"description": "The command to execute",
"type": "string"
},
"maxOutputSize": {
"description": "Maximum output size in bytes (default: 1MB)",
"type": "number"
},
"timeoutMs": {
"description": "Maximum execution time in milliseconds (default: 30 seconds)",
"type": "number"
}
},
"required": [
"command"
],
"type": "object"
},
"name": "run_command"
}
]