Unity-MCP
使用模型上下文协议 (MCP) 在 Unity 和 AI 助手之间建立桥梁。
概述
Unity-MCP 是 Unity 游戏开发的模型上下文协议 (MCP) 的开源实现。它使 AI 助手能够通过标准化接口与 Unity 游戏环境进行交互,从而实现 AI 辅助游戏开发、自动化测试、场景分析和运行时调试。
建筑学
该架构已简化为使用 AILogger 进行持久化,从而无需单独的服务器组件:
- AI 助手:使用 MCP 协议与 Unity-MCP STDIO 客户端进行通信
- Unity-MCP STDIO 客户端:将命令转发到 Unity 客户端并将结果存储在 AILogger 中
- Unity Client :在Unity中执行命令并返回结果
- AILogger :存储日志和结果以供日后检索
Unity-MCP STDIO 客户端直接与 Unity 客户端通信,后者提供代码执行和查询的端点。查询工具通过将查询包装在return
语句中,将其转换为代码执行。
特征
- 在 Unity 运行时环境中执行 C# 代码
- 检查游戏对象及其组件
- 分析场景层次和结构
- 运行测试并接收结果
- 调用游戏对象和组件的方法
- 在运行时修改游戏状态
部署选项
- Unity 编辑器扩展:一个在游戏执行周期之外持续存在的编辑器扩展
- Docker 容器:通过网络与 Unity 通信的容器化版本
- NPX 包:可以通过 NPX 安装和运行的 Node.js 包
文档
- MCP 架构:MCP 架构和命名空间概述
- MCP STDIO 客户端:有关 MCP STDIO 客户端及其日志记录功能的信息
- 查询工具:有关查询工具及其工作原理的详细信息
- AILogger 集成:有关 AILogger 集成的详细信息
- API 参考:有关 API 端点的详细信息
- 安装指南:安装和设置 Unity-MCP 的分步说明
- 开发指南:有关开发环境和工作流程的信息
- 热重载指南:关于开发环境中热重载的详细信息
- 热重载快速参考:热重载命令和技巧的快速参考指南
- 贡献指南:为项目做出贡献的指南
入门
要开始使用 Unity-MCP,请按照以下步骤操作:
- 克隆存储库:
- 安装依赖项:
- 构建项目:
- 启动 MCP STDIO 客户端:这将启动与 Unity 通信并使用 AILogger 进行持久化的 MCP STDIO 客户端。注意:确保 AILogger 在http://localhost:3030上运行或设置 AI_LOGGER_URL 环境变量以指向您的 AILogger 实例。
- 运行测试:
有关更详细的说明,请参阅安装指南。
连接AI助手
要将 Unity-MCP 桥接到 AI 助手,您需要创建一个 MCP 配置文件:
将此文件放置在适合您的AI助手的位置。对于Claude,通常位于Claude桌面应用程序的配置目录中。
可用工具
Unity-MCP 桥提供以下工具:
- execute_code :在 Unity 中直接执行 C# 代码。
- query :使用点符号执行查询来访问对象、属性和方法。
- get_logs :从 AILogger 检索日志。
- get_log_by_name :从 AILogger 检索特定日志。
使用示例
在 Unity 中执行代码
您可以使用execute_code
工具在Unity中执行C#代码。该代码将在Unity运行时环境中执行,并将结果存储在AILogger中以供后续检索。
JSON-RPC 请求
JSON-RPC 响应
查询 Unity 对象
您可以使用query
工具查询 Unity 对象。这允许您使用点符号访问对象、属性和方法。
JSON-RPC 请求
JSON-RPC 响应
从 AILogger 检索结果
您可以使用get_log_by_name
工具从 AILogger 检索以前操作的结果。
JSON-RPC 请求
JSON-RPC 响应
示例用法
一旦 AI 助手可以访问 Unity 工具,您就可以要求它执行以下任务:
执照
麻省理工学院
作者
T Savo( @TSavo )
You must be authenticated.
hybrid server
The server is able to function both locally and remotely, depending on the configuration or use case.
Unity 和 AI 助手之间的桥梁,使 AI 能够通过标准化接口与 Unity 游戏环境进行交互,以执行代码、场景分析和运行时调试。
Related Resources
Related MCP Servers
- -securityAlicense-qualityProvides code manipulation, execution, and version control capabilities. It allows AI assistants to read, write, and execute code while maintaining a history of changes.Last updated -8PythonMIT License
- -securityFlicense-qualityEnables AI assistants to interact with Metabase databases and dashboards, allowing users to list and execute queries, access data visualizations, and interact with database resources through natural language.Last updated -25JavaScript
- -securityAlicense-qualityA server that enables AI assistants to understand and interact with Unity projects in real-time, providing access to scene hierarchy, project settings, and the ability to execute code directly in the Unity Editor.Last updated -40MIT License
- -securityFlicense-qualityEnables AI assistants to interact with Metabase, providing access to dashboards, questions, databases, and tools for executing queries and viewing data through natural language.Last updated -JavaScript