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.0.1.tar.gz (18.1 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.0.1-py3-none-any.whl (15.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: terminal_mcp_server-1.0.1.tar.gz
  • Upload date:
  • Size: 18.1 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.0.1.tar.gz
Algorithm Hash digest
SHA256 d3851586f56edadf4b47b27e674c64f79330b2e68dc0cfcff75c0dd921bbe625
MD5 cc0d1b9cd514e32413aa8cc4571f2b38
BLAKE2b-256 7152ee96267f5979a953b4714ee4bcabd616373ef2ac7c752ab4ffbcc67adc34

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for terminal_mcp_server-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 22c9d119b79a6078971bcc2dbc643ad01a042adb5a085d1f166bb3aab0b07645
MD5 7892c4ed6a9ead4eacf8e89c10b885e0
BLAKE2b-256 8365e90957c6821f4f7120edaa7c00fa934eb99e1339c4f38086ad82ae4c6904

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