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": ["-y", "@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": ["-y", "@kanniganfan/terminal-mcp"]
    }
  }
}

Or install globally first:

npm install -g @kanniganfan/terminal-mcp

Then use:

{
  "mcpServers": {
    "terminal": {
      "command": "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.3.tar.gz (19.6 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.3-py3-none-any.whl (16.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: terminal_mcp_server-1.1.3.tar.gz
  • Upload date:
  • Size: 19.6 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.3.tar.gz
Algorithm Hash digest
SHA256 d375eacb0cfc4093e589df75a44cf8454f36d8e6d3158bc2ca13c7949dd8fc21
MD5 59d975542079b47dcee739a601c6b0e5
BLAKE2b-256 791229bd145352e8bef89b29312321d521993f3f669f86da2aaa10e25a891e64

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for terminal_mcp_server-1.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 24fa6bcc477805bcb74d530836ebdc0fe25a47db460f6a5613d06a2b8260f187
MD5 b29a3329af25494c2a17c77f8e62c6ca
BLAKE2b-256 e0c1da9bf84b7bf365acb9023a84a89c9e59e2202f58da2a51a224fc7c824787

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