dcc-mcp-unity

dcc-mcp-unity

Unity Editor adapter for the DCC MCP ecosystem, providing tools to inspect and modify Unity projects, scenes, builds, and diagnostics through a WebSocket bridge.

Category
访问服务器

README

dcc-mcp-unity

DCC-MCP Unity lockup

Unity Editor adapter for the DCC Model Context Protocol ecosystem. It ships a UPM Editor package, a loopback WebSocket bridge, and typed project, scene, build, and diagnostic tools.

The supported Editor range starts at Unity 2018.4.25f1 with the .NET 4.x Equivalent scripting runtime. CI pins that Unity 2018 baseline, the 2021.3 baseline, and the current stable Unity 6 release instead of using a drifting latest tag.

The first-release boundary and comparison with unity-cli and two established Unity MCP projects are documented in the architecture benchmark.

Install

pip install dcc-mcp-unity
dcc-mcp-unity-install /path/to/UnityProject

Open or restart the Unity project so Package Manager compiles DCC-MCP Unity, then run:

dcc-mcp-unity

See the installation guide for upgrade, environment, and connection verification details.

The MCP endpoint uses a free loopback port and is registered for gateway discovery. Set DCC_MCP_UNITY_PORT=8765 before starting the server only when a fixed direct endpoint is needed. The Editor package reconnects to the loopback bridge at ws://127.0.0.1:3852; set DCC_MCP_UNITY_BRIDGE_PORT before the MCP server and DCC_MCP_UNITY_BRIDGE_URL before Unity starts to override it. DCC_MCP_UNITY_BRIDGE_TIMEOUT may increase the 60-second RPC timeout but cannot lower it; queued Editor work expires first so timed-out mutations are not executed later.

The default bridge targets one Unity Editor. For concurrent Editors, run one adapter per Editor and assign each pair a unique bridge port and URL before starting either process.

Source writes are disabled by default. An operator may set DCC_MCP_UNITY_ALLOW_SOURCE_WRITES=1 before starting Unity to enable the bounded upsert_text_asset tool. It accepts only allowlisted UTF-8 text extensions below Assets, caps encoded content at 256 KiB, rejects JSON-unsafe control characters, requires compare-and-swap state, rejects reparse points, and replaces files atomically. The adapter exposes no delete, arbitrary path, shell, or code-evaluation tool.

The per-asset lock is cooperative: it serializes DCC-MCP writers but cannot stop another same-user process from ignoring the lock or swapping a junction or symlink after path validation and before the operating system resolves a write. That same-user race is outside this in-process boundary. If an external replacement conflict is detected, the adapter performs no automatic rollback, preserves the displaced bytes in a unique .dccmcp-*.backup conflict backup, and does not write the target again after detection. A failed conflict job does not prove the target stayed unchanged; inspect both the target and backup before submitting another write.

Standalone sidecar

Hosts without an embedded Python runtime can use the PyOxidizer sidecar released with each version. The release asset contains the executable, its adjacent lib/ runtime, and SHA256SUMS. Configure the Unity package to start it on editor load by setting DCC_MCP_UNITY_SIDECAR_PATH; optionally set DCC_MCP_UNITY_SIDECAR_SHA256 to the published digest. The launcher is loopback-only, passes the Unity process id to --watch-pid, and uses a per-project pid file to avoid duplicate sidecars after assembly reloads.

For local development, run dcc-mcp-unity-standalone --bridge-port 3852 --watch-pid <unity-pid>.

Agent workflow

  1. Load unity-project and call inspect_project before assuming project or editor state. Stop if the returned project is not the intended target or the Editor is compiling, updating, entering Play Mode, or playing.
  2. Read an existing source with read_text_asset, then pass its SHA-256 to upsert_text_asset; use expected_sha256: absent only for creation. Keep the UUID request_id and poll inspect_job until it reports succeeded or failed.
  3. Call refresh_and_compile, poll its job, and inspect read_console before entering Play Mode.
  4. Load unity-scene and call inspect_scene immediately before using an instance ID. Treat IDs as opaque values and return them unchanged. Unity 6000.5+ emits decimal strings; older Editors retain integer output, and both forms are accepted as input.
  5. Create GameObjects or change transforms through typed operations backed by Unity Undo, verify the hierarchy, then explicitly call save_scene.
  6. Use set_play_mode before capture_game_view; capture requires active, unpaused Play Mode, focuses Game View, waits a rendered frame, and succeeds only after Unity decodes a nonzero PNG below Builds/DccMcp/Captures. Captures are limited to 32 MiB, 8192 pixels per axis, and 32M pixels total.
  7. run_tests executes the installed Unity Test Framework in EditMode or PlayMode without spawning another Editor. Optional filters are exact fully-qualified test or fixture names. Poll the job and retain its request-scoped NUnit XML, SHA-256, outcome, and counts as test evidence; zero matches fail closed.
  8. build_windows_player persists an active-target switch when needed, rejects dirty enabled scenes, and builds exactly the saved Build Settings scenes to a new UUID directory below Builds/DccMcp. Poll the job and launch the reported executable as a separate acceptance gate.

Do not replace a timed-out job with a new UUID. Reconnect and inspect the original request_id; Unity persists queued/running/succeeded/failed state across domain reloads and rejects reuse with different parameters.

Unity 2018 reloads Editor assemblies during normal Play Mode transitions, so the loopback socket will disconnect and reconnect. set_play_mode persists its waiting state before requesting the transition; a bridge disconnect is not completion or failure. After reconnection, inspect the same request_id for the observed terminal state.

No raw C# evaluation, shell command, or arbitrary filesystem write is exposed. The Editor bridge accepts only the methods implemented in DccMcpCommands and executes them on Unity's editor update loop. One persistent mutating job runs at a time. Mutations fail closed in incompatible Editor states. Requests, queued work, source text, scene snapshots, Console reads, and serialized responses have explicit size or lifetime budgets.

Validation boundary

Public CI validates Python 3.9 and 3.12 on Windows, macOS, and Linux; validates the bundled skill contracts; performs static checks for the UPM package and main-thread/Undo contracts; and builds the PyPI artifacts. Trusted pull requests, main, and the weekly schedule also compile the UPM package and run its command, scene, Undo, and validation tests through GameCI in Unity 2018.4.25f1, 2021.3.45f1, and 6000.5.4f1. Fork pull requests skip the licensed Editor jobs because GitHub does not expose repository secrets to forks. Licensed runs share one repository-wide queue across pull requests, main, releases, and schedules so a Personal seat is never activated concurrently. Each Editor also completes a real WebSocket hello → project.inspect → response smoke against the Python sidecar and records the reported Editor version as an artifact.

Development

uv sync --extra dev
uv run python -m pytest
uv run ruff check src tests tools
uv run ruff format --check src tests tools
uv run python tools/lint_skills.py
uv run python -m build
uv run python -m twine check dist/*

Unity and the Unity cube logo are trademarks of Unity Technologies. This independent adapter is not affiliated with or endorsed by Unity Technologies.

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选