From 985471bdcf1077bfb31df984bc457a08c15da7f8 Mon Sep 17 00:00:00 2001 From: Yichen Jiang Date: Tue, 10 Nov 2026 13:32:36 +0800 Subject: [PATCH] fix(cua-mcp): document client entries instead of generating them `--print-client-config codex|claude-code|json` is withdrawn together with the client-config module and the static `node:sea` import that told a single-file executable from a script launch. The browser worker image packs every optional bundle and registers no `node:sea`, so the Cloudflare preview packer failed to load the bundle; the README now documents the Codex `config.toml` fragment, the `claude mcp add-json dsh_cua` command, and the generic `mcpServers` entry with the same timeouts, tool exposure, and output budget. The frontend accepts only `--help` besides the profile selection, and the server owns its `dsh_cua` name. The README names the macOS helper's prepared build directory relative to the provider package instead of as a repository path, because the gitignored `.build` directory does not exist on a clean tree and `verify-package-paths` rejects the reference. The expected-output e2e asserts the profile manifest after `initialize` instead of after a configuration print. --- ...26-11-09-computer-use-mcp-server.i18n.yaml | 8 +- .../2026-11-09-computer-use-mcp-server.md | 4 +- .../2026-11-09-computer-use-mcp-server.zh.md | 4 +- .../profiles/cua-mcp/cua-mcp.expected.e2e.ts | 16 +-- .../profiles/cua-mcp/expected/codex.toml | 13 -- docs/config-catalog.md | 2 +- docs/config-catalog.zh.md | 2 +- docs/subsystems/computer-use.i18n.yaml | 4 +- docs/subsystems/computer-use.md | 2 +- docs/subsystems/computer-use.zh.md | 2 +- .../experimental/cua-mcp/README.i18n.yaml | 8 +- packages/experimental/cua-mcp/README.md | 29 ++++- packages/experimental/cua-mcp/README.zh.md | 29 ++++- .../experimental/cua-mcp/src/client-config.ts | 115 ------------------ packages/experimental/cua-mcp/src/index.ts | 34 ++---- packages/experimental/cua-mcp/src/server.ts | 4 +- .../cua-mcp/tests/client-config.spec.ts | 71 ----------- .../cua-mcp/tests/startup.spec.ts | 25 +--- 18 files changed, 88 insertions(+), 284 deletions(-) delete mode 100644 apps/cli/tests/profiles/cua-mcp/expected/codex.toml delete mode 100644 packages/experimental/cua-mcp/src/client-config.ts delete mode 100644 packages/experimental/cua-mcp/tests/client-config.spec.ts diff --git a/.agents/notes/implemented/architecture/2026-11-09-computer-use-mcp-server.i18n.yaml b/.agents/notes/implemented/architecture/2026-11-09-computer-use-mcp-server.i18n.yaml index 747e3a9b6a..25e4c48418 100644 --- a/.agents/notes/implemented/architecture/2026-11-09-computer-use-mcp-server.i18n.yaml +++ b/.agents/notes/implemented/architecture/2026-11-09-computer-use-mcp-server.i18n.yaml @@ -9,11 +9,11 @@ en: 6050884223e0e491 zh: eb808c298c9fb652 /agent-note-serve-computer-use-to-other-harnesses-as-an-mcp-server/decision: - en: e91dc20268dc8785 - zh: cfe05aaa6356b329 + en: 607450e5d118c98d + zh: 38c7d795e78ddf97 /agent-note-serve-computer-use-to-other-harnesses-as-an-mcp-server/alternatives-considered: - en: e7a241490db020b0 - zh: 4e4f178f25319432 + en: c5e6980def4cba5f + zh: dd491b391c4ee85d /agent-note-serve-computer-use-to-other-harnesses-as-an-mcp-server/consequences: en: ee913f0c1bcdcc2b zh: 49d2d1d92348c59a diff --git a/.agents/notes/implemented/architecture/2026-11-09-computer-use-mcp-server.md b/.agents/notes/implemented/architecture/2026-11-09-computer-use-mcp-server.md index ffa9ebe057..0cce260992 100644 --- a/.agents/notes/implemented/architecture/2026-11-09-computer-use-mcp-server.md +++ b/.agents/notes/implemented/architecture/2026-11-09-computer-use-mcp-server.md @@ -18,7 +18,7 @@ Two tools form the surface. `cua_run_code` is the Agent's DSH registration serve Consent has two modes. `DSH_CUA_CONSENT=allow` answers every approval question of the connection's Agent with its approving label for the session. The default `elicit` forwards each question to the client as a form elicitation whose enum is the question's labels. No Session event is added: the training side consumes MCP tool results, and the connected harness's transcript records calls; DSH retains nested `tool/ptc-dispatch` events for diagnosis. -The composition lists its dependency closure, twenty-five rows, instead of layering on `dsh-base`: no model adapter, prompt-side tool, telemetry, or session-management row loads, and a new service injection in the CUA or PTC packages fails the required startup entry loudly until the patch adds the row. Initialization needs no `dsh plugin` step, so the Python runtime wheel and offline training Hosts need no registry access. `--print-client-config codex|claude-code|json` renders the client entry for the exact installation. +The composition lists its dependency closure, twenty-five rows, instead of layering on `dsh-base`: no model adapter, prompt-side tool, telemetry, or session-management row loads, and a new service injection in the CUA or PTC packages fails the required startup entry loudly until the patch adds the row. Initialization needs no `dsh plugin` step, so the Python runtime wheel and offline training Hosts need no registry access. Client entries are documented in the README instead of generated. ## Alternatives considered @@ -40,6 +40,8 @@ The composition lists its dependency closure, twenty-five rows, instead of layer **The `cua` API reference inside the tool description.** Claude Code 2.1.309 forwards the first 4,096 characters of an MCP tool description and appends `… [truncated]`, measured on 2026-11-10 with a 20,000-character probe description; `dsh-mcp-client` forwards the same description intact. The reference is about 13,000 characters, so it travels in the first result of each environment, and the registration's 2,200-character description stays within the budget. +**A `--print-client-config codex|claude-code|json` option.** Rendering the exact command of an installation needs `node:sea` to tell a single-file executable from a script launch, and the browser worker image, which packs every optional bundle, registers no `node:sea`; the documented entries carry the same timeouts and output budget without that dependency. + ## Consequences Every installation carries the bundle and its optional macOS provider dependency; `verify-default-product-isolation` keeps it out of default templates. The required startup entry `cua-mcp` fails the profile loudly when the frontend cannot activate. Hosts without a provider list only `cua_reset`, and a `cua_run_code` call fails as `unknown tool`. Clients see state loss on process exit, `cua_reset`, or Agent disposal and recreate objects. Consent elicitation depends on the 2025 MCP request model; clients on the 2026-07-28 revision use `allow`. The tool description and the reference text in the first result are pinned by the profile's expected-output test and change with the installed CUA packages. A provider description longer than 4,096 characters reaches Claude Code models cut. diff --git a/.agents/notes/implemented/architecture/2026-11-09-computer-use-mcp-server.zh.md b/.agents/notes/implemented/architecture/2026-11-09-computer-use-mcp-server.zh.md index 26d1181be2..0511ad8034 100644 --- a/.agents/notes/implemented/architecture/2026-11-09-computer-use-mcp-server.zh.md +++ b/.agents/notes/implemented/architecture/2026-11-09-computer-use-mcp-server.zh.md @@ -18,7 +18,7 @@ Computer Use 的训练数据应来自多个 agent harness,而不只是 DSH 会 授权有两种模式。`DSH_CUA_CONSENT=allow` 以批准标签为本会话回答连接 Agent 的每个审批问题。默认的 `elicit` 把每个问题作为表单 elicitation 转发给客户端,枚举即问题的选项标签。不新增任何 Session 事件:训练侧只消费 MCP 工具结果,接入 harness 的 transcript 记录调用;DSH 保留嵌套的 `tool/ptc-dispatch` 事件以供诊断。 -组合列出自己的依赖闭包(25 行),而不是叠在 `dsh-base` 之上:不加载任何模型适配器、提示侧工具、遥测或会话管理行;CUA 或 PTC 包新增服务注入时,必需启动条目会大声失败,直到 patch 补上该行。初始化不需要 `dsh plugin` 步骤,因此 Python runtime wheel 和离线训练 Host 都不需要访问 registry。`--print-client-config codex|claude-code|json` 为当前安装渲染客户端配置项。 +组合列出自己的依赖闭包(25 行),而不是叠在 `dsh-base` 之上:不加载任何模型适配器、提示侧工具、遥测或会话管理行;CUA 或 PTC 包新增服务注入时,必需启动条目会大声失败,直到 patch 补上该行。初始化不需要 `dsh plugin` 步骤,因此 Python runtime wheel 和离线训练 Host 都不需要访问 registry。客户端配置项由 README 给出,而不是由程序生成。 ## 考虑过的替代方案 @@ -40,6 +40,8 @@ Computer Use 的训练数据应来自多个 agent harness,而不只是 DSH 会 **把 `cua` API 参考放进工具描述。** Claude Code 2.1.309 只转发 MCP 工具描述的前 4,096 个字符并追加 `… [truncated]`,2026-11-10 用 20,000 个字符的探针描述测得;`dsh-mcp-client` 原样转发同一描述。参考约 13,000 个字符,因此随每个环境的首个结果传递,注册项 2,200 个字符的描述留在预算之内。 +**`--print-client-config codex|claude-code|json` 选项。** 为当前安装渲染准确命令需要 `node:sea` 来区分单文件可执行程序与脚本启动,而打包全部可选组合包的浏览器 worker 镜像没有注册 `node:sea`;文档给出的配置项带有同样的超时与输出预算,不需要这项依赖。 + ## 后果 每个安装都携带该组合包及其可选的 macOS 提供方依赖;`verify-default-product-isolation` 让它留在默认模板之外。必需启动条目 `cua-mcp` 在前端无法激活时让 profile 大声失败。没有提供方的 Host 只列出 `cua_reset`,调用 `cua_run_code` 以 `unknown tool` 失败。客户端会在进程退出、`cua_reset` 或 Agent 销毁时看到状态丢失并重新创建对象。授权 elicitation 依赖 2025 版 MCP 请求模型;使用 2026-07-28 修订版的客户端改用 `allow`。工具描述与首个结果中的参考文本由 profile 的期望输出测试固定,并随已安装的 CUA 包变化。提供方描述超过 4,096 个字符时,Claude Code 的模型只看到被截断的部分。 diff --git a/apps/cli/tests/profiles/cua-mcp/cua-mcp.expected.e2e.ts b/apps/cli/tests/profiles/cua-mcp/cua-mcp.expected.e2e.ts index ff1abd660e..ef67c03d73 100644 --- a/apps/cli/tests/profiles/cua-mcp/cua-mcp.expected.e2e.ts +++ b/apps/cli/tests/profiles/cua-mcp/cua-mcp.expected.e2e.ts @@ -26,7 +26,7 @@ function textOf(block: CallResult['content'][number] | undefined): string { } describe.skipIf(!existsSync(bin))('cua-mcp profile', { retry: 0 }, () => { - it('initializes the declared profile on first start, prints client configuration, serves programs over stdio, and exits on EOF', async () => { + it('initializes the declared profile on first start, serves programs over stdio, and exits on EOF', async () => { const temporary = await mkdtemp(join(tmpdir(), 'dsh-cua-mcp-profile-')) const home = join(temporary, 'home') const workspace = join(temporary, 'workspace') @@ -39,23 +39,15 @@ describe.skipIf(!existsSync(bin))('cua-mcp profile', { retry: 0 }, () => { } clearAmbientProxyEnv(env) await execFileAsync(process.execPath, ['-e', 'require("node:fs").mkdirSync(process.argv[1], { recursive: true })', workspace]) - const options = { cwd: workspace, env, timeout: 120_000, maxBuffer: 4_000_000 } - - // The first start initializes the profile the shipped bundle declares, without pnpm or network access. - const printed = await execFileAsync(process.execPath, [bin, '--profile', 'cua-mcp', '--print-client-config', 'codex'], options) - const manifest = JSON.parse(await readFile(join(home, 'profiles', 'cua-mcp', 'package.json'), 'utf8')) as { dsh: { profile: { bundles: string[] } } } - expect(manifest.dsh.profile.bundles).toEqual(['@deepseek-ai/dsh-cua-mcp']) - const normalized = printed.stdout - .split(JSON.stringify(process.execPath).slice(1, -1)).join('{{node}}') - .split(JSON.stringify(bin).slice(1, -1)).join('{{bin}}') - .split(JSON.stringify(home).slice(1, -1)).join('{{home}}') - await expect(normalized).toMatchFileSnapshot('./expected/codex.toml') const probe = owned.probe = startProbe({ args: [bin, '--profile', 'cua-mcp', '--patch', fixturePatch], cwd: workspace, env }) const initialized = await probe.request('initialize', { protocolVersion: '2025-06-18', capabilities: {}, clientInfo: { name: 'cua-mcp-e2e', version: '1' }, }) as { serverInfo: { name: string; version: string }; instructions: string; capabilities: object } probe.notify('notifications/initialized') + // The first start initialized the profile the shipped bundle declares, without pnpm or network access. + const manifest = JSON.parse(await readFile(join(home, 'profiles', 'cua-mcp', 'package.json'), 'utf8')) as { dsh: { profile: { bundles: string[] } } } + expect(manifest.dsh.profile.bundles).toEqual(['@deepseek-ai/dsh-cua-mcp']) expect(initialized.serverInfo.name).toBe('dsh_cua') expect(initialized.capabilities).toMatchObject({ tools: { listChanged: false } }) await expect(`${initialized.instructions}\n`).toMatchFileSnapshot('./expected/instructions.txt') diff --git a/apps/cli/tests/profiles/cua-mcp/expected/codex.toml b/apps/cli/tests/profiles/cua-mcp/expected/codex.toml deleted file mode 100644 index a1613c52f7..0000000000 --- a/apps/cli/tests/profiles/cua-mcp/expected/codex.toml +++ /dev/null @@ -1,13 +0,0 @@ -# ~/.codex/config.toml — the first start initializes the profile and prepares the Computer Use helper -[mcp_servers.dsh_cua] -command = "{{node}}" -args = ["{{bin}}", "--profile", "cua-mcp"] -env = { DSH_HOME = "{{home}}", DSH_CUA_CONSENT = "allow" } -startup_timeout_sec = 120 -tool_timeout_sec = 600 -enabled_tools = ["cua_run_code", "cua_reset"] -omit_tools_from = ["code_mode", "deferred"] -# default_tools_approval_mode = "auto" - -[mcp_servers.dsh_cua.tools.cua_run_code] -output_token_limit = 25000 diff --git a/docs/config-catalog.md b/docs/config-catalog.md index 8e2e1fef69..9043bc4835 100644 --- a/docs/config-catalog.md +++ b/docs/config-catalog.md @@ -892,7 +892,7 @@ export interface Config { ## `@deepseek-ai/dsh-cua-mcp` - `inject`: `cmdlineArgs` · `appReady` · `appExit` · `profileContext` · `agents` · `agentPresets` · `tools` · `systemPrompt` · `attachments` -- `source`: [`packages/experimental/cua-mcp/src/index.ts:25`](../packages/experimental/cua-mcp/src/index.ts) +- `source`: [`packages/experimental/cua-mcp/src/index.ts:22`](../packages/experimental/cua-mcp/src/index.ts) ```ts config-catalog /** Connection policy configurable from the profile patch. */ diff --git a/docs/config-catalog.zh.md b/docs/config-catalog.zh.md index 5660ded32f..0b6be18d38 100644 --- a/docs/config-catalog.zh.md +++ b/docs/config-catalog.zh.md @@ -894,7 +894,7 @@ export interface Config { ## `@deepseek-ai/dsh-cua-mcp` - `inject`: `cmdlineArgs` · `appReady` · `appExit` · `profileContext` · `agents` · `agentPresets` · `tools` · `systemPrompt` · `attachments` -- `source`: [`packages/experimental/cua-mcp/src/index.ts:25`](../packages/experimental/cua-mcp/src/index.ts) +- `source`: [`packages/experimental/cua-mcp/src/index.ts:22`](../packages/experimental/cua-mcp/src/index.ts) ```ts config-catalog /** Connection policy configurable from the profile patch. */ diff --git a/docs/subsystems/computer-use.i18n.yaml b/docs/subsystems/computer-use.i18n.yaml index 8d644c6906..63a5a522ca 100644 --- a/docs/subsystems/computer-use.i18n.yaml +++ b/docs/subsystems/computer-use.i18n.yaml @@ -6,8 +6,8 @@ en: e02a2e4cc9970cba zh: 29aac6c0530a582f /computer-use/serve-computer-use-to-another-harness: - en: 5c932fde2a8839f4 - zh: 8b753a0e382f5941 + en: 6c703ed9a8f79a1d + zh: d722cbd3fe203840 /computer-use/choose-a-provider: en: fa2e0d7b41c0450b zh: af9a799711f901e6 diff --git a/docs/subsystems/computer-use.md b/docs/subsystems/computer-use.md index e2287cac7f..0b49d8ace8 100644 --- a/docs/subsystems/computer-use.md +++ b/docs/subsystems/computer-use.md @@ -21,7 +21,7 @@ The [shared object API](../../packages/experimental/cua/README.md) uses `connect ## Serve Computer Use to another harness -[Computer use MCP server](../../packages/experimental/cua-mcp/README.md) is a shipped optional bundle that composes the standalone `cua-mcp` profile; the first `dsh --profile cua-mcp` initializes it. `dsh --profile cua-mcp` serves `cua_run_code` and `cua_reset` to one MCP client such as Codex or Claude Code; each connection owns one Agent whose programs retain application and window objects, and consent is granted unattended or forwarded to the client as an elicitation. `dsh --profile cua-mcp --print-client-config codex|claude-code|json` prints the client configuration. The profile runs no model turn and records no root tool calls in its Session. +[Computer use MCP server](../../packages/experimental/cua-mcp/README.md) is a shipped optional bundle that composes the standalone `cua-mcp` profile; the first `dsh --profile cua-mcp` initializes it. `dsh --profile cua-mcp` serves `cua_run_code` and `cua_reset` to one MCP client such as Codex or Claude Code; each connection owns one Agent whose programs retain application and window objects, and consent is granted unattended or forwarded to the client as an elicitation. The profile runs no model turn and records no root tool calls in its Session. ## Choose a provider diff --git a/docs/subsystems/computer-use.zh.md b/docs/subsystems/computer-use.zh.md index 7ff9771273..f3578735a3 100644 --- a/docs/subsystems/computer-use.zh.md +++ b/docs/subsystems/computer-use.zh.md @@ -21,7 +21,7 @@ CUA provider 通过 `ctx.cuaAccess` 提供系统权限状态、用户主动申 ## 向其他 harness 提供 Computer Use -[Computer Use MCP 服务器](../../packages/experimental/cua-mcp/README.zh.md)是随安装提供的可选组合包,独立组成 `cua-mcp` profile;首次 `dsh --profile cua-mcp` 即初始化该 profile。`dsh --profile cua-mcp` 向一个 MCP 客户端(如 Codex 或 Claude Code)提供 `cua_run_code` 和 `cua_reset`;每个连接拥有一个 Agent,其程序保留应用与窗口对象,授权可无人值守放行或作为 elicitation 转发给客户端。`dsh --profile cua-mcp --print-client-config codex|claude-code|json` 打印客户端配置。该 profile 不运行模型回合,其 Session 中不记录根工具调用。 +[Computer Use MCP 服务器](../../packages/experimental/cua-mcp/README.zh.md)是随安装提供的可选组合包,独立组成 `cua-mcp` profile;首次 `dsh --profile cua-mcp` 即初始化该 profile。`dsh --profile cua-mcp` 向一个 MCP 客户端(如 Codex 或 Claude Code)提供 `cua_run_code` 和 `cua_reset`;每个连接拥有一个 Agent,其程序保留应用与窗口对象,授权可无人值守放行或作为 elicitation 转发给客户端。该 profile 不运行模型回合,其 Session 中不记录根工具调用。 ## 选择提供方 diff --git a/packages/experimental/cua-mcp/README.i18n.yaml b/packages/experimental/cua-mcp/README.i18n.yaml index 63ea113400..08708b9525 100644 --- a/packages/experimental/cua-mcp/README.i18n.yaml +++ b/packages/experimental/cua-mcp/README.i18n.yaml @@ -21,8 +21,8 @@ en: 0ff492831b5835e2 zh: d06e805ca82520d0 /deepseek-ai-dsh-cua-mcp/use-this-package/connect-a-client: - en: b4db34975dce7ea2 - zh: ae55298bfd3e1c3a + en: 65cb4b0fb5cb2119 + zh: 98bb700cf459d8b2 /deepseek-ai-dsh-cua-mcp/use-this-package/what-you-get: en: 6ac4dc23b5f775c0 zh: 255f4dee8d11be7e @@ -30,8 +30,8 @@ en: 8996e07a265596a5 zh: 8cf79827c51f2a2d /deepseek-ai-dsh-cua-mcp/understand-the-implementation: - en: a5963da0da0412a3 - zh: 2a54e1c4af66a694 + en: 1af8cb5abbd0a8a5 + zh: 30605a718f3fd789 /deepseek-ai-dsh-cua-mcp/further-exploration: en: 0328a9b46caad949 zh: a20731d490d5412a diff --git a/packages/experimental/cua-mcp/README.md b/packages/experimental/cua-mcp/README.md index d7f281d9cf..5fdf3bb310 100644 --- a/packages/experimental/cua-mcp/README.md +++ b/packages/experimental/cua-mcp/README.md @@ -38,14 +38,31 @@ command = [*resolve_bundled_launch_args(), "--profile", "cua-mcp"] # the MCP st ### Connect a client -`dsh --profile cua-mcp` is the stdio command. It prints its own help with `--help`, and `--print-client-config codex|claude-code|json` prints a ready configuration for this installation and Harness home: a `~/.codex/config.toml` fragment, a `claude mcp add-json dsh_cua` command, or a generic `mcpServers` document. Each embeds the absolute executable, `DSH_HOME`, and the current `DSH_CUA_CONSENT`. The Codex fragment sets `startup_timeout_sec = 120` for first-run helper preparation, `tool_timeout_sec = 600` to match the default program maximum, exposes both tools directly instead of through tool search, and raises the `cua_run_code` output budget to 25,000 tokens. Codex forwards elicitations only with `approval_policy.granular.mcp_elicitations = true`. DSH's own `dsh-mcp-client` declares no elicitation capability, and Claude Code 2.1 print mode declines elicitations, so unattended runs through those clients need `DSH_CUA_CONSENT=allow`. +`dsh --profile cua-mcp` is the stdio command, and `--help` prints its own help. A client entry names the installation's `dsh` executable by absolute path, passes `--profile cua-mcp`, sets `DSH_HOME` when the server should use a Harness home other than the default, and sets `DSH_CUA_CONSENT` for the consent mode; from a source checkout the command is `node` with `/apps/cli/lib/bin.js` as its first argument, after `pnpm run build`. For Codex, add to `~/.codex/config.toml`: -```sh -dsh --profile cua-mcp --print-client-config codex >> ~/.codex/config.toml -dsh --profile cua-mcp --print-client-config claude-code | sh +```toml +[mcp_servers.dsh_cua] +command = "/absolute/path/to/dsh" +args = ["--profile", "cua-mcp"] +env = { DSH_HOME = "/absolute/path/to/dsh-home", DSH_CUA_CONSENT = "elicit" } +startup_timeout_sec = 120 +tool_timeout_sec = 600 +enabled_tools = ["cua_run_code", "cua_reset"] +omit_tools_from = ["code_mode", "deferred"] + +[mcp_servers.dsh_cua.tools.cua_run_code] +output_token_limit = 25000 ``` -On macOS the profile prepares the signed Computer Use helper on first start and needs Accessibility and Screen Recording permissions for it; the [macOS provider](../cua-macos/README.md) owns that setup. This profile has no permission page, so grant both in System Settings → Privacy & Security by adding the helper application: a source checkout prepares `DSH Computer Use Dev.app` under `packages/experimental/cua-macos/native/.build/prepared///`, where `current.json` names the selected build; an installed package ships `DSH Computer Use.app`. Until both are granted, `await cua.getCapabilities()` reports the missing flags and application operations fail; a locked desktop fails them with `SESSION_LOCKED`. On other Hosts the profile starts without a provider, and both tools return an error naming the missing provider. +`startup_timeout_sec = 120` covers first-run helper preparation, `tool_timeout_sec = 600` matches the default program maximum, `enabled_tools` with `omit_tools_from` exposes both tools directly instead of through tool search, and `output_token_limit` raises the `cua_run_code` output budget to 25,000 tokens. For Claude Code, register the same entry with a ten-minute tool timeout: + +```sh +claude mcp add-json dsh_cua '{"type":"stdio","command":"/absolute/path/to/dsh","args":["--profile","cua-mcp"],"env":{"DSH_HOME":"/absolute/path/to/dsh-home","DSH_CUA_CONSENT":"elicit"},"timeout":600000,"alwaysLoad":true}' +``` + +Other clients take the same `command`, `args`, and `env` under `mcpServers`. Codex forwards elicitations only with `approval_policy.granular.mcp_elicitations = true`. DSH's own `dsh-mcp-client` declares no elicitation capability, and Claude Code 2.1 print mode declines elicitations, so unattended runs through those clients need `DSH_CUA_CONSENT=allow`. + +On macOS the profile prepares the signed Computer Use helper on first start and needs Accessibility and Screen Recording permissions for it; the [macOS provider](../cua-macos/README.md) owns that setup. This profile has no permission page, so grant both in System Settings → Privacy & Security by adding the helper application: a source checkout prepares `DSH Computer Use Dev.app` under the macOS provider package's `native/.build/prepared///` directory, where `current.json` names the selected build; an installed package ships `DSH Computer Use.app`. Until both are granted, `await cua.getCapabilities()` reports the missing flags and application operations fail; a locked desktop fails them with `SESSION_LOCKED`. On other Hosts the profile starts without a provider, and both tools return an error naming the missing provider. ### What you get @@ -78,7 +95,7 @@ The patch also mounts the provider with `screenshotTarget: { longEdge: 2048, max The [patch](cordis.patch.yml) composes the whole profile over the empty root: sessions with JSONL persistence and projections, attachments, storage for application grants, the subprocess, sandbox, approval, and filesystem seams program processes run under, tools with the native executor, the system prompt, user questions, the llm hub without an adapter, the Agent registry with the agent-loop factory, the preset registry with the empty default preset, the `computer-use` registry, the macOS provider row disabled off Darwin, and this frontend. `dsh.bundle.profile` names the `cua-mcp` profile, which app-boot initializes from this single bundle on first start. The frontend parses the invocation with `parseCmdline`, binds stdin EOF to the launcher's bounded shutdown, and connects the official MCP server to a stdio transport after the launcher commits readiness. `cua-mcp` is a required startup entry, so a frontend that cannot activate stops the profile. -[`server.ts`](src/server.ts) serves both tools through the protocol server's low-level `tools/list` and `tools/call` handlers: the listing projects the Agent's `cua_run_code` registration, checked against the protocol's tool type, beside the hand-written `cua_reset`. The connection's Agent mounts the registry's default preset and records the launch directory. A `cua_run_code` call runs through `ctx.tools.execute` inside `ctx.agents.withInitiator` with the Agent and the request signal and no model step, so the Session log carries nested `tool/ptc-dispatch` events but no root `tool/call`; [`projection.ts`](src/projection.ts) renders the result and its deferred screenshot contexts, reading each image through `ctx.cuaPrograms.screenshotRequestTarget`. `cua_reset` calls `ctx.cuaPrograms.reset`. [`consent.ts`](src/consent.ts) is the `user-questions/request` answerer for that Agent; [`client-config.ts`](src/client-config.ts) renders the client snippets. +[`server.ts`](src/server.ts) serves both tools through the protocol server's low-level `tools/list` and `tools/call` handlers: the listing projects the Agent's `cua_run_code` registration, checked against the protocol's tool type, beside the hand-written `cua_reset`. The connection's Agent mounts the registry's default preset and records the launch directory. A `cua_run_code` call runs through `ctx.tools.execute` inside `ctx.agents.withInitiator` with the Agent and the request signal and no model step, so the Session log carries nested `tool/ptc-dispatch` events but no root `tool/call`; [`projection.ts`](src/projection.ts) renders the result and its deferred screenshot contexts, reading each image through `ctx.cuaPrograms.screenshotRequestTarget`. `cua_reset` calls `ctx.cuaPrograms.reset`. [`consent.ts`](src/consent.ts) is the `user-questions/request` answerer for that Agent. diff --git a/packages/experimental/cua-mcp/README.zh.md b/packages/experimental/cua-mcp/README.zh.md index d2646d275d..c0a6c2843a 100644 --- a/packages/experimental/cua-mcp/README.zh.md +++ b/packages/experimental/cua-mcp/README.zh.md @@ -38,14 +38,31 @@ command = [*resolve_bundled_launch_args(), "--profile", "cua-mcp"] # the MCP st ### 接入客户端 -`dsh --profile cua-mcp` 就是 stdio 命令。`--help` 打印它自己的帮助;`--print-client-config codex|claude-code|json` 为当前安装和 Harness home 打印可直接使用的配置:一段 `~/.codex/config.toml` 片段、一条 `claude mcp add-json dsh_cua` 命令,或一份通用 `mcpServers` 文档。三者都嵌入绝对可执行路径、`DSH_HOME` 与当前 `DSH_CUA_CONSENT`。Codex 片段把 `startup_timeout_sec = 120` 留给首次 helper 准备,用 `tool_timeout_sec = 600` 对齐默认程序上限,让两个工具直接暴露而不进入工具搜索,并把 `cua_run_code` 的输出预算提高到 25,000 token。Codex 只有在 `approval_policy.granular.mcp_elicitations = true` 时才转发 elicitation。DSH 自己的 `dsh-mcp-client` 未声明 elicitation 能力,Claude Code 2.1 的 print 模式会拒绝 elicitation,因此经这两类客户端的无人值守运行需要 `DSH_CUA_CONSENT=allow`。 +`dsh --profile cua-mcp` 就是 stdio 命令,`--help` 打印它自己的帮助。客户端配置项以绝对路径指向安装的 `dsh` 可执行程序,传入 `--profile cua-mcp`,在服务器应使用非默认 Harness home 时设置 `DSH_HOME`,并用 `DSH_CUA_CONSENT` 设置授权模式;源码检出在 `pnpm run build` 之后以 `node` 为命令、`/apps/cli/lib/bin.js` 为首个参数。Codex 在 `~/.codex/config.toml` 中加入: -```sh -dsh --profile cua-mcp --print-client-config codex >> ~/.codex/config.toml -dsh --profile cua-mcp --print-client-config claude-code | sh +```toml +[mcp_servers.dsh_cua] +command = "/absolute/path/to/dsh" +args = ["--profile", "cua-mcp"] +env = { DSH_HOME = "/absolute/path/to/dsh-home", DSH_CUA_CONSENT = "elicit" } +startup_timeout_sec = 120 +tool_timeout_sec = 600 +enabled_tools = ["cua_run_code", "cua_reset"] +omit_tools_from = ["code_mode", "deferred"] + +[mcp_servers.dsh_cua.tools.cua_run_code] +output_token_limit = 25000 ``` -在 macOS 上,profile 首次启动时准备已签名的 Computer Use helper,并需要为其授予辅助功能与屏幕录制权限;[macOS 提供方](../cua-macos/README.zh.md)负责这部分设置。本 profile 没有权限页面,因此要在「系统设置 → 隐私与安全性」中添加 helper 应用来授予这两项权限:源码检出在 `packages/experimental/cua-macos/native/.build/prepared///` 下准备 `DSH Computer Use Dev.app`,其中 `current.json` 记录当前选中的构建;已安装的包附带 `DSH Computer Use.app`。两项权限都授予之前,`await cua.getCapabilities()` 会报告缺失的标志,应用操作会失败;桌面处于锁定状态时这些操作以 `SESSION_LOCKED` 失败。在其他 Host 上 profile 没有提供方也能启动,两个工具都返回指出缺少提供方的错误。 +`startup_timeout_sec = 120` 留给首次 helper 准备,`tool_timeout_sec = 600` 对齐默认程序上限,`enabled_tools` 配合 `omit_tools_from` 让两个工具直接暴露而不进入工具搜索,`output_token_limit` 把 `cua_run_code` 的输出预算提高到 25,000 token。Claude Code 以十分钟工具超时注册同一配置项: + +```sh +claude mcp add-json dsh_cua '{"type":"stdio","command":"/absolute/path/to/dsh","args":["--profile","cua-mcp"],"env":{"DSH_HOME":"/absolute/path/to/dsh-home","DSH_CUA_CONSENT":"elicit"},"timeout":600000,"alwaysLoad":true}' +``` + +其他客户端在 `mcpServers` 下使用同样的 `command`、`args` 与 `env`。Codex 只有在 `approval_policy.granular.mcp_elicitations = true` 时才转发 elicitation。DSH 自己的 `dsh-mcp-client` 未声明 elicitation 能力,Claude Code 2.1 的 print 模式会拒绝 elicitation,因此经这两类客户端的无人值守运行需要 `DSH_CUA_CONSENT=allow`。 + +在 macOS 上,profile 首次启动时准备已签名的 Computer Use helper,并需要为其授予辅助功能与屏幕录制权限;[macOS 提供方](../cua-macos/README.zh.md)负责这部分设置。本 profile 没有权限页面,因此要在「系统设置 → 隐私与安全性」中添加 helper 应用来授予这两项权限:源码检出在 macOS 提供方包的 `native/.build/prepared///` 目录下准备 `DSH Computer Use Dev.app`,其中 `current.json` 记录当前选中的构建;已安装的包附带 `DSH Computer Use.app`。两项权限都授予之前,`await cua.getCapabilities()` 会报告缺失的标志,应用操作会失败;桌面处于锁定状态时这些操作以 `SESSION_LOCKED` 失败。在其他 Host 上 profile 没有提供方也能启动,两个工具都返回指出缺少提供方的错误。 ### 你会得到什么 @@ -78,7 +95,7 @@ patch 还以 `screenshotTarget: { longEdge: 2048, maxBytes: 2097152 }` 挂载提 [patch](cordis.patch.yml) 在空根上组成整个 profile:带 JSONL 持久化与投影的会话、附件、保存应用授权的存储、程序进程所依赖的子进程、沙箱、审批与文件系统 seam、带原生执行器的工具、系统提示、用户提问、不挂适配器的 llm hub、带 agent-loop 工厂的 Agent 注册表、带空默认 preset 的 preset 注册表、`computer-use` 注册表、在非 Darwin 上禁用的 macOS 提供方行,以及本前端。`dsh.bundle.profile` 声明 `cua-mcp` profile,app-boot 在首次启动时用这一个组合包初始化它。前端用 `parseCmdline` 解析调用,把 stdin EOF 绑定到启动器的有界关闭,并在启动器提交就绪后把官方 MCP 服务器连接到 stdio 传输。`cua-mcp` 是启动必需条目,前端无法激活时 profile 停止启动。 -[`server.ts`](src/server.ts) 通过协议服务器的低层 `tools/list` 与 `tools/call` handler 提供两个工具:列表把该 Agent 的 `cua_run_code` 注册项按协议的工具类型校验后投影出来,与手写的 `cua_reset` 并列。连接的 Agent 挂载注册表的默认 preset 并记录启动目录。`cua_run_code` 调用在 `ctx.agents.withInitiator` 内带着 Agent 和请求 signal、不经模型步骤地通过 `ctx.tools.execute` 运行,因此 Session 日志只有嵌套的 `tool/ptc-dispatch` 事件而没有根 `tool/call`;[`projection.ts`](src/projection.ts) 渲染结果及其延后的截图上下文,并通过 `ctx.cuaPrograms.screenshotRequestTarget` 读取每张图片。`cua_reset` 调用 `ctx.cuaPrograms.reset`。[`consent.ts`](src/consent.ts) 是该 Agent 的 `user-questions/request` 应答者;[`client-config.ts`](src/client-config.ts) 渲染客户端片段。 +[`server.ts`](src/server.ts) 通过协议服务器的低层 `tools/list` 与 `tools/call` handler 提供两个工具:列表把该 Agent 的 `cua_run_code` 注册项按协议的工具类型校验后投影出来,与手写的 `cua_reset` 并列。连接的 Agent 挂载注册表的默认 preset 并记录启动目录。`cua_run_code` 调用在 `ctx.agents.withInitiator` 内带着 Agent 和请求 signal、不经模型步骤地通过 `ctx.tools.execute` 运行,因此 Session 日志只有嵌套的 `tool/ptc-dispatch` 事件而没有根 `tool/call`;[`projection.ts`](src/projection.ts) 渲染结果及其延后的截图上下文,并通过 `ctx.cuaPrograms.screenshotRequestTarget` 读取每张图片。`cua_reset` 调用 `ctx.cuaPrograms.reset`。[`consent.ts`](src/consent.ts) 是该 Agent 的 `user-questions/request` 应答者。 diff --git a/packages/experimental/cua-mcp/src/client-config.ts b/packages/experimental/cua-mcp/src/client-config.ts deleted file mode 100644 index a16e2542c9..0000000000 --- a/packages/experimental/cua-mcp/src/client-config.ts +++ /dev/null @@ -1,115 +0,0 @@ -/** Client configuration snippets for the Computer Use MCP server. @module */ -import type { ProfileContext } from '@deepseek-ai/dsh-app-boot' -import type { ConsentMode } from './consent.ts' - -/** Clients with a generated configuration. */ -export type ClientConfigTarget = 'codex' | 'claude-code' | 'json' - -/** Every client target, in the order help lists them. */ -export const CLIENT_CONFIG_TARGETS: readonly ClientConfigTarget[] = ['codex', 'claude-code', 'json'] - -/** MCP server name clients address; external tool names become `mcp__dsh_cua__cua_run_code` in Claude Code. */ -export const MCP_SERVER_NAME = 'dsh_cua' - -/** The exact stdio command a client runs to start this profile. */ -export interface ClientLaunch { - /** Absolute executable path. */ - readonly command: string - /** Arguments in order, ending with the profile selection. */ - readonly args: readonly string[] - /** Environment the client passes to the process. */ - readonly env: Readonly> -} - -/** The process facts a generated client configuration embeds. */ -export interface LaunchFacts { - readonly execPath: string - readonly execArgv: readonly string[] - readonly argv: readonly string[] - /** Whether this process is a single-file executable, which takes no script argument. */ - readonly sea: boolean -} - -/** - * Resolve the stdio command a client runs to reach this exact installation and profile. - * @param facts - Current process executable, Node options, and arguments. - * @param profile - Launched profile. - * @param consent - Consent mode the generated environment pins. - * @returns Absolute command, arguments, and environment. - * @throws Error when a script-launched process has no script argument. - */ -export function clientLaunch(facts: LaunchFacts, profile: Pick, consent: ConsentMode): ClientLaunch { - const selection = ['--profile', profile.name] - const script = facts.argv[1] - if (!facts.sea && script === undefined) throw new Error('cua-mcp: the launching script is unknown, so no client command can be generated') - return { - command: facts.execPath, - args: facts.sea ? selection : [...facts.execArgv, script as string, ...selection], - env: { DSH_HOME: profile.home, DSH_CUA_CONSENT: consent }, - } -} - -/** Per-call limit a client should allow; the default `cua_run_code` maximum timeout is ten minutes. */ -const TOOL_TIMEOUT_SECONDS = 600 -/** Startup allowance covering first-run native helper preparation on macOS. */ -const STARTUP_TIMEOUT_SECONDS = 120 -/** Output budget matching the Claude Code default and the Codex Computer Use plugin. */ -const OUTPUT_TOKEN_LIMIT = 25_000 - -function tomlString(value: string): string { - return JSON.stringify(value) -} - -function tomlInlineTable(values: Readonly>): string { - return `{ ${Object.entries(values).map(([key, value]) => `${key} = ${tomlString(value)}`).join(', ')} }` -} - -/** - * Render the configuration an MCP client needs to run this server. - * @param target - Client whose configuration format is rendered. - * @param launch - Resolved stdio command of this installation and profile. - * @returns Complete text ending with one newline: a TOML fragment for Codex, a `claude mcp add-json` command - * for Claude Code, or a generic `mcpServers` JSON document. - */ -export function renderClientConfig(target: ClientConfigTarget, launch: ClientLaunch): string { - const entry = { - type: 'stdio' as const, - command: launch.command, - args: [...launch.args], - env: { ...launch.env }, - } - switch (target) { - case 'codex': - return [ - '# ~/.codex/config.toml — the first start initializes the profile and prepares the Computer Use helper', - `[mcp_servers.${MCP_SERVER_NAME}]`, - `command = ${tomlString(launch.command)}`, - `args = [${launch.args.map(tomlString).join(', ')}]`, - `env = ${tomlInlineTable(launch.env)}`, - `startup_timeout_sec = ${String(STARTUP_TIMEOUT_SECONDS)}`, - `tool_timeout_sec = ${String(TOOL_TIMEOUT_SECONDS)}`, - 'enabled_tools = ["cua_run_code", "cua_reset"]', - 'omit_tools_from = ["code_mode", "deferred"]', - '# default_tools_approval_mode = "auto"', - '', - `[mcp_servers.${MCP_SERVER_NAME}.tools.cua_run_code]`, - `output_token_limit = ${String(OUTPUT_TOKEN_LIMIT)}`, - '', - ].join('\n') - case 'claude-code': { - const json = JSON.stringify({ ...entry, timeout: TOOL_TIMEOUT_SECONDS * 1000, alwaysLoad: true }) - return [ - `claude mcp add-json ${MCP_SERVER_NAME} '${json.replaceAll("'", String.raw`'\''`)}'`, - '', - ].join('\n') - } - case 'json': - return `${JSON.stringify({ mcpServers: { [MCP_SERVER_NAME]: entry } }, null, 2)}\n` - default: - return assertNever(target) - } -} - -function assertNever(value: never): never { - throw new Error(`unknown client configuration target ${String(value)}`) -} diff --git a/packages/experimental/cua-mcp/src/index.ts b/packages/experimental/cua-mcp/src/index.ts index 5e983a341f..5520338da2 100644 --- a/packages/experimental/cua-mcp/src/index.ts +++ b/packages/experimental/cua-mcp/src/index.ts @@ -1,18 +1,15 @@ /** * The Computer Use MCP stdio application: the standalone cua-mcp profile's frontend, serving the Agent's - * `cua_run_code` registration and `cua_reset` to an external MCP client. Help and `--print-client-config` exit - * without claiming stdio; a served connection owns one Agent, created before the transport opens, until the client - * closes stdin. + * `cua_run_code` registration and `cua_reset` to an external MCP client. Help exits without claiming stdio; a + * served connection owns one Agent, created before the transport opens, until the client closes stdin. * @module @deepseek-ai/dsh-cua-mcp */ -import { isSea } from 'node:sea' import type { Context } from '@deepseek-ai/cordis' import Schema from '@deepseek-ai/schemastery' import type {} from '@deepseek-ai/dsh-app-boot' -import { exitOnStdinEnd, internals, parseCmdline } from '@deepseek-ai/dsh-cmdline' +import { exitOnStdinEnd, parseCmdline } from '@deepseek-ai/dsh-cmdline' import { StdioServerTransport } from '@modelcontextprotocol/server/stdio' -import { Command, Option } from 'commander' -import { CLIENT_CONFIG_TARGETS, clientLaunch, renderClientConfig, type ClientConfigTarget, type LaunchFacts } from './client-config.ts' +import { Command } from 'commander' import type { ConsentMode } from './consent.ts' import { createCuaMcpServer, type CuaMcpServer } from './server.ts' @@ -36,8 +33,8 @@ export const Config: Schema, Config> = Schema.object({ }) /** - * Accept the profile invocation, print a client configuration on request, or serve MCP over stdio once the - * launcher commits readiness. Stdin EOF ends the process through the launcher's bounded shutdown. + * Accept the profile invocation and serve MCP over stdio once the launcher commits readiness; help exits before + * anything starts. Stdin EOF ends the process through the launcher's bounded shutdown. * @param ctx - Profile context carrying the command line, readiness, exit request, and profile identity. * @param config - Validated consent mode. * @throws Error when the plugin runs outside the dsh profile launcher. @@ -50,26 +47,15 @@ export function apply(ctx: Context, config: Config): void { const commandName = `dsh --profile ${profile.name}` const program = new Command(commandName) .description('Serve DeepSeek Harness Computer Use to an MCP client over stdio.') - .addOption(new Option('--print-client-config ', 'print the MCP client configuration for this installation and exit') - .choices([...CLIENT_CONFIG_TARGETS])) .addHelpText('after', ` Examples: - ${commandName} serve one MCP client until it closes stdin - ${commandName} --print-client-config codex print a ~/.codex/config.toml fragment - DSH_CUA_CONSENT=allow ${commandName} grant application access without a human + ${commandName} serve one MCP client until it closes stdin + DSH_CUA_CONSENT=allow ${commandName} grant application access without a human `) - let accepted: { print: ClientConfigTarget | undefined } | undefined - program.action(() => { - accepted = { print: program.opts<{ printClientConfig?: ClientConfigTarget }>().printClientConfig } - }) + let accepted: true | undefined + program.action(() => { accepted = true }) parseCmdline(ctx, program) if (accepted === undefined) return - if (accepted.print !== undefined) { - const facts: LaunchFacts = { execPath: process.execPath, execArgv: process.execArgv, argv: process.argv, sea: isSea() } - internals.stdout.write(renderClientConfig(accepted.print, clientLaunch(facts, profile, config.consent))) - exit(0) - return - } exitOnStdinEnd(ctx, 'cua-mcp: stdin') ctx.effect(() => { const lifetime = new AbortController() diff --git a/packages/experimental/cua-mcp/src/server.ts b/packages/experimental/cua-mcp/src/server.ts index ad40796bc7..17d45e6b94 100644 --- a/packages/experimental/cua-mcp/src/server.ts +++ b/packages/experimental/cua-mcp/src/server.ts @@ -12,7 +12,6 @@ import { SessionId } from '@deepseek-ai/dsh-session' import type {} from '@deepseek-ai/dsh-system-prompt' import type { ToolDefinition } from '@deepseek-ai/dsh-tools' import { Server, specTypeSchemas, type CallToolResult, type Tool } from '@modelcontextprotocol/server' -import { MCP_SERVER_NAME } from './client-config.ts' import { createConsentAnswerer, type ConsentMode, type ElicitationClient } from './consent.ts' import { projectToolResult } from './projection.ts' @@ -41,6 +40,9 @@ export interface CuaMcpServer { dispose(): Promise } +/** MCP server name clients address; external tool names become `mcp__dsh_cua__cua_run_code` in Claude Code. */ +const MCP_SERVER_NAME = 'dsh_cua' + /** The DSH tool whose registration for the connection's Agent is served as the MCP tool of the same name. */ const PROGRAM_TOOL = 'cua_run_code' diff --git a/packages/experimental/cua-mcp/tests/client-config.spec.ts b/packages/experimental/cua-mcp/tests/client-config.spec.ts deleted file mode 100644 index 5d72e99f28..0000000000 --- a/packages/experimental/cua-mcp/tests/client-config.spec.ts +++ /dev/null @@ -1,71 +0,0 @@ -/** Generated client configurations embed the exact launch command and quote every value. */ -import { describe, expect, it } from 'vitest' -import { CLIENT_CONFIG_TARGETS, MCP_SERVER_NAME, clientLaunch, renderClientConfig, type ClientLaunch } from '../src/client-config.ts' - -const launch: ClientLaunch = { - command: '/opt/node/bin/node', - args: ['/opt/dsh/lib/bin.js', '--profile', 'cua-mcp'], - env: { DSH_HOME: "/Users/o'neil/.dsh", DSH_CUA_CONSENT: 'elicit' }, -} - -describe('client configuration', () => { - it('renders a Codex TOML fragment with the launch command and limits', () => { - const toml = renderClientConfig('codex', launch) - expect(toml).toMatchInlineSnapshot(` - "# ~/.codex/config.toml — the first start initializes the profile and prepares the Computer Use helper - [mcp_servers.dsh_cua] - command = "/opt/node/bin/node" - args = ["/opt/dsh/lib/bin.js", "--profile", "cua-mcp"] - env = { DSH_HOME = "/Users/o'neil/.dsh", DSH_CUA_CONSENT = "elicit" } - startup_timeout_sec = 120 - tool_timeout_sec = 600 - enabled_tools = ["cua_run_code", "cua_reset"] - omit_tools_from = ["code_mode", "deferred"] - # default_tools_approval_mode = "auto" - - [mcp_servers.dsh_cua.tools.cua_run_code] - output_token_limit = 25000 - " - `) - }) - - it('renders a shell-safe claude mcp add-json command with the stdio entry', () => { - const command = renderClientConfig('claude-code', launch) - const lines = command.trimEnd().split('\n') - expect(lines).toHaveLength(1) - const match = /^claude mcp add-json dsh_cua '(.*)'$/.exec(lines[0] ?? '') - if (match === null) throw new Error(`unexpected command line: ${String(lines[0])}`) - // The single-quoted shell argument closes, escapes, and reopens around the apostrophe in the home path. - const shellValue = match[1]!.replaceAll(String.raw`'\''`, "'") - expect(JSON.parse(shellValue)).toEqual({ - type: 'stdio', command: launch.command, args: launch.args, env: launch.env, timeout: 600_000, alwaysLoad: true, - }) - }) - - it('renders a generic mcpServers document without comments', () => { - expect(JSON.parse(renderClientConfig('json', launch))).toEqual({ - mcpServers: { [MCP_SERVER_NAME]: { type: 'stdio', command: launch.command, args: launch.args, env: launch.env } }, - }) - expect(CLIENT_CONFIG_TARGETS).toEqual(['codex', 'claude-code', 'json']) - expect(() => renderClientConfig('cursor' as 'json', launch)).toThrow('unknown client configuration target cursor') - }) -}) - -describe('launch resolution', () => { - const profile = { name: 'cua-mcp', home: '/home/me/.dsh' } - - it('embeds the Node executable, its options, and the launching script for a script launch', () => { - expect(clientLaunch({ execPath: '/opt/node', execArgv: ['--import', 'tsx/esm'], argv: ['/opt/node', '/repo/apps/cli/src/bin.ts', 'cua-mcp'], sea: false }, profile, 'allow')) - .toEqual({ - command: '/opt/node', args: ['--import', 'tsx/esm', '/repo/apps/cli/src/bin.ts', '--profile', 'cua-mcp'], - env: { DSH_HOME: '/home/me/.dsh', DSH_CUA_CONSENT: 'allow' }, - }) - }) - - it('embeds only the executable for a single-file runtime and rejects a script launch without a script', () => { - expect(clientLaunch({ execPath: '/opt/dsh-runtime', execArgv: [], argv: ['/opt/dsh-runtime', '--profile', 'cua-mcp'], sea: true }, profile, 'elicit').args) - .toEqual(['--profile', 'cua-mcp']) - expect(() => clientLaunch({ execPath: '/opt/node', execArgv: [], argv: ['/opt/node'], sea: false }, profile, 'elicit')) - .toThrow('launching script is unknown') - }) -}) diff --git a/packages/experimental/cua-mcp/tests/startup.spec.ts b/packages/experimental/cua-mcp/tests/startup.spec.ts index d9a5fc81d5..33d1cc62d4 100644 --- a/packages/experimental/cua-mcp/tests/startup.spec.ts +++ b/packages/experimental/cua-mcp/tests/startup.spec.ts @@ -1,4 +1,4 @@ -/** The frontend parses its invocation, prints client configuration, and serves MCP only after readiness. */ +/** The frontend parses its invocation and serves MCP only after readiness. */ import { EventEmitter } from 'node:events' import { Context } from '@deepseek-ai/cordis' import { internals, provideCmdline } from '@deepseek-ai/dsh-cmdline' @@ -12,7 +12,6 @@ vi.mock('../src/server.ts', async original => ({ ...await original(), createCuaMcpServer: vi.fn(), })) vi.mock('@modelcontextprotocol/server/stdio', () => ({ StdioServerTransport: vi.fn() })) -vi.mock('node:sea', () => ({ isSea: () => false })) /** Controllable stdin for one invocation. */ class TestStdin extends EventEmitter { @@ -99,27 +98,13 @@ describe('Computer Use MCP startup', () => { expect(dispose).toHaveBeenCalledOnce() }) - it('prints client configuration and exits without claiming stdin or constructing a server', async () => { - const { exit, stdout, ready, stdin } = await boot(['--print-client-config', 'json']) - const document = JSON.parse(stdout.join('')) as { mcpServers: Record }> } - expect(document.mcpServers.dsh_cua).toEqual({ - type: 'stdio', command: process.execPath, args: [...process.execArgv, process.argv[1], '--profile', 'cua-mcp'], - env: { DSH_HOME: '/home/me/.dsh', DSH_CUA_CONSENT: 'elicit' }, - }) - expect(exit).toHaveBeenCalledWith(0) - expect(createCuaMcpServer).not.toHaveBeenCalled() - ready() - stdin.end() - expect(exit).toHaveBeenCalledTimes(1) - }) - - it('rejects an unknown client and documents help without starting anything', async () => { - const unknown = await boot(['--print-client-config', 'cursor']) + it('rejects an unknown option and documents help without starting anything', async () => { + const unknown = await boot(['--print-client-config', 'json']) expect(unknown.exit).toHaveBeenCalledWith(1) - expect(unknown.stderr.join('')).toContain('Allowed choices are codex, claude-code, json') + expect(unknown.stderr.join('')).toContain("unknown option '--print-client-config'") + expect(unknown.stdout.join('')).toBe('') const help = await boot(['--help']) expect(help.stdout.join('')).toContain('Usage: dsh --profile cua-mcp [options]') - expect(help.stdout.join('')).toContain('--print-client-config codex') expect(help.stdout.join('')).toContain('DSH_CUA_CONSENT=allow') expect(help.exit).toHaveBeenCalledWith(0) expect(createCuaMcpServer).not.toHaveBeenCalled()