Skip to content

fix(desktop): bind MCP lifecycle to one Node runtime#3455

Merged
t8y2 merged 4 commits into
t8y2:mainfrom
CN-Scars:fix/mcp-node-runtime-resolution
Jul 15, 2026
Merged

fix(desktop): bind MCP lifecycle to one Node runtime#3455
t8y2 merged 4 commits into
t8y2:mainfrom
CN-Scars:fix/mcp-node-runtime-resolution

Conversation

@CN-Scars

Copy link
Copy Markdown
Contributor

变更说明

修复 DBX Desktop 安装、检测和启动 DBX MCP Server 时可能使用不同 Node.js 运行时的问题。

本 PR 将 DBX 管理的 MCP 生命周期绑定到同一个 Node/npm 运行时:

  • 安装 @dbx-app/mcp-server 时,使用选定 Node 安装目录下对应的 npm CLI。
  • 状态检测和包路径解析使用同一个 Node/npm runtime tuple,避免混用不同环境中的 nodenpm root -g 或 npm shim。
  • Codex CLI / MCP 配置生成时使用绝对 node 路径和绝对 dist/index.js 路径启动 MCP Server,避免 #!/usr/bin/env node 在后续 PATH 中解析到另一个 Node。
  • 补充相关单元测试,覆盖 runtime 绑定、已安装包优先级、canonical path 和 Windows npm 布局等场景。

变更类型

  • 新功能
  • Bug 修复
  • 性能优化
  • 代码重构
  • 文档更新
  • CI / 构建

涉及前端

本 PR 涉及前端配置生成逻辑,但不涉及 UI 布局、样式或交互视觉变化;改动点是 AI 设置中生成 Codex MCP 配置时的 command / args 内容。

  • 本 PR 涉及前端改动,已附截图/录屏(见下方)

无可视 UI 差异;已通过 DBX Desktop UI 安装 MCP 后手动验证生成路径和 MCP 调用链路。

验证

  • make check 通过
  • make cargo-check-fast 通过
  • 相关测试通过

已执行:

  • cargo fmt --all --check
  • make check
  • make cargo-check-fast
  • cargo test -p dbx commands::mcp::tests --no-default-features
  • cargo test --workspace --no-default-features
  • git diff --check

手动验证:

  • 先在 Homebrew Node 下安装 @dbx-app/mcp-server,确认 DBX 能解析并用同一个 Node/script 组合启动 MCP。
  • 通过 DBX Desktop UI 重新安装 MCP,确认安装落在 .nvmrc 对应的 fnm Node v22.13.0 下。
  • 使用解析出的绝对 Node 路径和 MCP dist/index.js 路径初始化 MCP,并执行 Redis DBSIZE 工具调用成功。

关联 Issue

N/A

@CN-Scars
CN-Scars marked this pull request as draft July 14, 2026 11:22
@CN-Scars
CN-Scars force-pushed the fix/mcp-node-runtime-resolution branch from 2beaf0b to d84ff2c Compare July 14, 2026 11:25
@CN-Scars
CN-Scars marked this pull request as ready for review July 14, 2026 11:27

@t8y2 t8y2 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm going to request changes for now. The runtime paths are kept coherent, but runtime compatibility is still not enforced.

NodeRuntime::probe records the selected Node version, and prefer_runtime immediately accepts any runtime whose npm root contains the MCP script. @dbx-app/mcp-server requires Node >=22.13.0, so with a shared global npm prefix an older Node earlier in PATH can see a package installed by Node 22 and still be selected. DBX would then generate an absolute old-Node + MCP-script command that cannot start the server.

Please reject incompatible Node runtimes before they can win selection (or validate the package's engines.node) and add a regression test covering an old PATH Node sharing an npm root with a later compatible runtime. Since this PR also changes Windows-specific runtime discovery, please run the Windows-only tests on Windows as part of the update.

@CN-Scars
CN-Scars force-pushed the fix/mcp-node-runtime-resolution branch from d84ff2c to 7bcedaa Compare July 14, 2026 15:52
@CN-Scars

Copy link
Copy Markdown
Contributor Author

已补充 Node.js >=22.13.0 兼容性检查和共享 npm root 的回归测试;Windows 专项 CI 已通过,并已在 Windows/macOS 真机确认 UI 安装后的运行时路径一致。请再次 review。

@t8y2
t8y2 merged commit 872e59f into t8y2:main Jul 15, 2026
7 checks passed
@t8y2

t8y2 commented Jul 15, 2026

Copy link
Copy Markdown
Owner

Thanks for the contribution! Merged in 872e59f, will be released in the next version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants