本指南将详细介绍如何在 Unity 项目中整合 MCP 协议,涵盖安装、项目结构、运行、配置、调试、故障排查等方面的内容,帮助你快速上手使用。
在开始整合 MCP 协议之前,请确保你已经完成以下步骤:
git clone https://github.com/CoderGamester/mcp-unity.git
cd mcp-unity
Assets/Package Manager:
git clone https://github.com/CoderGamester/mcp-unity.git
cd mcp-unity
Assets/Package Manager:
mcp-unity/
├── Assets/ # Unity 工程资产
│ ├── Editor/ # MCP 编辑器脚本
│ └── PackageManager/ # 包管理配置文件
├── Server/ # Node.js 服务端代码
│ ├── src/ # 源代码文件夹
│ │ ├── index.ts # 入口文件
│ │ └── server.ts # 服务逻辑
│ └── build/ # 编译生成目录
├── .env # 环境变量配置
└── README.md # 使用文档
cd ABSOLUTE/PATH/TO/mcp-unity/Server
npm install && node build/index.js
在根目录创建或编辑 .env 文件,添加以下配置:
LOGGING=true
LOGGING_FILE=false
PORT=8090
通过命令行传递额外参数:
# 设置日志级别
--logLevel debug
# 启用远程调试
--enableRemoteDebugging
支持以下协议版本:
ws://localhost:8090
"/api/v1"
在 Server/src 目录下,添加断点并启动调试程序。
启用控制台日志:
set LOGGING=true & set LOGGING_FILE=false
参与以下社区讨论:
.env 文件中设置 LOGGING=false。本项目遵循 MIT 开源协议:
MIT License
Copyright (c) 2023 CoderGamester
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.