Terminal MCP server

Provides secure terminal command execution through both isolated commands and persistent shell sessions that maintain state across interactions, supporting cross-platform automation workflows with configurable timeouts and session management.
Back to servers
Setup instructions
Provider
iris-networks
Release date
Jul 12, 2025
Language
Python
Stats
4 stars

The MCP Terminal Server is a high-performance server implementing the Model Context Protocol (MCP) for secure terminal execution across platforms. It enables applications to safely execute terminal commands through a standardized protocol interface.

Installation

Building from Source

To build the MCP Terminal Server from source:

# Build the server
make build

Running the Server

The server can be run in two modes:

# Run in HTTP mode with StreamableHTTP transport
./mcp-terminal-server --http --port 8080

# Run in STDIO mode (default)
./mcp-terminal-server

Usage

Testing the StreamableHTTP Transport

Once the server is running in HTTP mode, you can test it with curl commands:

# Start server in HTTP mode
./mcp-terminal-server --http --port 8080

# Test MCP initialization
curl -X POST http://localhost:8080/mcp \
  -H "Content-Type: application/json" \
  -d '{"jsonrpc": "2.0", "id": 1, "method": "initialize", "params": {"protocolVersion": "2024-11-05", "capabilities": {}, "clientInfo": {"name": "test-client", "version": "1.0.0"}}}'

# Test tools listing (use session ID from initialize response)
curl -X POST http://localhost:8080/mcp \
  -H "Content-Type: application/json" \
  -H "Mcp-Session-Id: <session-id>" \
  -d '{"jsonrpc": "2.0", "id": 2, "method": "tools/list"}'

# Execute a command
curl -X POST http://localhost:8080/mcp \
  -H "Content-Type: application/json" \
  -H "Mcp-Session-Id: <session-id>" \
  -d '{"jsonrpc": "2.0", "id": 3, "method": "tools/call", "params": {"name": "execute_command", "arguments": {"command": "echo Hello StreamableHTTP!"}}}'

Testing Persistent Shell

The server supports persistent shell sessions:

# Test persistent shell functionality
chmod +x examples/persistent_shell_examples.sh
./examples/persistent_shell_examples.sh

Available Tools

The MCP Terminal Server provides the following tools:

  1. execute_command - Execute single commands with timeout
  2. persistent_shell - Execute commands in persistent shell sessions
  3. session_manager - Manage shell sessions (list, close)

Configuration

Environment Variables

Configure the server using these environment variables:

  • MCP_COMMAND_TIMEOUT - Default command timeout in seconds (default: 30)
  • MCP_SHELL - Custom shell to use for command execution (default: /bin/bash on Unix)
  • DISPLAY - X11 display for GUI applications (automatically forwarded to commands)

GUI Application Support

The server automatically forwards the DISPLAY environment variable to executed commands, enabling GUI applications:

# Set DISPLAY when starting the server
DISPLAY=:0 ./mcp-terminal-server

# GUI applications launched through MCP will use the correct display
# e.g., xterm, firefox, gedit, etc.

Server Endpoints

When running in HTTP mode (--http flag), the server provides:

  • POST /mcp - StreamableHTTP transport endpoint for all MCP operations
    • Supports initialize, tools/list, tools/call methods
    • Requires Mcp-Session-Id header for authenticated requests
    • Returns session ID in response headers for initialize calls

Integration

Claude Desktop Integration

Add to your claude_desktop_config.json:

{
  "mcpServers": {
    "terminal": {
      "command": "/path/to/mcp-terminal-server",
      "env": {
        "MCP_COMMAND_TIMEOUT": "30",
        "DISPLAY": ":0"
      }
    }
  }
}

Docker Integration

# Run AMD64 image
docker run --rm -p 8080:8080 terminal-mcp:latest-linux-amd64 --http --port 8080

# Run ARM64 image  
docker run --rm -p 8080:8080 terminal-mcp:latest-linux-arm64 --http --port 8080

# Run with persistent shell session
docker run --rm -p 8080:8080 -v /tmp:/tmp terminal-mcp:latest-linux-amd64 --http --port 8080

How to install this MCP server

For Claude Code

To add this MCP server to Claude Code, run this command in your terminal:

claude mcp add-json "terminal" '{"command":"/path/to/mcp-terminal-server","env":{"MCP_COMMAND_TIMEOUT":"30","DISPLAY":":0"}}'

See the official Claude Code MCP documentation for more details.

For Cursor

There are two ways to add an MCP server to Cursor. The most common way is to add the server globally in the ~/.cursor/mcp.json file so that it is available in all of your projects.

If you only need the server in a single project, you can add it to the project instead by creating or adding it to the .cursor/mcp.json file.

Adding an MCP server to Cursor globally

To add a global MCP server go to Cursor Settings > Tools & Integrations and click "New MCP Server".

When you click that button the ~/.cursor/mcp.json file will be opened and you can add your server like this:

{
    "mcpServers": {
        "terminal": {
            "command": "/path/to/mcp-terminal-server",
            "env": {
                "MCP_COMMAND_TIMEOUT": "30",
                "DISPLAY": ":0"
            }
        }
    }
}

Adding an MCP server to a project

To add an MCP server to a project you can create a new .cursor/mcp.json file or add it to the existing one. This will look exactly the same as the global MCP server example above.

How to use the MCP server

Once the server is installed, you might need to head back to Settings > MCP and click the refresh button.

The Cursor agent will then be able to see the available tools the added MCP server has available and will call them when it needs to.

You can also explicitly ask the agent to use the tool by mentioning the tool name and describing what the function does.

For Claude Desktop

To add this MCP server to Claude Desktop:

1. Find your configuration file:

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

2. Add this to your configuration file:

{
    "mcpServers": {
        "terminal": {
            "command": "/path/to/mcp-terminal-server",
            "env": {
                "MCP_COMMAND_TIMEOUT": "30",
                "DISPLAY": ":0"
            }
        }
    }
}

3. Restart Claude Desktop for the changes to take effect

Want to 10x your AI skills?

Get a free account and learn to code + market your apps using AI (with or without vibes!).

Nah, maybe later