pharo smalltalk互操作mcp服务器

本地MCP服务器,用于传输本地Pharo Smalltalk图像。 它支持:
- 代码求值:执行Smalltalk表达式并返回结果
- 代码自检:检索类和方法的源代码、注释和元数据
- 搜索和发现:查找类、特征、方法、引用和实现者
- 包管理:导出和导入Tonel格式的包
- 项目安装:使用Metacello安装项目
- 测试执行:在包或类级别运行测试套件
- UI调试:捕获屏幕截图并检查World变形、Spec演示者和Roassal可视化的UI结构
- 服务器配置:动态检索和修改服务器设置
先决条件
- Python 3.10或更高版本
- 紫外线 包管理器
- Pharo与 PharoSmalltalkInteropServer 安装
安装
快速入门(使用uvx)
在不克隆存储库的情况下运行服务器的最简单方法:
uvx --from git+https://github.com/mumez/pharo-smalltalk-interop-mcp-server.git pharo-smalltalk-interop-mcp-server开发安装
为发展而设立:
- 克隆存储库:
git clone https://github.com/mumez/pharo-smalltalk-interop-mcp-server.git- 使用uv安装依赖项:
cd pharo-smalltalk-interop-mcp-server
uv sync --dev用法
运行MCP服务器
使用uvx(无需安装):
uvx --from git+https://github.com/mumez/pharo-smalltalk-interop-mcp-server.git pharo-smalltalk-interop-mcp-server使用uv(克隆存储库后):
uv run pharo-smalltalk-interop-mcp-server环境变量
您可以使用环境变量配置服务器:
PHARO_SIS_PORT:PharoSmalltalkInteropServer的端口号(默认值:8086)
示例:
使用uvx:
PHARO_SIS_PORT=8086 uvx --from git+https://github.com/mumez/pharo-smalltalk-interop-mcp-server.git pharo-smalltalk-interop-mcp-server使用紫外线:
PHARO_SIS_PORT=9999 uv run pharo-smalltalk-interop-mcp-server光标MCP设置
使用uvx(推荐):
{
"mcpServers": {
"smalltalk-interop": {
"command": "uvx",
"args": [
"--from",
"git+https://github.com/mumez/pharo-smalltalk-interop-mcp-server.git",
"pharo-smalltalk-interop-mcp-server"
],
"env": {
"PHARO_SIS_PORT": "8086"
}
}
}
}使用紫外线(克隆后):
{
"mcpServers": {
"smalltalk-interop": {
"command": "uv",
"args": [
"--directory",
"/your-path/to/pharo-smalltalk-interop-mcp-server",
"run",
"pharo-smalltalk-interop-mcp-server"
],
"env": {
"PHARO_SIS_PORT": "8086"
}
}
}
}注: env 部分是可选的,可用于为MCP服务器设置环境变量。
Claude代码配置
使用uvx(推荐):
claude mcp add -s user smalltalk-interop -- uvx --from git+https://github.com/mumez/pharo-smalltalk-interop-mcp-server.git pharo-smalltalk-interop-mcp-server使用紫外线(克隆后):
claude mcp add -s user smalltalk-interop -- uv --directory /path/to/pharo-smalltalk-interop-mcp-server run pharo-smalltalk-interop-mcp-serverMCP工具可用
该服务器提供22个MCP工具,映射到所有 PharoSmalltalkInteropServer API:
代码评估
eval:执行Smalltalk表达式并返回结果
代码反思
get_class_source:检索类的源代码get_method_source:检索特定方法的源代码get_class_comment:检索类的注释/文档
搜索与发现
search_classes_like:查找与模式匹配的类search_methods_like:查找与模式匹配的方法search_traits_like:查找与模式匹配的特征search_implementors:查找方法选择器的所有实现者search_references:查找对方法选择器的所有引用search_references_to_class:查找对某个类的所有引用
包管理
list_packages:列出图像中的所有包list_classes:列出特定包中的类list_extended_classes:列出包中的扩展类list_methods:列出包中的方法export_package:以Tonel格式导出包import_package:从指定路径导入包
工程安装
install_project:使用Metacello安装带有可选加载组的项目
测试执行
run_package_test:运行包的测试套件run_class_test:为特定类运行测试套件
UI调试
read_screen:用于调试Pharo界面的UI屏幕阅读器,具有屏幕截图和结构提取功能
服务器配置
get_settings:检索当前服务器配置apply_settings:动态修改服务器配置
read_screen工具
这 read_screen 该工具捕获屏幕截图并提取UI结构,用于调试Pharo UI问题。
参数:
target_type(字符串,默认值:“world”):要检查的UI类型(变形为“world”,窗口为“spec”,可视化为“roassal”)capture_screenshot(布尔值,默认值:true):在响应中包含PNG屏幕截图
退货: 带有屏幕截图和人类可读摘要的UI结构
使用示例:
# Inspect all morphs in World
read_screen(target_type='world')
# Inspect Spec presenter windows
read_screen(target_type='spec', capture_screenshot=false)
# Inspect Roassal visualizations without screenshot (faster)
read_screen(target_type='roassal', capture_screenshot=false)提取的数据包括:
*世界(变形):*
- 类名和类型标识
- 边界(x、y、宽度、高度坐标)
- 可见性状态
- 背景颜色
- 所有者类别
- 子公司数量
- 文本内容(如有)
输出示例:
{
"totalMorphs": 12,
"displayedMorphCount": 1,
"morphs": [
{
"class": "MenubarMorph",
"visible": true,
"bounds": {"x": 0, "y": 0, "width": 976, "height": 18},
"backgroundColor": "(Color r: 0.883... alpha: 0.8)",
"owner": "WorldMorph",
"submorphCount": 8
}
]
}*规格(演示者):*
- 窗口标题和类名
- 几何形状(范围、位置)
- 窗口状态(最大化、最小化、可调整大小)
- 装饰(菜单、工具栏、状态栏显示)
- 演示者层次结构(递归,最大深度为3级)
- 演示者类名、子计数和内容属性(标签、文本、值等)
- 启用和可见性状态
输出示例:
{
"windowCount": 1,
"presenters": [
{
"class": "SpWindowPresenter",
"title": "Welcome",
"extent": "(700@550)",
"hasMenu": false,
"presenter": {
"class": "StWelcomeBrowser",
"childCount": 2,
"isVisible": true,
"children": []
}
}
]
}*咆哮(可视化):*
- 画布边界和可见性状态
- 画布类标识
- 背景颜色和缩放级别
- 形状细节(颜色、位置、范围、标签、文本)
- 边缘细节(源、目标、颜色、标签)
- 节点和边数
输出示例:
{
"canvasCount": 1,
"canvases": [
{
"class": "RSAthensMorph",
"canvasClass": "RSCanvas",
"bounds": {"x": 203, "y": 145, "width": 490, "height": 467},
"backgroundColor": "Color blue",
"zoomLevel": "1.0",
"shapeCount": 5,
"shapes": [
{
"class": "RSCircle",
"color": "(Color r: 1.0 g: 0.0 b: 0.0 alpha: 0.2)",
"position": "(0.0@0.0)",
"extent": "(5.0@5.0)"
}
],
"edgeCount": 0,
"edges": [],
"nodeCount": 0
}
]
}服务器配置工具
这 get_settings 和 apply_settings 工具提供动态服务器配置管理。
获取设置
检索当前服务器配置。
参数: 无
退货: 包含当前服务器设置的词典
使用示例:
# Get current settings
get_settings()
# Returns: {"stackSize": 100, "customKey": "customValue"}响应格式:
{
"success": true,
"result": {
"stackSize": 100,
"customKey": "customValue"
}
}应用程序设置
动态修改服务器配置。设置在当前会话期间立即生效。
参数:
settings(dict):包含要修改的设置的词典
退货: 成功确认消息
使用示例:
# Apply new settings
apply_settings(settings={"stackSize": 200, "customKey": "customValue"})
# Returns: "Settings applied successfully"常用设置:
| 设置 | 类型 | 默认值 | 描述 |
|---|---|---|---|
stackSize | integer | 100 | 错误报告的最大堆栈跟踪深度 |
注: 服务器接受超出文档设置的任意键值对,允许自定义配置选项。
发展
运行测试
该项目包括全面的单元测试和基于模拟的测试,以避免需要实时Pharo实例:
# Run all tests
uv run pytest
# Run tests with verbose output
uv run pytest -v
# Run specific test file
uv run pytest tests/test_core.py -v代码质量
# Run linting
uv run ruff check
# Run formatting
uv run ruff format
# Run all pre-commit hooks
uv run pre-commit run --all-files项目结构
pharo-smalltalk-interop-mcp-server/
├── pharo_smalltalk_interop_mcp_server/
│ ├── __init__.py
│ ├── core.py # HTTP client and core functions
│ └── server.py # FastMCP server with tool definitions
├── tests/
│ ├── __init__.py
│ ├── test_core.py # Tests for core HTTP client functionality
│ └── test_server.py # Tests for MCP server integration
├── pyproject.toml # Project configuration
├── pytest.ini # Test configuration
└── README.md测试策略
测试套件使用基于模拟的测试来确保:
- 无外部依赖关系:测试运行时不需要实时Pharo实例
- 全面覆盖:测试了所有22个端点和错误场景
- 快速执行:测试在1秒内完成
- 可靠的结果:测试是确定性的,不依赖于外部状态
测试覆盖范围包括:
- HTTP客户端功能(
PharoClient类) - 所有22个Pharo互操作操作
- 错误处理(连接错误、HTTP错误、JSON解析错误)
- MCP服务器初始化和工具注册
- 核心功能和MCP工具之间的集成
