dsh-unity-mcp-bridge
Agent 与会话 活跃维护

dsh-unity-mcp-bridge

xiake-1/dsh-unity-mcp-bridge

连接unitymcp(第三方unitymcp工具,实测速度和质量兼具)和dsh的插件,同时加入了技能工具,精简了unitymcp的输入和输出量,加快使用agent协助unity开发速度

0
Stars 标星
0
Forks 分支
0
Watchers 关注
0
Open Issues
JavaScript
主要语言
MIT
开源协议
123 KB
仓库大小
1 个月前
最后推送
一键安装扩展 / 插件指令
dsh plugin --profile web add github:xiake-1/dsh-unity-mcp-bridge
git clone https://github.com/xiake-1/dsh-unity-mcp-bridge.git
git clone git@github.com:xiake-1/dsh-unity-mcp-bridge.git
README.md main

dsh-unity-mcp-bridge

Feature overview and a measured comparison of "tools vs handling it directly from files"
(token cost and latency, with the numbers behind them):
FEATURES-AND-COMPARISON.md (Chinese).

中文说明(简明版)→ README.zh.md

A self-contained DeepSeek Harness (DSH) plugin that connects on demand to a Unity MCP
server (AI Game Developer / com.ivanmurzak.unity.mcp). It is dormant until the user runs
/unity-mcp-tools
— Unity capability never turns on by itself (see
Activation model). On top of that it adds the three things the
stock @deepseek-ai/dsh-mcp-client does not give you:

  1. A vendored implementation — the bridge lives in this package, so a DSH/npx upgrade
    cannot silently revert it. (Patching the installed lib/index.js gets wiped on upgrade;
    this does not.)
  2. A shipped tool catalog skill — skills/SKILL.md (index) plus skills/reference/*.md
    (per-category detail) are registered as a runtime skill at activation. The model loads the
    index on demand and reads one category file only when it needs it.
  3. A restore-when-done helper tool — unity_tools_restore disables every Unity tool
    except the tool-management ones, so an on-demand tool set collapses back to the minimal
    resident set when the task is over.

It also carries the original fix that makes the workflow possible at all:
resyncAfterTools — after a listed tool call returns, the bridge re-fetches tools/list
itself and swaps the registry, instead of waiting for the server's
notifications/tools/list_changed (which DSH's long-lived session does not receive).

Why not just patch the installed package?

@deepseek-ai/dsh-mcp-client is a build artifact inside the npx cache
(.../node_modules/@deepseek-ai/dsh-mcp-client/lib/index.js). npx @deepseek-ai/dsh can
reinstall or upgrade it at any time, silently dropping a hand-applied patch. Vendoring the
implementation here makes the behaviour yours and version-pinned.

Install

The plugin is a normal npm package with @deepseek-ai/* declared as peer dependencies
(the host provides them, exactly like upstream and like third-party plugins such as
dshmarket). Only @modelcontextprotocol/sdk, zod and @deepseek-ai/schemastery are real
dependencies.

DSH version compatibility

The five @deepseek-ai/dsh-* peers declare a floor, not a pin (>=0.1.5-rc.2), so one
checkout installs into any DSH runtime from 0.1.5-rc.2 onward. Verified against the host's own
gate (dsh-app-boot → evaluatePluginCompatibility, i.e.
semver.satisfies(version, range, { includePrerelease: true })) for 0.1.5-rc.2, 0.1.7-rc.2 and
0.2.0-rc.2; the host API this package uses is unchanged across them. @deepseek-ai/cordis keeps
^4.0.2 — it is a separate version line and the host does not gate it. A genuinely
incompatible future runtime is still reported by the host's install-time gate.

# 1) install into the profile that runs the MCP bridge (this profile forwards to pnpm)
#    <profile> is `web` for `dsh web`, `desktop` for the DeepSeek Harness desktop app
dsh plugin --profile <profile> add file:<path-to-this-checkout>
#    or straight from git:
dsh plugin --profile <profile> add git+https://github.com/xiake-1/dsh-unity-mcp-bridge.git

# 2) point your profile patch entry at this package instead of the stock client
#    %DSH_HOME%/profiles/<profile>/cordis.patch.yml
- insert:
    - id: unity-mcp
      name: 'dsh-unity-mcp-bridge'
      config:
        serverName: unity
        transport: streamable-http
        url: http://localhost:24009/p/<your-token>
        resyncAfterTools:
          - tool-set-enabled-state
        resyncIntervalMs: 0
  1. Restart the app (dsh web, or the desktop app). The skill and the helper tool appear
    automatically.

Do not run this bridge and the stock @deepseek-ai/dsh-mcp-client against the same
serverName at the same time.
They are separate module instances, so each believes it
owns the namespace, and both would publish the same public tool names.

Companion skills: install and check

Two more shipped runtime skills cover the other half of the setup — the Unity-side plugin, and
the link between the two halves. Unlike the catalog they are model-visible by default (they
are the on-ramp and the doctor, not the Unity capability itself), and both are also slash
commands:

Skill What it does
/unity-mcp-install Checks whether unity-mcp-cli is on the machine — installs it with npm install -g unity-mcp-cli when it is missing, and checks that its version matches the project's plugin: CLI 1.2.0 ↔ plugin com.ivanmurzak.unity.mcp@1.2.0 ↔ server 9.2.11 are lockstep, and an old CLI silently carries an older AI-agent list (no kilo-code). Then it finds the Unity project inside the current workspace (by ProjectSettings/ProjectVersion.txt). If com.ivanmurzak.unity.mcp is already in Packages/manifest.json it says so; otherwise it runs unity-mcp-cli install-plugin <project> --with-server — which also stages the GameDev-MCP-Server binary into the CLI's managed dir (~/.ai-game-dev/server/<rid>/, the thing configure --agent executes) — and re-reads the manifest to verify. When the GitHub download fails on a restricted network it retries through the machine's own system proxy (Clash): the port is read from the registry instead of guessed, NODE_USE_ENV_PROXY=1 is mandatory because Node 24's global fetch otherwise ignores HTTP_PROXY, and NO_PROXY must keep OpenUPM/npm direct or even plugin-version resolution breaks. Last resort: a resumable proxied zip download verified against the release SHA256SUMS, installed with --server-source.
/unity-mcp-check Finds the same project and pins everything to port 20000. The Unity side is rewritten with unity-mcp-cli bootstrap-local --url http://localhost:20000/ (the project's own UserSettings/AI-Game-Developer-Config.json, after a timestamped backup and a --dry-run diff); the DSH side's unity-mcp row is corrected to http://localhost:20000/mcp when it drifted; other clients still pinned to the old port are reported rather than silently broken. Then it sets the AI agent to Kilo Code: unity-mcp-cli configure <project> --agent kilo-code --url http://localhost:20000 writes .kilocode/mcp.json whose url is http://localhost:20000/p/<pin> — the port follows --url, the path is the per-project pin, and both /mcp and /p/<pin> answer 200. setup-mcp cannot do this (its list has 14 agents, no kilo-code), so the skill uses configure --agent, which proxies to the managed server's configurator (16 agents), and falls back to the project's own Library/mcp-server/<rid>/gamedev-mcp-server.exe when the managed binary is missing. Kilo Code skills come from the Editor's Auto-generate (skillAutoGenerate / skillsPath: .kilocode/skills), since setup-skills lacks the id too. It then initializes the Unity tool set to a single enabled tool — tool-set-enabled-state, the same keep-set unity_tools_restore uses — with two unity-mcp-cli configure calls — --disable-all-tools, then --enable-tools tool-set-enabled-state; they must not be combined, because disable-all wins and would turn off the one management tool that can undo it (no running Editor needed), probes the port and HTTP endpoint, and finishes by loading the bridge with unity_mcp_activate to prove the link.

Both follow the documented setup flow at https://ai-game.dev/engines/unity. Set
registerHelperSkills: false to ship without them; the configuration table below has the name
and invocation knobs.

Configuration

Everything the stock client accepts (serverName, transport, command/args/env/cwd
for stdio, url/headers for streamable-http, toolCallTimeoutMs, failOnStartupError,
reconnect.*) works unchanged. On top of that:

Field Default Meaning
autoStart false Dormant by default: no connection and no bridged tools until a session opts in. Set true to connect at boot (the old always-on behaviour).
activateToolName unity_mcp_activate Name of the always-registered activation hook.
restoreDeactivates true unity_tools_restore also disconnects, returning the session to dormant. false keeps the connection alive.
skillModelInvocable false The catalog skill is not offered to the model, so it never auto-loads and Unity capability never turns on by itself.
skillUserInvocable true The skill is user-invocable: /unity-mcp-tools is the opt-in entry point.
resyncAfterTools [] Raw MCP tool names whose call completion triggers a tools/list re-sync and registry swap. Set it to ['tool-set-enabled-state'] for the on-demand workflow. The trigger runs ~200 ms after the call returns, so the in-flight result finalizes first.
resyncIntervalMs 0 Periodic re-sync (ms); 0 disables. Enabling it also picks up switches flipped by hand in the Unity window, at the cost of rebuilding the tool registrations every tick.
restoreToolName unity_tools_restore Name of the native restore hook.
keepEnabledTools [] Extra raw tool names the restore hook leaves enabled (on top of tool-set-enabled-state).
registerCatalogSkill true Register the shipped catalog as a runtime skill.
skillName unity-mcp-tools Skill name / slash command (/unity-mcp-tools).
registerHelperSkills true Register the two shipped helper skills (/unity-mcp-install, /unity-mcp-check).
installSkillName unity-mcp-install Name of the skill that installs the Unity-side plugin into the workspace's Unity project.
checkSkillName unity-mcp-check Name of the skill that verifies the bridge reaches Unity and repairs the profile URL.
helperSkillsModelInvocable true The helpers, unlike the catalog, are offered to the model so it can reach for them unprompted.
helperSkillsUserInvocable true They are also user-invocable slash commands.

Activation model (opt-in)

The plugin is dormant from boot: it registers exactly two tiny hook tools and does not
connect to Unity, so a session that never asks for Unity pays ~895 characters (~224 tokens)
and nothing else.

boot ──► DORMANT ──(/unity-mcp-tools ─► unity_mcp_activate)──► ACTIVE ──(unity_tools_restore)──► DORMANT
          2 hook tools                                          bridged mcp__unity__* tools
  1. The user invokes /unity-mcp-tools. The skill is model-invisible (skillModelInvocable: false), so this is the only way in; its body is injected as instructions.
  2. The model calls unity_mcp_activate → the bridge connects, and the Unity tools currently
    enabled on the Unity side are registered (mcp__unity__*).
  3. Work proceeds with the on-demand enable/use workflow below.
  4. unity_tools_restore disables every Unity tool except tool-set-enabled-state and
    disconnects
    , so the session is dormant again.

Workflow the model is told to follow

The skill body states it, and the hook tools enforce the ends of it:

  1. Activate — unity_mcp_activate (the first step after /unity-mcp-tools).
  2. Locate — read the index, then the one reference/<category>.md that matters.
  3. Enable — mcp__unity__tool-set-enabled-state with the needed commands set to
    enabled: true. Takes effect on the next step (the registry is rebuilt at request
    boundaries), never in the same step.
  4. Use — call mcp__unity__<command> on the next step.
  5. Restore — call unity_tools_restore when the Unity work is done. It disables
    everything except the management tool. Keep specific tools with
    unity_tools_restore({ "keep": ["gameobject-find"] }).

Every enabled command contributes its full JSON schema to every subsequent model request;
disabled ones contribute nothing. Enabling is a temporary, reclaimable cost — forgetting step 4
is what turns it permanent. The restore helper exists so step 4 never requires enumerating 73
names.

Regenerating the catalog

tools/generate-unity-mcp-catalog.ps1 scans the installed
com.ivanmurzak.unity.mcp@* package and rewrites skills/SKILL.md plus
skills/reference/*.md (categories come from the plugin's own [AiTool(Title = ...)]
attributes). Re-run it after a Unity plugin upgrade, then restart dsh web.

powershell -NoProfile -ExecutionPolicy Bypass -File tools/generate-unity-mcp-catalog.ps1 -ProjectRoot <your-unity-project>

Uninstall / rollback

dsh plugin --profile web remove dsh-unity-mcp-bridge

Then point the profile patch entry back at @deepseek-ai/dsh-mcp-client (or delete the row).
No files outside this package are modified, so rollback is just the removal.

Provenance and license

lib/index.js is derived from @deepseek-ai/dsh-mcp-client v0.1.5-rc.2
(MIT, Copyright (c) 2026 DeepSeek — see LICENSE). The file header lists the exact
modifications: plugin rename, resyncAfterTools/resyncIntervalMs, sync-completion
reporting, the restore helper, and the runtime catalog skill. The MIT license permits this;
the upstream copyright notice is retained.

Self-test

tools/selftest.mjs drives the real plugin against a live Unity MCP server with a minimal
fake host context — no DSH restart needed. It needs the package dependencies installed
(pnpm install inside the package, or run it from a profile that already has them), and it
reads the endpoint from UNITY_MCP_URL, so no project token is stored in the repository.

$env:UNITY_MCP_URL = 'http://localhost:24009/p/<your-token>'   # your project's own endpoint
node tools/selftest.mjs

It asserts, in order: the module exports; Config accepts every new field with
upstream-compatible defaults; apply() connects and registers both the bridged tool and the
native helper; the catalog skill registers with the right resourceBase and a body containing
the workflow; calling the bridged management tool makes the bridge re-sync on its own (the
newly enabled tool appears in the registry); and the restore helper disables everything outside
its keep set. Observed output on the reference setup:

3) apply() 启动…
   [info] unity-mcp-bridge: catalog skill "unity-mcp-tools" registered
   桥接工具: mcp__unityprobe__tool-set-enabled-state
   原生工具: unity_tools_restore
   技能正文包含工作流与恢复指令: true
4) 通过桥接工具开启 gameobject-find …
   [info] unity-mcp-bridge(unityprobe): tool tool-set-enabled-state returned, re-syncing tool list
   >>> 自动重同步是否生效: 是 ✓
5) 调用恢复工具 keep=[unity-tool-list] …
   返回: Disabled 1 Unity-MCP tool(s); kept enabled: tool-set-enabled-state, unity-tool-list.
   恢复后桥接工具: mcp__unityprobe__tool-set-enabled-state

Status

  • Verified against a live Unity MCP server: module load, Config defaults, apply()
    registration (bridged tools + native helper), runtime skill registration with
    resourceBase, self-driven re-sync after a management-tool call, and the restore helper's
    disable-everything-except-keep behaviour. See tools/selftest.mjs.
  • Not verified here: installation via dsh plugin --profile web add and a full dsh web
    boot with the plugin mounted — that needs a profile install and a DSH restart.