textual-mcp-server
An MCP server that lets AI agents launch, interact with, and inspect Textual TUI applications headlessly.
README
textual-mcp-server
An MCP server that lets AI agents launch, interact with, and inspect Textual TUI applications headlessly. Drive any Textual app through its full lifecycle — click buttons, type text, read widget state, take screenshots — all via the Model Context Protocol.
Features
- Headless app execution — Launch any Textual app without a terminal, powered by Textual's built-in
Pilottesting API - Full interaction toolkit — Click, type, press keys, and hover over widgets using CSS selectors
- Rich state inspection — Snapshot the widget tree, query widgets by selector, and extract type-specific properties from 16+ widget types
- Multi-session support — Run multiple apps concurrently with isolated sessions
- Error tracking — Automatic collection of worker errors and app exceptions via message hooks
- Screenshot capture — Export the current screen as plain text or SVG
Installation
Requires Python 3.10+.
pip install textual-mcp-server
For development:
git clone https://github.com/discohead/textual-mcp-server.git
cd textual-mcp-server
pip install -e ".[dev]"
Quick Start
As a standalone server
textual-mcp
With Claude Code
claude mcp add textual -- textual-mcp
Or add manually to your MCP configuration (e.g., ~/.claude.json or project .mcp.json):
{
"mcpServers": {
"textual": {
"command": "textual-mcp"
}
}
}
Typical workflow
1. textual_launch("my_app.py") → session_id
2. textual_snapshot(session_id) → widget tree + focus + bindings
3. textual_click(session_id, "#submit") → interact
4. textual_screenshot(session_id) → visual output
5. textual_stop(session_id) → cleanup
Tools
Lifecycle
| Tool | Description |
|---|---|
textual_launch |
Launch a Textual app headlessly. Accepts a file path (app.py), path with class (app.py:MyApp), or module path (mypackage.module:MyApp). Returns a session_id. |
textual_stop |
Stop a running session and return any collected errors. |
Interaction
| Tool | Description |
|---|---|
textual_press |
Simulate key presses (e.g., ["enter"], ["ctrl+s"]). |
textual_click |
Click a widget by CSS selector with optional offset and repeat count. |
textual_type_text |
Type text into the focused input widget, with optional submit (Enter). |
textual_hover |
Hover the mouse over a widget by CSS selector. |
Observation
| Tool | Description |
|---|---|
textual_snapshot |
Snapshot the widget tree with ref markers, focus state, active key bindings, and errors. |
textual_screenshot |
Capture the current screen as plain text or SVG. |
textual_query |
Query widgets matching a CSS selector. Returns type, ID, classes, and extracted properties. |
textual_get_screen_stack |
Get the current screen stack with modal indicators. |
Assertion & Waiting
| Tool | Description |
|---|---|
textual_wait_for |
Wait for a condition: idle, animation, workers (all complete), or widget (selector appears). |
textual_check_errors |
Check for collected worker errors and app exceptions. |
Architecture
textual_mcp/
├── server.py # FastMCP server, tool registration, and tool implementations
├── session.py # AppSession — headless app lifecycle via Pilot
├── session_manager.py # Multi-session management
├── app_loader.py # Dynamic app loading from file or module path
├── error_collector.py # Message hook for worker error aggregation
└── serializers/
├── widget_tree.py # DOM → indented text tree with [ref=N] markers
└── widget_state.py # Type-specific property extraction (16 widget types)
Key design decisions:
AppSessionwraps Textual'sApp.run_test()to provide launch/stop semantics with a persistentPilothandleWidgetTreeSerializerproduces LLM-friendly text output — interactive widgets get[ref=N]markers; scrollbars and hidden widgets are excludedWidgetStateExtractoruses an ordered isinstance registry to extract properties from Input, Button, DataTable, TextArea, Tree, and 11 other widget typesErrorCollectorhooks into Textual's message system to captureWorker.StateChangederrors without disrupting normal operation
Supported Widget Types
The state extractor provides rich property data for:
Input, Button, Static, Label, Checkbox, Switch, Select, TextArea, DataTable, Tree, ListView, OptionList, TabbedContent, ProgressBar, RadioSet, ContentSwitcher
Development
# Run tests
pytest
# Run a specific test
pytest tests/test_integration_calculator.py -v
Requirements
License
MIT
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。