虚幻的python mcp
MCP(模型上下文协议)服务器,用于Unreal Python API文档和执行。
使Claude Code等AI编码助手能够:
- 浏览虚幻Python API文档
- 搜索类和函数
- 在虚幻编辑器中执行Python代码
安装
# Clone the repository
git clone https://github.com/self-taught-code-tokushima/unreal-python-mcp.git
cd unreal-python-mcp
# Install with uv
uv syncClaude代码设置
添加到您的Claude Code MCP配置中(~/.config/claude/mcp.json 或项目级别 .mcp.json):
{
"mcpServers": {
"unreal-python": {
"command": "uv",
"args": ["--directory", "D:\\UnrealProjects\\unreal-python-mcp", "run", "unreal-python-mcp"]
}
}
}或
{
"mcpServers": {
"unreal-python": {
"command": "uvx",
"args": ["--from", "git+https://github.com/self-taught-code-tokushima/unreal-python-mcp", "unreal-python-mcp"]
}
}
}需求
- Python 3.13+
- 启用Python插件的虚幻编辑器
- 在编辑器首选项>插件>Python中选中“启用远程执行”
自定义模块支持
除了内置 unreal 模块,您可以在虚幻编辑器环境中记录可用的自定义Python模块(例如。, MaterialGraphEditor).
设置
添加 env 使用 UNREAL_PYTHON_CUSTOM_MODULES 环境变量:
{
"mcpServers": {
"unreal-python": {
"command": "uvx",
"args": ["--from", "git+https://github.com/self-taught-code-tokushima/unreal-python-mcp", "unreal-python-mcp"],
"env": {
"UNREAL_PYTHON_CUSTOM_MODULES": "YourCustomModule1,YourCustomModule2"
}
}
}
}使用自定义模块刷新缓存
配置自定义模块后,刷新缓存以包含它们:
# Windows PowerShell
$env:UNREAL_PYTHON_CUSTOM_MODULES="MaterialGraphEditor,BlueprintGraphEditor"
uvx unreal-python-mcp-refresh
# Or with uv run
$env:UNREAL_PYTHON_CUSTOM_MODULES="MaterialGraphEditor,BlueprintGraphEditor"
uv run unreal-python-mcp-refresh# Linux/macOS
UNREAL_PYTHON_CUSTOM_MODULES="MaterialGraphEditor,BlueprintGraphEditor" uvx unreal-python-mcp-refresh备注
- 将多个模块指定为逗号分隔的值
- 自定义模块将与内置模块一起出现在模块列表中
- MCP服务器启动时将自动使用配置的模块
可用工具
| 工具 | 说明 |
|---|---|
search_unreal_api | 按类/函数名称搜索API |
get_class_overview | 获取类概述(成员名单,1-3KB) |
get_member_info | 获取特定成员的详细信息 |
get_members_info | 获取多个成员的详细信息(批量) |
list_modules | 列出可用的虚幻模块 |
exec_unreal_python | 在虚幻编辑器中执行Python代码 |
list_unreal_instances | 列出可用的虚幻编辑器实例 |
refresh_api_cache | 刷新API文档缓存(也可作为CLI: uvx unreal-python-mcp-refresh) |
可用资源
层级索引
类按模块组织,以尽量减少上下文使用。
| 资源 | 大小 | 描述 |
|---|---|---|
unreal-python://index/summary | ~2KB | 从这里开始。 API概述及模块列表 |
unreal-python://index/module/{name} | ~20-90KB | 特定模块的类 |
unreal-python://index/enums | ~50KB | 所有枚举 |
unreal-python://index/structs | ~200KB | 所有结构 |
unreal-python://index/delegates | ~10KB | 所有代表 |
常用模块:
Engine(994个类):核心类-演员、世界、游戏静态UnrealEd(204类):编辑器实用程序-EditorAssetLibraryUMG(110个类):UI/Widget类Niagara(98类):粒子系统
课堂文件
| 资源 | 描述 |
|---|---|
unreal-python://class/{name} | 详细的课堂文档 |
用法示例
在克劳德代码中:
User: Actor クラスの位置を取得するメソッドを教えて
Claude: [Reads unreal-python://index/summary]
→ Engine モジュールに Actor があることを確認
[Reads unreal-python://index/module/Engine]
→ Actor: 145 methods, 48 properties
[Uses get_class_overview("Actor")]
→ メソッド名一覧を取得(1-2KB程度)
[Uses get_member_info("Actor", "get_actor_location")]
→ 詳細ドキュメントを取得
Actor の位置を取得するには get_actor_location() を使います。
返り値は Vector 型です。User: EditorAssetLibrary の使い方を教えて
Claude: [Reads unreal-python://index/summary]
→ UnrealEd モジュールにあることを確認
[Reads unreal-python://index/module/UnrealEd]
[Uses get_class_overview("EditorAssetLibrary")]
→ メソッド名一覧を取得
EditorAssetLibrary はエディタ専用のアセット操作ユーティリティです...User: Unreal で Hello World を出力して
Claude: [Uses exec_unreal_python("print('Hello World')")]
実行結果: Hello World首次设置
- 使用项目启动虚幻编辑器
- 在编辑器首选项中启用Python远程执行(编辑器首选项>插件>Python>启用远程执行)
- 刷新API文档缓存:
# Using uvx (recommended)
uvx unreal-python-mcp-refresh
# Or with uv run (if you cloned the repository)
uv run unreal-python-mcp-refresh或者,您可以使用 refresh_api_cache 连接到MCP服务器后,使用Claude Code的MCP工具。
发展
# Run MCP dev server (with inspector)
uv run mcp dev src/unreal_python_mcp/server.py
# Run directly
uv run unreal-python-mcp许可证
麻省理工学院
