About Terminal MCP Server
Terminal MCP Server exposes terminal command execution and a command cheat sheet, while also illustrating unsafe execution patterns for developers studying MCP security.
Key features
- 01Run terminal commands and return output
- 02Report errors and exit codes
- 03Provide a command cheat sheet
- 04Demonstrate unsafe command execution
Use cases
- 01Run terminal commands through an MCP client
- 02Review common terminal commands and examples
- 03Study command-injection risks in MCP implementations
MCP support
An MCP server exposing the `run_command` and `magical_tool` tools, plus the `terminal_commands_cheat_sheet` resource. It can be configured for Claude Desktop.
Configuration
Local server config is the same for every client. Copy it into your client’s MCP config file.
We haven’t collected a package or remote endpoint for this server. Follow the instructions in the project README.
Tools
Local servers expose tools only once running on your machine, and the maintainer has not provided a tool list.
Details
From the project READMETerminal MCP Server
A simple MCP server that executes terminal commands and provides a terminal command cheat sheet. Also demonstrates potential security vulnerabilities in MCP server implementations.
Features
-
Terminal Command Execution
- Execute any terminal command
- Get stdout, stderr, and return code
- Error handling
-
Security Vulnerability Demo
- magical_tool demonstrates unsafe command execution
- Shows how malicious code can be executed
- Highlights importance of secure implementation
-
Terminal Command Cheat Sheet
- 30 essential terminal commands
- Common options and flags
- Usage examples
Installation
- Create a virtual environment:
uv venv
- Activate the virtual environment:
source .venv/bin/activate
- Install dependencies:
uv pip install -e .
Adding to Claude
- Locate Claude's desktop configuration file:
~/Library/Application Support/Claude/claude_desktop_config.json
- Add the terminal server configuration:
{
"mcpServers": {
"terminal": {
"command": "/path/to/terminal-mcp-server/.venv/bin/python",
"args": [
"/path/to/terminal-mcp-server/src/server.py"
]
}
}
}
Replace /path/to/terminal-mcp-server with the actual path where you cloned this repository.
- Restart Claude to load the new configuration.
Testing with MCP Inspector
You can test the MCP server using the MCP Inspector tool, which provides a web interface for interacting with MCP servers.
- Install MCP Inspector:
npm install -g @modelcontextprotocol/inspector
- In another terminal, run the inspector:
npx @modelcontextprotocol/inspector
This will start a web application locally where you can:
- Connect to your MCP server
- Test all available tools
- View tool responses
- Inspect resources
- Debug communication
Usage
The server provides:
run_commandtool:
# Safe command execution
result = await run_command("ls -la")
print(result["stdout"]) # Command output
print(result["stderr"]) # Any errors
print(result["return_code"]) # Exit code
magical_tool:
# WARNING: Demonstrates unsafe command execution
# Shows how external commands can be executed without proper validation
result = await magical_tool()
print(result["stdout"]) # Executed command output
print(result["stderr"]) # Any errors
print(result["return_code"]) # Command exit code
terminal_commands_cheat_sheetresource:
# Access terminal commands cheat sheet
commands = await terminal_commands_cheat_sheet()
print(commands) # List of commands with examples
Security Implications
The magical_tool demonstrates a common security vulnerability where user inputs or file paths are used directly in command execution without proper validation. This could allow:
- Command Injection
- Arbitrary File Access
- System Manipulation
This is intentionally included as an educational example of what NOT to do in production systems.
Development
- Clone the repository
- Create and activate virtual environment as shown above
- Install dependencies
- Run the server:
uv run src/server.py
Error Handling
- All tools handle errors gracefully
- Failed commands return error messages in stderr
- Resource access failures return error messages
- Non-zero return codes indicate command failures
License
MIT
Comments
New to MCP?
From what the protocol is to installing your first server, these answers cover most first questions.
An open protocol that defines how AI applications connect to external tools and data in a uniform way. Clients talk to the model; MCP servers provide tools, resources and prompt templates. They exchange standard messages, so one server can be reused by many clients.