MCP server for interactive terminal sessions with cross-platform PTY support
Project description
๐ฅ๏ธ MCP Terminal Server
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:
- API Documentation: http://localhost:8777/docs
- MCP Endpoint: http://localhost:8777/mcp
- Health Check: http://localhost:8777/health
๐ 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 terminallist_terminals_terminals__get- List active terminalsget_terminal_snapshot_terminals__terminal_id__snapshot_get- Get visual snapshotsend_terminal_input_terminals__terminal_id__input_post- Send commandsresize_terminal_terminals__terminal_id__resize_put- Resize terminalclose_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.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
๐ License
This project is licensed under the MIT License - see the LICENSE file for details.
๐ Acknowledgments
- Built with FastAPI
- Uses terminado for cross-platform PTY support
- Uses pyte for terminal emulation
- MCP integration via fastapi-mcp
๐ 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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file mcp_terminal_emulator-0.2.3.tar.gz.
File metadata
- Download URL: mcp_terminal_emulator-0.2.3.tar.gz
- Upload date:
- Size: 22.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8cc2b7ab6e191e093136eb51551be1e42b6f3168c8836a3c7d27443b8956626d
|
|
| MD5 |
f0f93f86aead546515316e7197865332
|
|
| BLAKE2b-256 |
7463ff5d8fcd1b3ffaaab9407cc6570dccfab08e4fdaba96fd5a678a1bd0a8d1
|
File details
Details for the file mcp_terminal_emulator-0.2.3-py3-none-any.whl.
File metadata
- Download URL: mcp_terminal_emulator-0.2.3-py3-none-any.whl
- Upload date:
- Size: 21.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d8285bc3b162f29e506739212e0a4e008baa3e936ddd9f33d7e2424439e29e88
|
|
| MD5 |
f6a538c2899a6b333eada3a0bdf14e57
|
|
| BLAKE2b-256 |
1ed73c877530bec56637ed17c47a2841f2d74fd6c6736b6e51466b3755747c32
|