这是一个用于Unreal Engine (UE) 的插件,它创建了模型上下文协议 (MCP)的服务器实现。 这允许像Anthropic的Claude这样的MCP客户端访问完整的UE Python API。
最简单的安装MCP Python Bridge插件的方法是从Fab商店列表。购买插件后,它会出现在Epic Games启动器中的库中。点击“安装到引擎”并选择适当的Unreal Engine版本。
Plugins文件夹。Plugins文件夹中,以便有一个新的包含所有项目内容的文件夹。.uproject结尾),并选择“生成Visual Studio项目文件”。如果您立即看不到该选项,请先选择“显示更多选项”,然后它应该会出现。MCPClient文件夹中的unreal_mcp_client.py复制到您选择的位置。claude_desktop_config.json配置文件。
Mac位置:~/Library/Application\ Support/Claude/claude_desktop_config.json
Windows位置:[您的用户账户路径]\AppData\Claude\claude_desktop_config.jsonunreal-engine服务器部分添加到您的配置文件中,并更新路径位置,不包括方括号,如下所示。
Mac路径格式:/[步骤4中的路径]/unreal_mcp_client.py
Windows路径格式:C:\\[步骤4中的路径]\\unreal_mcp_client.py{
"mcpServers": {
"unreal-engine": {
"command": "python",
"args": [
"[mac_or_windows_format_path_to_unreal_mcp_client.py]"
]
}
}
}
UnrealMCPBridge插件,并重新启动。create_castle和create_town。您可以在插件的Content文件夹下的unreal_server_init.py中编辑它们的实现。确保在更改后重新启动Unreal Engine。查看unreal_mcp_client.py,您会看到MCP如何使用函数上方的Python装饰器定义工具和提示。例如:
@mcp.tool()
def get_project_dir() -> str:
"""获取顶级项目目录"""
result = send_command("get_project_dir")
if result.get("status") == "success":
response = result.get("result")
return response
else:
return json.dumps(result)
这将get_project_dir命令发送给Unreal Engine执行,并返回当前项目的顶级目录。在插件的Content文件夹下,您可以看到此工具命令的服务器端实现:
@staticmethod
def get_project_dir():
"""获取顶级项目目录"""
try:
project_dir = unreal.Paths.project_dir()
return json.dumps({
"status": "success",
"result" : f"{project_dir}"
})
except Exception as e:
return json.dumps({ "status": "error", "message": str(e) })
遵循这个模式,在Claude桌面界面的锤子图标下创建新的工具。
实现新的提示就是将其添加到unreal_mcp_client.py中。例如,这里是来自unreal_mcp_client.py的create_castle提示:
@mcp.prompt()
def create_castle() -> str:
"""创建一座城堡"""
return f"""
请在当前的Unreal Engine项目中创建一座城堡。
0. 创建新Python代码时,请参考Unreal Engine Python API:https://dev.epicgames.com/documentation/en-us/unreal-engine/python-api/?application_version=5.5
1. 清除场景中的所有静态网格物体。
2. 获取项目目录和内容目录。
3. 寻找可用于构建结构的基本形状。
4. 使用这些基本形状创建一座城堡。
"""
确保保持三重引号,以便整个提示被返回。迭代创建提示的一个好方法是简单地与Claude迭代每个步骤编号,直到获得满意的结果。然后将它们全部合并成一个编号的逐步提示,如上所示。
您必须重启Claude才能使对unreal_mcp_client.py所做的更改生效。请注意,在Windows上,您可能需要在任务管理器中结束Claude进程才能真正重启Claude。