mcp-terminal-server

abhisvakil/mcp-terminal-server

3.2

If you are the rightful owner of mcp-terminal-server and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to henry@mcphub.com.

The MCP Terminal Server is a secure bridge that allows Claude AI to manage local files and directories through terminal commands.

MCP Terminal Server ๐Ÿš€

My first Model Context Protocol (MCP) server that enables Claude AI to manage local files and directories through terminal commands. This project demonstrates how to create a secure bridge between AI assistants and your local development environment.

๐ŸŒŸ What is MCP?

Model Context Protocol (MCP) is a protocol that allows AI assistants like Claude to communicate with external tools and services on your local machine. It's like a secure bridge between the AI and your system, enabling powerful local development workflows.

๐ŸŽฏ Project Overview

This MCP server provides Claude with the ability to:

  • Execute terminal commands in a controlled workspace
  • Manage files and directories
  • Run development tools and scripts
  • Install packages and dependencies
  • All while maintaining security through isolated execution

๐Ÿ—๏ธ Architecture

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”    MCP Protocol    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”    Shell Commands    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚                 โ”‚โ—„โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–บโ”‚                  โ”‚โ—„โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–บโ”‚             โ”‚
โ”‚   Claude AI     โ”‚                    โ”‚  Terminal Server โ”‚                      โ”‚   Terminal  โ”‚
โ”‚                 โ”‚                    โ”‚  (Python Script) โ”‚                      โ”‚             โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜                    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜                      โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                                              โ”‚
                                              โ–ผ
                                       โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
                                       โ”‚ ~/mcp/      โ”‚
                                       โ”‚ workspace/  โ”‚
                                       โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

๐Ÿš€ Features

  • Secure Command Execution: All commands run in an isolated workspace directory
  • Error Handling: Comprehensive error capture and reporting
  • MCP Protocol Compliance: Full compatibility with Claude Desktop
  • Easy Configuration: Simple setup with clear documentation

๐Ÿ“ฆ Installation

Prerequisites

  • Python 3.9+
  • Claude Desktop application
  • MCP library (pip install mcp>=1.0.0)

Setup

  1. Clone the repository:

    git clone https://github.com/yourusername/mcp-terminal-server.git
    cd mcp-terminal-server
    
  2. Install dependencies:

    cd servers/terminal_server
    pip install -e .
    
  3. Configure Claude Desktop:

    Open your Claude Desktop config file:

    • macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
    • Windows: %APPDATA%\Claude\claude_desktop_config.json
    • Linux: ~/.config/Claude/claude_desktop_config.json

    Add the following configuration:

    {
        "mcpServers": {
            "terminal": {
                "command": "/path/to/your/python",
                "args": [
                    "/path/to/mcp-terminal-server/servers/terminal_server/terminal_server.py"
                ]
            }
        }
    }
    
  4. Restart Claude Desktop to load the new configuration.

๐Ÿ› ๏ธ Usage

Once configured, you can ask Claude to perform terminal operations:

  • "Create a new Python project in the workspace"
  • "List all files in the workspace"
  • "Install the requests package"
  • "Run the test suite"
  • "Create a backup of the current project"

๐Ÿ”ง Development

Project Structure

mcp-terminal-server/
โ”œโ”€โ”€ servers/
โ”‚   โ””โ”€โ”€ terminal_server/
โ”‚       โ”œโ”€โ”€ terminal_server.py    # Main MCP server implementation
โ”‚       โ”œโ”€โ”€ pyproject.toml        # Python project configuration
โ”‚       โ””โ”€โ”€ README.md            # Server-specific documentation
โ”œโ”€โ”€ workspace/                   # Default working directory for commands
โ”œโ”€โ”€ .vscode/                    # VS Code configuration
โ””โ”€โ”€ README.md                   # This file

Key Components

terminal_server.py

The main MCP server that:

  • Defines the run_command tool for Claude
  • Handles command execution in the workspace
  • Provides error handling and output capture
pyproject.toml

Python project configuration with:

  • MCP dependency specification
  • Build system configuration
  • Project metadata

๐Ÿ”’ Security Features

  1. Isolated Workspace: All commands run in ~/mcp/workspace
  2. Controlled Access: Only specific tools are exposed to Claude
  3. Error Handling: Safe error capture and reporting
  4. No System Access: Commands cannot access your entire filesystem

๐Ÿงช Testing

Test your MCP server:

cd servers/terminal_server
python -c "import terminal_server; print('Server imports successfully')"

๐Ÿ“ Configuration Examples

Different Python Interpreters

Anaconda/Miniconda:

{
    "command": "/opt/anaconda3/bin/python",
    "args": ["/path/to/terminal_server.py"]
}

System Python:

{
    "command": "/usr/bin/python3",
    "args": ["/path/to/terminal_server.py"]
}

Virtual Environment:

{
    "command": "/path/to/venv/bin/python",
    "args": ["/path/to/terminal_server.py"]
}

๐Ÿค Contributing

This is my first MCP project! Feel free to:

  • Report issues
  • Suggest improvements
  • Share your own MCP server creations

๐Ÿ“š Learning Resources

๐ŸŽ‰ My MCP Journey

This project marks the beginning of my exploration into Model Context Protocol. MCP opens up incredible possibilities for AI-assisted development, allowing Claude to become a true development partner that can interact with your local environment safely and effectively.

Key Learnings:

  • Understanding the MCP protocol and its capabilities
  • Building secure bridges between AI and local systems
  • Creating tools that enhance AI assistant functionality
  • The power of controlled, isolated command execution

๐Ÿ“„ License

MIT License - feel free to use this project as a starting point for your own MCP servers!


Built with โค๏ธ and MCP | My first step into the future of AI-assisted development