MCP Terminal Server

MCP Terminal Server

Provides cross-platform terminal access through MCP, enabling AI assistants to create and manage interactive terminal sessions, execute commands, and capture visual snapshots on Windows, Linux, and macOS.

Category
访问服务器

README

🖥️ 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:

  • 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 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

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选