文本mcp服务器
一 主控程序 允许AI代理启动、交互和检查的服务器 文本的 TUI应用程序无头。通过模型上下文协议,驱动任何Textual应用程序完成其整个生命周期——点击按钮、键入文本、读取小部件状态、截图。
特性
- 无头应用程序执行 --无需终端即可启动任何Textual应用程序,由Textual的内置功能提供支持
Pilot测试API - 完整的交互工具包 --使用CSS选择器单击、键入、按键并将鼠标悬停在小部件上
- 富国检查 --快照小部件树,按选择器查询小部件,并从16+个小部件类型中提取特定类型的属性
- 多会话支持 --以独立会话同时运行多个应用程序
- 错误追踪 --通过消息挂钩自动收集工作程序错误和应用程序异常
- 屏幕截图 --将当前屏幕导出为纯文本或SVG
安装
需要Python 3.10+。
pip install textual-mcp-server发展:
git clone https://github.com/discohead/textual-mcp-server.git
cd textual-mcp-server
pip install -e ".[dev]"快速开始
作为独立服务器
textual-mcp使用克劳德代码
claude mcp add textual -- textual-mcp或者手动添加到MCP配置中(例如。, ~/.claude.json 或项目 .mcp.json):
{
"mcpServers": {
"textual": {
"command": "textual-mcp"
}
}
}典型工作流程
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工具
生命周期
| 工具 | 说明 |
|---|---|
textual_launch | 无头启动Textual应用程序。接受文件路径(app.py),带类的路径(app.py:MyApp),或模块路径(mypackage.module:MyApp).返回a session_id. |
textual_stop | 停止正在运行的会话并返回任何收集到的错误。 |
交互
| 工具 | 说明 |
|---|---|
textual_press | 模拟按键(例如。, ["enter"], ["ctrl+s"]). |
textual_click | 通过CSS选择器单击具有可选偏移量和重复计数的小部件。 |
textual_type_text | 在焦点输入小部件中键入文本,并可选择提交(Enter)。 |
textual_hover | 将鼠标悬停在CSS选择器的小部件上。 |
观察
| 工具 | 说明 |
|---|---|
textual_snapshot | 使用引用标记、焦点状态、活动键绑定和错误对小部件树进行快照。 |
textual_screenshot | 将当前屏幕捕获为纯文本或SVG。 |
textual_query | 查询与CSS选择器匹配的小部件。返回类型、ID、类和提取的属性。 |
textual_get_screen_stack | 使用模态指示器获取当前屏幕堆栈。 |
断言和等待
| 工具 | 说明 |
|---|---|
textual_wait_for | 等待一个条件: idle, animation, workers (全部完成),或 widget (选择器出现)。 |
textual_check_errors | 检查收集到的工作程序错误和应用程序异常。 |
建筑
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)关键设计决策:
AppSession包裹文本App.run_test()以持久的方式提供启动/停止语义Pilot处理WidgetTreeSerializer生成LLM友好的文本输出——交互式小部件获取[ref=N]标记;滚动条和隐藏的小部件被排除在外WidgetStateExtractor使用有序的isinstance注册表从Input、Button、DataTable、TextArea、Tree和其他11种小部件类型中提取属性ErrorCollector连接到Textual的消息系统进行捕获Worker.StateChanged在不中断正常操作的情况下发生错误
支持的小部件类型
状态提取器为以下对象提供了丰富的属性数据:
输入、按钮、静态、标签、复选框、切换、选择、文本区域、DataTable、树、ListView、选项列表、标签内容、进度条、RadioSet、内容切换器
发展
# Run tests
pytest
# Run a specific test
pytest tests/test_integration_calculator.py -v需求
许可证
麻省理工学院
