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
Provider
WeiDwonder
Release date
Mar 21, 2025
Language
TypeScript
Stats
6 stars

Terminal MCP Server provides an interface for executing commands on local or remote hosts via the Model Context Protocol (MCP). It enables AI models and applications to run system commands locally or remotely through SSH connections, with features like session persistence and environment variable customization.

Installation Options

Via Smithery

The simplest way to install the terminal-mcp-server for Claude Desktop is using Smithery:

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

Manual Installation

To install the server 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 connection method uses standard input/output:

# Start with npm
npm start

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

SSE Mode

For remote connections via HTTP Server-Sent Events:

# Start with npm
npm run start:sse

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

Customize the SSE server with these 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 configuration:

node build/index.js --sse --port 3000 --endpoint /mcp --host 0.0.0.0

This makes the server available at http://0.0.0.0:3000/mcp.

Testing Your Setup

To verify your server is working correctly:

npm run inspector

Using the execute_command Tool

The core 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 address (omit for local execution)
username string When using host SSH username
session string No Session identifier (default: "default")
env object No Environment variables (default: empty object)

Usage Examples

Local Command Execution

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

Remote Command Execution

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

Configuring AI Assistants

Roo Code Configuration

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

  2. Add one of these configurations:

For stdio mode:

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

For SSE mode:

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

Cline Configuration

  1. Open the Cline settings file: ~/.cline/config.json
  2. Add the same configuration as above (either stdio or SSE mode)

Claude Desktop Configuration

  1. Open: ~/Library/Application Support/Claude/claude_desktop_config.json
  2. Add the same configuration as above (either stdio or SSE mode)

Best Practices

Effective Command Execution

  • Determine the system type before running commands
  • Use full paths to avoid path-related issues
  • Connect multiple commands with && to maintain environment
  • For long-running commands, consider using nohup or screen/tmux

SSH Connection Tips

  • Ensure SSH key-based authentication is configured
  • Check for the existence of key files (default: ~/.ssh/id_rsa)
  • Verify the SSH service is running on remote hosts

Session Management

  • Use consistent session names for related commands
  • Sessions automatically time out after 20 minutes of inactivity
  • Use sessions to maintain environment variables between commands

Error Handling

  • Command results include both stdout and stderr
  • Check stderr to verify successful execution
  • Add verification steps for complex operations

How to add this MCP server to 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 > MCP and click "Add new global MCP server".

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

{
    "mcpServers": {
        "cursor-rules-mcp": {
            "command": "npx",
            "args": [
                "-y",
                "cursor-rules-mcp"
            ]
        }
    }
}

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 explictly ask the agent to use the tool by mentioning the tool name and describing what the function does.

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