Skip to main content

MCP server for interactive terminal sessions with cross-platform PTY support

Project description

๐Ÿ–ฅ๏ธ MCP Terminal Server

PyPI version Python Versions License: MIT

Interactive terminal sessions via Model Context Protocol (MCP)

MCP Terminal Server provides cross-platform PTY (pseudo-terminal) support for Windows, Linux, and macOS, exposing terminal sessions through both REST API and MCP protocol. Perfect for AI assistants, remote terminal access, and terminal automation.

โœจ Features

  • ๐ŸŒ Cross-platform: Works on Windows (cmd.exe/PowerShell), Linux, and macOS
  • ๐Ÿ”„ Real PTY: Supports interactive commands (vim, nano, htop, etc.)
  • ๐Ÿ‘๏ธ Visual Snapshots: Captures what a human would see on the terminal screen
  • ๐Ÿ”ค UTF-8 Support: Handles special characters and emojis correctly
  • ๐Ÿš€ MCP Protocol: Auto-exposes all endpoints as MCP tools via fastapi-mcp
  • ๐Ÿ“ก REST API: Full HTTP/REST API with FastAPI
  • ๐ŸŽฏ Multiple Sessions: Manage multiple terminal sessions simultaneously

๐Ÿ“ฆ Installation

From PyPI

pip install mcp-terminal

From Source

git clone https://github.com/alejoair/mcp-terminal
cd mcp-terminal
pip install -e .

๐Ÿš€ Quick Start

Start the Server

# Start on default port (8777)
mcp-terminal

# Start on custom port
mcp-terminal --port 9000

# Development mode with auto-reload
mcp-terminal --reload

# Custom host and port
mcp-terminal --host 0.0.0.0 --port 8888

Access the Server

Once running, you can access:

๐Ÿ“– Usage

REST API

Create a Terminal

curl -X POST http://localhost:8777/terminals \
  -H "Content-Type: application/json" \
  -d '{"rows": 24, "cols": 80}'

Response:

{
  "success": true,
  "terminal_id": "550e8400-e29b-41d4-a716-446655440000",
  "message": "Terminal created successfully"
}

Send Commands

curl -X POST http://localhost:8777/terminals/{terminal_id}/input \
  -H "Content-Type: application/json" \
  -d '{"data": "echo Hello World\n"}'

Get Visual Snapshot

curl http://localhost:8777/terminals/{terminal_id}/snapshot

Response:

{
  "terminal_id": "550e8400-e29b-41d4-a716-446655440000",
  "display": "C:\\Users\\...\nHello World\nC:\\Users\\...> ",
  "lines": ["C:\\Users\\...", "Hello World", "C:\\Users\\...> "],
  "cursor": {"row": 2, "col": 15},
  "size": {"rows": 24, "cols": 80},
  "is_alive": true,
  "created_at": "2024-01-01T00:00:00"
}

List Terminals

curl http://localhost:8777/terminals

Resize Terminal

curl -X PUT http://localhost:8777/terminals/{terminal_id}/resize \
  -H "Content-Type: application/json" \
  -d '{"rows": 30, "cols": 100}'

Close Terminal

curl -X DELETE http://localhost:8777/terminals/{terminal_id}

MCP Tools

When using with MCP clients (like Claude Desktop), the following tools are automatically available:

  • create_terminal_terminals__post - Create new terminal
  • list_terminals_terminals__get - List active terminals
  • get_terminal_snapshot_terminals__terminal_id__snapshot_get - Get visual snapshot
  • send_terminal_input_terminals__terminal_id__input_post - Send commands
  • resize_terminal_terminals__terminal_id__resize_put - Resize terminal
  • close_terminal_terminals__terminal_id__delete - Close terminal

Python API

from mcp_terminal import TerminalManager

# Create manager
manager = TerminalManager()

# Create terminal
terminal_id = await manager.create(rows=24, cols=80)

# Send input
await manager.send_input(terminal_id, "echo Hello\n")

# Get snapshot
snapshot = await manager.get_snapshot(terminal_id)
print(snapshot["display"])

# Close terminal
await manager.close(terminal_id)

๐Ÿ—๏ธ Architecture

src/mcp_terminal/
โ”œโ”€โ”€ __init__.py          # Package initialization
โ”œโ”€โ”€ __main__.py          # CLI entry point
โ”œโ”€โ”€ server.py            # FastAPI application with MCP integration
โ”œโ”€โ”€ core/
โ”‚   โ””โ”€โ”€ terminal/
โ”‚       โ”œโ”€โ”€ session.py   # TerminalSession - PTY management
โ”‚       โ”œโ”€โ”€ buffer.py    # TerminalBuffer - Visual screen capture
โ”‚       โ””โ”€โ”€ manager.py   # TerminalManager - Multi-session coordinator
โ””โ”€โ”€ models/
    โ””โ”€โ”€ terminal.py      # Pydantic models for API

๐Ÿ”ง Configuration

Command Line Options

--host HOST          Host to bind to (default: 127.0.0.1)
--port PORT          Port to bind to (default: 8777)
--reload             Enable auto-reload for development
--log-level LEVEL    Set log level (debug, info, warning, error, critical)
--version            Show version and exit

Environment Variables

You can also configure via environment variables:

export MCP_TERMINAL_HOST=0.0.0.0
export MCP_TERMINAL_PORT=9000
export MCP_TERMINAL_LOG_LEVEL=debug

๐Ÿงช Testing

# Install dev dependencies
pip install -e ".[dev]"

# Run tests
pytest

# Run with coverage
pytest --cov=mcp_terminal

๐Ÿค Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

๐Ÿ“„ License

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

๐Ÿ™ Acknowledgments

๐Ÿ“š Resources

๐Ÿ› Bug Reports

If you find a bug, please open an issue on GitHub.

๐Ÿ’ฌ Support

For questions and support, please use GitHub Discussions.


Made with โค๏ธ by the MCP Terminal team

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

mcp_terminal_emulator-0.2.1.tar.gz (20.2 kB view details)

Uploaded Source

Built Distribution

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

mcp_terminal_emulator-0.2.1-py3-none-any.whl (21.3 kB view details)

Uploaded Python 3

File details

Details for the file mcp_terminal_emulator-0.2.1.tar.gz.

File metadata

  • Download URL: mcp_terminal_emulator-0.2.1.tar.gz
  • Upload date:
  • Size: 20.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.9

File hashes

Hashes for mcp_terminal_emulator-0.2.1.tar.gz
Algorithm Hash digest
SHA256 6270bdffaae645e7c58fe782cd91d76d91f863e884bb34e1da87386e0207d0af
MD5 334a72750823030546311fb5c637aa8c
BLAKE2b-256 b3751f149a520f176fc99fbdf2f94b91414590c590a7435fe3f19ae6a4144e4e

See more details on using hashes here.

File details

Details for the file mcp_terminal_emulator-0.2.1-py3-none-any.whl.

File metadata

File hashes

Hashes for mcp_terminal_emulator-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 571c7abcb196e53e23b303cad172739bef5fb3ece5282813efe59901c43b7231
MD5 ea07682557eda05324befbb918074410
BLAKE2b-256 33c34023a44723db7fd5325b2b2a02f40aa9265b6eff768e360bfaf310dfa6c7

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