Skip to main content
Glama

๐Ÿงฉ Terminal MCP

License: MIT Version Node.js Contributions Welcome

A production-grade Model Context Protocol (MCP) server with PTY-native execution designed specifically for Cursor IDE. Provides a unified interactive terminal for Cursor's AI assistant and humans, enabling seamless command execution in shared terminal environments.

โœจ Features

  • PTY-native execution - Commands run directly in PTY terminals (single source of truth)

  • Multi-project support - On-demand PTY per project root with shared state

  • Real environment - AWS SSO, exports, credentials all work correctly

  • Shared visibility - You and AI assistants see the exact same terminal

  • HTTP transport - Deploy anywhere, access from any machine

  • WebSocket support - Real-time terminal attachment and monitoring

  • Context-aware execution - Enhanced tools that provide terminal context before execution

  • Daemon mode - Run as a background service with CLI management

  • Graceful shutdown - Proper cleanup of PTY processes and connections

Related MCP server: AdminMCP

๐Ÿ“‹ Prerequisites

  • Node.js (v16 or higher)

  • A Unix-like system (macOS, Linux) with PTY support

๐Ÿš€ Quick Start

Installation

npm install -g terminal-mcp

Or clone and install locally:

git clone https://github.com/yourusername/terminal-mcp.git
cd terminal-mcp
npm install

Basic Usage

  1. Start the daemon:

npm run daemon
# Or run in background:
npm run daemon:bg
  1. Configure Cursor MCP settings (Cursor โ†’ Settings โ†’ Features โ†’ Model Context Protocol):

{
  "mcpServers": {
    "pty-terminal": {
      "url": "http://localhost:3333/mcp"
    }
  }
}
  1. Restart Cursor

CLI Commands

# Start daemon
npm run daemon

# Start daemon in background
npm run daemon:bg

# Check status
npm run status

# List active terminals
npm run list

# Stop daemon
npm run stop

๐Ÿ—๏ธ Architecture

Cursor/AI Assistant
  โ”‚
  โ–ผ
MCP HTTP Server (Express)
  โ”‚
  โ”œโ”€ HTTP Transport (JSON + SSE)
  โ”œโ”€ WebSocket Transport (real-time)
  โ”‚
  โ–ผ
PTY Manager
  โ”‚
  โ”œโ”€ On-demand PTY creation per project root
  โ”œโ”€ Shared PTY state (env vars, cwd, auth tokens)
  โ”œโ”€ Terminal Event Journal (output history)
  โ”‚
  โ–ผ
PTY Processes (node-pty)
  โ”‚
  โ–ผ
Real Shell Environment

Key Components:

  • PTY Manager: Manages multiple PTY instances, one per project root

  • Terminal Event Journal: Captures and stores terminal output history

  • MCP Tools: execute, execute2, interrupt, list_terminals, read_terminal

  • HTTP Server: Express-based server with MCP transport and WebSocket support

๐Ÿ“ How It Works

  1. MCP server starts and creates a default PTY for the default project root

  2. AI assistants send commands via the MCP execute or execute2 tool

  3. Commands are executed in the appropriate PTY (based on project root)

  4. Output is captured via PTY event listeners and stored in the event journal

  5. Results are returned to the AI assistant via MCP

  6. Humans can attach to terminals via WebSocket or CLI to monitor activity

๐ŸŽฏ Usage Examples

For AI Assistants (Automatic)

AI assistants automatically use this terminal for all commands. Just ask:

  • "Run tests"

  • "Install dependencies"

  • "Start the server"

  • "Check the logs"

  • "Build the project"

For Humans (Manual Terminal Access)

Attach to a terminal via WebSocket:

# Using the CLI
mcp-terminal attach

# Or connect directly via WebSocket
wscat -c ws://localhost:3333/attach?projectRoot=/path/to/project

๐Ÿ”ง Configuration

Environment Variables

  • PORT: Server port (default: 3333)

  • PROJECT_ROOT: Default project root path (default: home directory)

  • SHELL: Shell to use for PTY (default: /bin/zsh)

Project-Specific Terminals

