MCP cover image
See in Github
2025-01-20

An MCP server that provides secure terminal access for Claude and other LLMs

1

Github Watches

3

Github Forks

2

Github Stars

MCP Terminal Server

A secure terminal execution server implementing the Model Context Protocol (MCP). This server provides controlled command execution capabilities with security features and resource limits.

Features

  • Command Execution: Execute shell commands with output capture and error handling
  • Security Controls: Restrict allowed commands and prevent command injection
  • Resource Controls:
    • Command timeouts
    • Maximum output size limits
  • MCP Protocol Support:
    • Standard MCP message format
    • Capability advertisement
    • Streaming output support

Development

Local Setup

# 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 .venv\Scripts\activate on Windows

# Install development dependencies
uv pip install -e ".[dev]"

Publishing to PyPI

# Build the package
uv pip install build
python -m build

# Upload to PyPI
uv pip install twine
python -m twine upload dist/*

Testing with MCP Inspector

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"

Running Tests

# Run all tests
pytest tests/

# Run specific test file
pytest tests/test_terminal.py

# Run with coverage
pytest --cov=mcp_terminal tests/

Using with Claude Desktop

Once the package is published to PyPI:

  1. Install UV (if not already installed):

    pip install uv
    
  2. Install the Package using UV:

    uv pip install mcp-terminal
    
  3. Configure Claude Desktop: Edit your Claude Desktop config file (typically at ~/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"
          ]
        }
      }
    }
    

Protocol Implementation

The server implements the Model Context Protocol (MCP) with the following capabilities:

Capabilities Advertisement

{
  "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" }
        }
      }
    }
  }
}

Message Format

Request:

{
  "type": "execute",
  "data": {
    "command": "echo 'hello world'"
  }
}

Response:

{
  "type": "result",
  "data": {
    "command": "echo 'hello world'",
    "exitCode": 0,
    "stdout": "hello world\n",
    "stderr": "",
    "startTime": "2024-01-20T12:34:56.789Z",
    "endTime": "2024-01-20T12:34:56.790Z"
  }
}

Error:

{
  "type": "error",
  "data": {
    "message": "command not allowed"
  }
}

Security Considerations

  1. Command Validation:

    • Only allowed commands can be executed
    • Shell operators are blocked
    • Command injection attempts are prevented
  2. Resource Protection:

    • Command timeouts prevent hanging
    • Output size limits prevent memory exhaustion
    • Error handling for all failure cases
  3. Best Practices:

    • Always set allowed-commands in production
    • Use conservative timeout and size limits
    • Monitor command execution logs

Contributing

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

License

This project is licensed under the MIT License - see the LICENSE file for details.

相关推荐

  • NiKole Maxwell
  • I craft unique cereal names, stories, and ridiculously cute Cereal Baby images.

  • https://suefel.com
  • Latest advice and best practices for custom GPT development.

  • Yusuf Emre Yeşilyurt
  • I find academic articles and books for research and literature reviews.

  • https://maiplestudio.com
  • Find Exhibitors, Speakers and more

  • Carlos Ferrin
  • Encuentra películas y series en plataformas de streaming.

  • Bora Yalcin
  • Evaluator for marketplace product descriptions, checks for relevancy and keyword stuffing.

  • Joshua Armstrong
  • Confidential guide on numerology and astrology, based of GG33 Public information

  • Contraband Interactive
  • Emulating Dr. Jordan B. Peterson's style in providing life advice and insights.

  • Jan Meindl
  • Builds new GPTs

  • rustassistant.com
  • Your go-to expert in the Rust ecosystem, specializing in precise code interpretation, up-to-date crate version checking, and in-depth source code analysis. I offer accurate, context-aware insights for all your Rust programming questions.

  • https://jgadvisorycpa.com
  • This GPT assists in finding a top-rated business CPA - local or virtual. We account for their qualifications, experience, testimonials and reviews. Business operators provide a short description of your business, services wanted, and city or state.

  • Elijah Ng Shi Yi
  • Advanced software engineer GPT that excels through nailing the basics.

  • apappascs
  • Discover the most comprehensive and up-to-date collection of MCP servers in the market. This repository serves as a centralized hub, offering an extensive catalog of open-source and proprietary MCP servers, complete with features, documentation links, and contributors.

  • Mintplex-Labs
  • The all-in-one Desktop & Docker AI application with built-in RAG, AI agents, No-code agent builder, MCP compatibility, and more.

  • modelcontextprotocol
  • Model Context Protocol Servers

  • ShrimpingIt
  • Micropython I2C-based manipulation of the MCP series GPIO expander, derived from Adafruit_MCP230xx

  • OffchainLabs
  • Go implementation of Ethereum proof of stake

  • n8n-io
  • Fair-code workflow automation platform with native AI capabilities. Combine visual building with custom code, self-host or cloud, 400+ integrations.

  • WangRongsheng
  • 🧑‍🚀 全世界最好的LLM资料总结(Agent框架、辅助编程、数据处理、模型训练、模型推理、o1 模型、MCP、小语言模型、视觉语言模型) | Summary of the world's best LLM resources.

    Reviews

    2 (1)
    Avatar
    user_SFyeFDUa
    2025-04-15

    I've been using mcp-server-demo for a while now, and it has significantly enhanced my productivity. Kahnwong has done a fantastic job with this application. The user interface is intuitive, and the functionalities are robust. From seamless navigation to efficient data management, everything works perfectly. Highly recommend checking it out at https://mcp.so/server/mcp-server-demo/kahnwong!