一个本地MCP服务器,用于与本地Pharo Smalltalk镜像通信。 它支持:
无需克隆仓库即可运行服务器的最简单方式:
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
cd pharo-smalltalk-interop-mcp-server
uv sync --dev
使用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
使用uv:
PHARO_SIS_PORT=9999 uv run pharo-smalltalk-interop-mcp-server
使用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"
}
}
}
}
使用uv(克隆后):
{
"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服务器的环境变量。
使用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
使用uv(克隆后):
claude mcp add -s user smalltalk-interop -- uv --directory /path/to/pharo-smalltalk-interop-mcp-server run pharo-smalltalk-interop-mcp-server
此服务器提供了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:运行特定类的测试套件read_screen:用于调试Pharo接口的UI屏幕阅读器,带有截图和结构提取get_settings:检索当前服务器配置apply_settings:动态修改服务器配置read_screen工具捕获截图并提取UI结构,用于调试Pharo UI问题。
参数:
target_type(字符串,默认值:'world'):要检查的UI类型('world'用于形态,'spec'用于窗口,'roassal'用于可视化)capture_screenshot(布尔值,默认值:true):响应中是否包含PNG截图返回值: 带有截图和人类可读摘要的UI结构
使用示例:
# 检查World中的所有形态
read_screen(target_type='world')
# 检查Spec演示器窗口
read_screen(target_type='spec', capture_screenshot=False)
# 不带截图检查Roassal可视化(更快)
read_screen(target_type='roassal', capture_screenshot=False)
提取的数据包括:
World(形态):
示例输出:
{
"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
}
]
}
Spec(演示器):
示例输出:
{
"windowCount": 1,
"presenters": [
{
"class": "SpWindowPresenter",
"title": "Welcome",
"extent": "(700@550)",
"hasMenu": false,
"presenter": {
"class": "StWelcomeBrowser",
"childCount": 2,
"isVisible": true,
"children": []
}
}
]
}
Roassal(可视化):
示例输出:
{
"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_settings()
# 返回:{"stackSize": 100, "customKey": "customValue"}
响应格式:
{
"success": true,
"result": {
"stackSize": 100,
"customKey": "customValue"
}
}
动态修改服务器配置。设置在当前会话期间立即生效。
参数:
settings(字典):包含要修改的设置的字典返回值: 成功确认消息
使用示例:
# 应用新设置
apply_settings(settings={"stackSize": 200, "customKey": "customValue"})
# 返回:"设置应用成功"
常见设置:
| 设置 | 类型 | 默认值 | 描述 |
|---|---|---|---|
stackSize | 整数 | 100 | 错误报告的最大堆栈跟踪深度 |
注意: 服务器接受超出文档设置的任意键值对,允许自定义配置选项。
该项目包含全面的单元测试,采用基于模拟的测试,避免需要实时Pharo实例:
# 运行所有测试
uv run pytest
# 运行具有详细输出的测试
uv run pytest -v
# 运行特定测试文件
uv run pytest tests/test_core.py -v
# 运行代码检查
uv run ruff check
# 运行代码格式化
uv run ruff format
# 运行所有预提交钩子
uv run pre-commit run --all-files
pharo-smalltalk-interop-mcp-server/
├── pharo_smalltalk_interop_mcp_server/
│ ├── __init__.py
│ ├── core.py # HTTP客户端和核心函数
│ └── server.py # FastMCP服务器及工具定义
├── tests/
│ ├── __init__.py
│ ├── test_core.py # 核心HTTP客户端功能测试
│ └── test_server.py # MCP服务器集成测试
├── pyproject.toml # 项目配置
├── pytest.ini # 测试配置
└── README.md
测试套件使用基于模拟的测试确保:
测试覆盖率包括:
PharoClient类)