Skip to main content

Smart terminal session management for AI assistants

Project description

Terminal MCP Server

License: MIT Python 3.8+

Smart terminal session management for AI assistants. Solve terminal blocking issues with async execution, auto cleanup, and real-time web monitoring.

Support up to 64 concurrent terminals with intelligent idle detection, system monitoring, and auto browser opening.


โœจ Key Features

  • ๐Ÿš€ Async Execution - Commands never block AI operations
  • ๐Ÿ”ข Multi-Terminal - Up to 64 concurrent sessions
  • ๐Ÿงน Auto Cleanup - Intelligent idle session detection
  • โšก Broadcast - Execute commands across multiple terminals
  • ๐Ÿ“Š System Monitor - Real-time CPU/Memory/GPU tracking
  • ๐ŸŒ Web Interface - Auto-open browser with full terminal view
  • ๐Ÿ–ฅ๏ธ Smart Shell - Auto-detect best shell (Git Bash > PowerShell > cmd)
  • ๐Ÿ›‘ Resource Control - One-click shutdown button

๐Ÿš€ Quick Start

Step 1: Add MCP Configuration

Add to your Cursor MCP config:

{
  "mcpServers": {
    "terminal": {
      "command": "uvx",
      "args": ["terminal-mcp-server"]
    }
  }
}

Or for Node.js:

{
  "mcpServers": {
    "terminal": {
      "command": "npx",
      "args": ["@kanniganfan/terminal-mcp"]
    }
  }
}

Step 2: โš ๏ธ IMPORTANT - Add IDE Rule

To make AI always use this MCP for terminal operations, add this rule to your IDE's Project Rules or User Rules:

All terminal operations (read/write) must be proxied through the Terminal MCP.
Use MCP tools for all terminal commands instead of direct terminal access.

In Cursor:

  • Settings โ†’ Rules โ†’ Add this rule
  • Or in .cursorrules file in your project root

Why this is important:

  • โœ… Prevents AI from getting stuck in terminal
  • โœ… All commands run asynchronously
  • โœ… Can monitor all terminals in web interface
  • โœ… Better resource management

Step 3: Restart Cursor

Step 4: Start Using

In Cursor:

Create a terminal session named "dev"
Execute "npm run dev" in dev session

Browser auto-opens โ†’ View real-time output โ†’ Monitor system resources!


๐Ÿ“Š Web Interface

Auto-opens at http://localhost:18888

Dashboard Features

Top Panel:

  • ๐Ÿ“Š CPU Usage (real-time)
  • ๐Ÿ’พ Memory Usage (% + GB)
  • ๐Ÿ–ฅ๏ธ GPU Info (Windows)
  • ๐Ÿ“ˆ Session Stats
  • ๐Ÿ›‘ Shutdown Server Button

Layout:

  • Left: Terminal session list
  • Right: Full-screen xterm.js terminal (click to expand)
  • Bottom: Command input

Actions

  • Click session โ†’ Full terminal expands
  • Type commands โ†’ Real-time execution
  • Click ๐Ÿ›‘ โ†’ Shutdown all sessions + release port

๐Ÿ› ๏ธ Available MCP Tools

Tool Description
create_session Create new terminal session
execute_command Execute command (async, non-blocking)
broadcast_command Execute across multiple terminals
get_all_sessions List all sessions
get_session_status Get session status
get_output Get terminal output
kill_session Terminate session
cleanup_idle_sessions Clean idle sessions
get_stats Get statistics

โš™๏ธ Configuration

Edit config.json:

{
  "max_sessions": 64,
  "idle_timeout": 300,
  "auto_cleanup_interval": 60,
  "max_output_lines": 10000,
  "web_port": 18888,
  "auto_open_browser": true
}

๐Ÿ–ฅ๏ธ Smart Shell Detection

Windows Priority:

  1. Git Bash (C:\Program Files\Git\bin\bash.exe)
  2. PowerShell 7 / Windows PowerShell
  3. cmd.exe (fallback)

Linux/Mac: Uses $SHELL environment variable


๐Ÿ“ Project Structure

terminal-mcp/
โ”œโ”€โ”€ src/terminal_mcp_server/
โ”‚   โ”œโ”€โ”€ server.py          # Core MCP server (all-in-one)
โ”‚   โ””โ”€โ”€ config.json        # Default configuration
โ”œโ”€โ”€ config.json            # User configuration
โ”œโ”€โ”€ mcp_config_example.json # Cursor config template
โ”œโ”€โ”€ requirements.txt       # Dependencies
โ””โ”€โ”€ README.md             # This file

๐ŸŽฏ Use Cases

Development Workflow

1. Create "frontend" โ†’ npm run dev
2. Create "backend" โ†’ python manage.py runserver
3. Create "database" โ†’ docker-compose up
4. Monitor all in web interface
5. Click any terminal to view full output

Batch Operations

1. Create 5 sessions
2. Broadcast "git status" to all
3. View results in web interface

Long-running Tasks

1. Create session
2. Execute "npm run build"
3. AI continues other work
4. Check output anytime in browser

๐Ÿ›‘ Resource Management

When switching IDEs or done working:

  1. Open web interface
  2. Click ๐Ÿ›‘ Shutdown Server button
  3. All sessions terminated
  4. Port 18888 released
  5. Process fully exits

No more port conflicts or resource leaks!


๐Ÿ“ฆ Installation

Python Users (PyPI)

{
  "mcpServers": {
    "terminal": {
      "command": "uvx",
      "args": ["terminal-mcp-server"]
    }
  }
}

Node.js Users (npm)

{
  "mcpServers": {
    "terminal": {
      "command": "npx",
      "args": ["@kanniganfan/terminal-mcp"]
    }
  }
}

No download, no install, just works!


๐Ÿ”ง Troubleshooting

Web Interface Not Opening

Solution: Manually visit http://localhost:18888

Port Already in Use

Solution:

  1. Change web_port in config.json
  2. Or click shutdown button in existing web interface

Shell Not Detected

Solution: Check that Git Bash/PowerShell is installed


๐Ÿ“„ License

MIT License - see LICENSE file


๐Ÿค Contributing

Contributions welcome! See CONTRIBUTING.md


๐ŸŒŸ Star History

If this helps you, please give it a star! โญ


Made with โค๏ธ for AI Assistants | Report Issues

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

terminal_mcp_server-1.1.0.tar.gz (19.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

terminal_mcp_server-1.1.0-py3-none-any.whl (16.3 kB view details)

Uploaded Python 3

File details

Details for the file terminal_mcp_server-1.1.0.tar.gz.

File metadata

  • Download URL: terminal_mcp_server-1.1.0.tar.gz
  • Upload date:
  • Size: 19.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.0

File hashes

Hashes for terminal_mcp_server-1.1.0.tar.gz
Algorithm Hash digest
SHA256 21c54428903e8041297d033afd48c5df1ff28a71b542f89334df43b6bf9eb2c9
MD5 2e14d79f2ef354997d18641fb41365d3
BLAKE2b-256 884a1c339e51fed09b99cfc433b52966dd2521d7a646c23240fcba00b7911cc5

See more details on using hashes here.

File details

Details for the file terminal_mcp_server-1.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for terminal_mcp_server-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 dd8efa4476d3c37e50f5c8069bda0df8d6983f6538159d11c09d54452a93ccaf
MD5 af3f87475155526bf61a56b0ce9ac212
BLAKE2b-256 f3fe62476d318c4dc179d81d935d8c57316261c43dab154a882a663d52129815

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page