The server automatically creates separate PTY instances for different project roots. Specify the project root when calling MCP tools:

{
  "command": "npm test",
  "projectRoot": "/path/to/my/project"
}

๐Ÿš€ Deployment

Docker

docker build -t terminal-mcp .
docker run -p 3333:3333 \
  -e PROJECT_ROOT=/app \
  -e PORT=3333 \
  terminal-mcp

Cloud Platforms

Works on:

  • AWS EC2 / GCP VM / DigitalOcean

  • Cloud Run / Fly.io / Render

  • Docker Compose / Kubernetes

All support HTTP + SSE transport.

๐Ÿ”’ Security

Important Security Considerations:

  • โš ๏ธ No authentication by default - Add authentication for production use

  • โš ๏ธ No rate limiting - Implement rate limiting for public deployments

  • โš ๏ธ Full command execution access - Commands run with the same privileges as the daemon user

For production, add:

  • API key header authentication

  • IP allowlist

  • Command denylist/filtering

  • Read-only mode toggle

  • TLS/HTTPS encryption

See SECURITY.md for more information.

๐Ÿงช Development

Setup

git clone https://github.com/yourusername/terminal-mcp.git
cd terminal-mcp
npm install

Running Tests

npm test

Code Quality

# Linting (if configured)
npm run lint

# Formatting (if configured)
npm run format

See CONTRIBUTING.md for detailed development guidelines.

๐Ÿ“š API Reference

MCP Tools

execute

Execute a command in the shared PTY terminal.

Parameters:

  • command (required): Shell command to execute

  • projectRoot (optional): Project root path

execute2

Context-aware execution that shows terminal history before executing.

Parameters:

  • command (required): Shell command to execute

  • projectRoot (optional): Project root path

  • contextChars (optional): Maximum characters of context to show (default: 2000)

interrupt

Send Ctrl+C to interrupt the currently running command.

Parameters:

  • projectRoot (optional): Project root path

list_terminals

List all active PTY terminals managed by the server.

read_terminal

Read terminal output history without executing any command.

Parameters:

  • projectRoot (optional): Project root path

  • maxChars (optional): Maximum characters to return (default: 8000)

  • mode (optional): Read mode - tail, since_last, or full (default: tail)

HTTP Endpoints

  • GET /health - Health check endpoint

  • POST /mcp - MCP protocol endpoint

  • GET /terminals - List active terminals

  • WS /attach - WebSocket endpoint for terminal attachment

๐Ÿ› ๏ธ Troubleshooting

Terminal not found

The server automatically creates PTY instances on demand. If you encounter issues:

  1. Check that the daemon is running: npm run status

  2. Verify the project root path exists

  3. Check server logs for errors

Commands not executing

Make sure:

  1. The MCP server is configured correctly in Cursor settings

  2. The PROJECT_ROOT path is absolute and correct

  3. You've restarted Cursor after configuration

  4. The daemon is running and accessible

Check active terminals

npm run list
# Or via HTTP:
curl http://localhost:3333/terminals

๐Ÿค Contributing

We welcome contributions! Please see CONTRIBUTING.md for guidelines.

๐Ÿ“„ License

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

๐Ÿ™ Acknowledgments

๐Ÿ“ž Support


Made with โค๏ธ for the open source community

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelogโ€ฆ

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      Not graded
      quality
      D
      maintenance
      Enables AI agents to interact with terminal environments through multiple concurrent PTY sessions. Supports cross-platform terminal operations including command execution, session management, and real-time communication.
      2
      MIT
    • F
      license
      Not graded
      quality
      Not graded
      maintenance
      Provides LLMs with administrative capabilities to execute shell commands on local systems through a pseudo-terminal environment with Unix Domain Socket communication.
      -
    • F
      license
      A
      quality
      D
      maintenance
      Enables AI agents to start and manage pseudo-terminal sessions, run shell commands and interact with REPLs programmatically.
      7
      -
    • A
      license
      Not graded
      quality
      D
      maintenance
      Enables AI agents to execute commands in a shared tmux session that is simultaneously visible to a human via a web-based terminal UI.
      1
      MIT