Terminal MCP server

Enables AI systems to execute terminal commands in local or remote environments through a TypeScript-based server supporting both standard I/O and SSE communication modes.
Back to servers
Setup instructions
Provider
WeiDwonder
Release date
Mar 21, 2025
Language
TypeScript
Stats
24 stars

Terminal MCP Server is a powerful tool that implements the Model Context Protocol (MCP), allowing AI models and applications to execute commands on local or remote machines. It provides a straightforward interface for command execution with support for session persistence and environment variable customization.

Installation Options

Install via Smithery

The easiest way to install Terminal MCP Server for Claude Desktop is through Smithery:

npx -y @smithery/cli install @weidwonder/terminal-mcp-server --client claude

Manual Installation

If you prefer to install manually:

# Clone the repository
git clone https://github.com/weidwonder/terminal-mcp-server.git
cd terminal-mcp-server

# Install dependencies
npm install

# Build the project
npm run build

Starting the Server

Standard Mode (stdio)

The default mode uses stdio for communication:

# Start the server using npm
npm start

# Or run the built file directly
node build/index.js

SSE Mode

Server-Sent Events (SSE) mode allows remote connections via HTTP:

# Start the server in SSE mode
npm run start:sse

# Or run with SSE flag
node build/index.js --sse

SSE Mode Configuration Options

Option Description Default
--port or -p The port to listen on 8080
--endpoint or -e The endpoint path /sse
--host or -h The host to bind to localhost

Example with custom options:

# Custom SSE configuration
node build/index.js --sse --port 3000 --endpoint /mcp --host 0.0.0.0

Using the execute_command Tool

The main functionality of Terminal MCP Server is provided through the execute_command tool.

Parameters

Parameter Type Required Description
command string Yes The command to execute
host string No Remote host (if omitted, executes locally)
username string Required with host SSH username
session string No Session name (defaults to "default")
env object No Environment variables

Example: Local Command Execution

{
  "command": "ls -la",
  "session": "my-local-session",
  "env": {
    "NODE_ENV": "development"
  }
}

Example: Remote Command Execution

{
  "host": "example.com",
  "username": "user",
  "command": "ls -la",
  "session": "my-remote-session",
  "env": {
    "NODE_ENV": "production"
  }
}

Integrating with AI Assistants

Claude Desktop Configuration

Add the following to your Claude Desktop settings file at ~/Library/Application Support/Claude/claude_desktop_config.json:

For stdio mode (local connection)

{
  "mcpServers": {
    "terminal-mcp": {
      "command": "node",
      "args": ["/path/to/terminal-mcp-server/build/index.js"],
      "env": {}
    }
  }
}

For SSE mode (remote connection)

{
  "mcpServers": {
    "terminal-mcp-sse": {
      "url": "http://localhost:8080/sse",
      "headers": {}
    }
  }
}

Roo Code Configuration

Add to the Roo Code settings file at ~/Library/Application Support/Code/User/globalStorage/rooveterinaryinc.roo-cline/settings/cline_mcp_settings.json:

Similar configuration format as Claude Desktop, with stdio or SSE options.

Cline Configuration

Add to the Cline settings file at ~/.cline/config.json:

Similar configuration format as Claude Desktop, with stdio or SSE options.

Best Practices

Command Execution Tips

  • Determine the system type before running platform-specific commands
  • Use full paths to avoid path-related issues
  • For command sequences that need to maintain environment, use && between commands
  • For long-running commands, consider using nohup or screen/tmux

Session Management

  • Use the same session name for related commands to maintain environment
  • Sessions automatically close after 20 minutes of inactivity
  • Sessions provide persistent terminal environments for connected commands

Error Handling

  • Always check stderr in command results to determine execution success
  • Add verification steps for complex operations
  • Command results include both stdout and stderr

Important Notes

  • Remote command execution requires SSH key-based authentication
  • Local commands run in the context of the user who started the server
  • Session timeout is 20 minutes by default

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-mcp" '{"command":"node","args":["/path/to/terminal-mcp-server/build/index.js"],"env":[]}'

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-mcp": {
            "command": "node",
            "args": [
                "/path/to/terminal-mcp-server/build/index.js"
            ],
            "env": []
        }
    }
}

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-mcp": {
            "command": "node",
            "args": [
                "/path/to/terminal-mcp-server/build/index.js"
            ],
            "env": []
        }
    }
}

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