Sponsored by Deepsite.site

Terminal MCP Server

Created By
bhanuchaddha8 months ago
Content

Terminal 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

  1. Terminal Command Execution

    • Execute any terminal command
    • Get stdout, stderr, and return code
    • Error handling
  2. Security Vulnerability Demo

    • magical_tool demonstrates unsafe command execution
    • Shows how malicious code can be executed
    • Highlights importance of secure implementation
  3. Terminal Command Cheat Sheet

    • 30 essential terminal commands
    • Common options and flags
    • Usage examples

Installation

  1. Create a virtual environment:
uv venv
  1. Activate the virtual environment:
source .venv/bin/activate
  1. Install dependencies:
uv pip install -e .

Adding to Claude

  1. Locate Claude's desktop configuration file:
~/Library/Application Support/Claude/claude_desktop_config.json
  1. 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.

  1. 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.

  1. Install MCP Inspector:
npm install -g @modelcontextprotocol/inspector
  1. 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:

  1. run_command tool:
# 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
  1. 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
  1. terminal_commands_cheat_sheet resource:
# 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:

  1. Command Injection
  2. Arbitrary File Access
  3. System Manipulation

This is intentionally included as an educational example of what NOT to do in production systems.

Development

  1. Clone the repository
  2. Create and activate virtual environment as shown above
  3. Install dependencies
  4. 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

Recommend Servers
TraeBuild with Free GPT-4.1 & Claude 3.7. Fully MCP-Ready.
MiniMax MCPOfficial MiniMax Model Context Protocol (MCP) server that enables interaction with powerful Text to Speech, image generation and video generation APIs.
ChatWiseThe second fastest AI chatbot™
WindsurfThe new purpose-built IDE to harness magic
BlenderBlenderMCP connects Blender to Claude AI through the Model Context Protocol (MCP), allowing Claude to directly interact with and control Blender. This integration enables prompt assisted 3D modeling, scene creation, and manipulation.
Baidu Map百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
CursorThe AI Code Editor
Playwright McpPlaywright MCP server
MCP AdvisorMCP Advisor & Installation - Use the right MCP server for your needs
Serper MCP ServerA Serper MCP Server
DeepChatYour AI Partner on Desktop
Jina AI MCP ToolsA Model Context Protocol (MCP) server that integrates with Jina AI Search Foundation APIs.
Zhipu Web SearchZhipu Web Search MCP Server is a search engine specifically designed for large models. It integrates four search engines, allowing users to flexibly compare and switch between them. Building upon the web crawling and ranking capabilities of traditional search engines, it enhances intent recognition capabilities, returning results more suitable for large model processing (such as webpage titles, URLs, summaries, site names, site icons, etc.). This helps AI applications achieve "dynamic knowledge acquisition" and "precise scenario adaptation" capabilities.
Howtocook Mcp基于Anduin2017 / HowToCook (程序员在家做饭指南)的mcp server,帮你推荐菜谱、规划膳食,解决“今天吃什么“的世纪难题; Based on Anduin2017/HowToCook (Programmer's Guide to Cooking at Home), MCP Server helps you recommend recipes, plan meals, and solve the century old problem of "what to eat today"
Visual Studio Code - Open Source ("Code - OSS")Visual Studio Code
AiimagemultistyleA Model Context Protocol (MCP) server for image generation and manipulation using fal.ai's Stable Diffusion model.
Amap Maps高德地图官方 MCP Server
Tavily Mcp
TimeA Model Context Protocol server that provides time and timezone conversion capabilities. This server enables LLMs to get current time information and perform timezone conversions using IANA timezone names, with automatic system timezone detection.
EdgeOne Pages MCPAn MCP service designed for deploying HTML content to EdgeOne Pages and obtaining an accessible public URL.
Context7Context7 MCP Server -- Up-to-date code documentation for LLMs and AI code editors