/ utils / computerUse / setup.ts
setup.ts
 1  import { buildComputerUseTools } from '@ant/computer-use-mcp'
 2  import { join } from 'path'
 3  import { fileURLToPath } from 'url'
 4  import { buildMcpToolName } from '../../services/mcp/mcpStringUtils.js'
 5  import type { ScopedMcpServerConfig } from '../../services/mcp/types.js'
 6  
 7  import { isInBundledMode } from '../bundledMode.js'
 8  import { CLI_CU_CAPABILITIES, COMPUTER_USE_MCP_SERVER_NAME } from './common.js'
 9  import { getChicagoCoordinateMode } from './gates.js'
10  
11  /**
12   * Build the dynamic MCP config + allowed tool names. Mirror of
13   * `setupClaudeInChrome`. The `mcp__computer-use__*` tools are added to
14   * `allowedTools` so they bypass the normal permission prompt — the package's
15   * `request_access` handles approval for the whole session.
16   *
17   * The MCP layer isn't ceremony: the API backend detects `mcp__computer-use__*`
18   * tool names and emits a CU availability hint into the system prompt
19   * (COMPUTER_USE_MCP_AVAILABILITY_HINT in the anthropic repo). Built-in tools
20   * with different names wouldn't trigger it. Cowork uses the same names for the
21   * same reason (apps/desktop/src/main/local-agent-mode/systemPrompt.ts:314).
22   */
23  export function setupComputerUseMCP(): {
24    mcpConfig: Record<string, ScopedMcpServerConfig>
25    allowedTools: string[]
26  } {
27    const allowedTools = buildComputerUseTools(
28      CLI_CU_CAPABILITIES,
29      getChicagoCoordinateMode(),
30    ).map(t => buildMcpToolName(COMPUTER_USE_MCP_SERVER_NAME, t.name))
31  
32    // command/args are never spawned — client.ts intercepts by name and
33    // uses the in-process server. The config just needs to exist with
34    // type 'stdio' to hit the right branch. Mirrors Chrome's setup.
35    const args = isInBundledMode()
36      ? ['--computer-use-mcp']
37      : [
38          join(fileURLToPath(import.meta.url), '..', 'cli.js'),
39          '--computer-use-mcp',
40        ]
41  
42    return {
43      mcpConfig: {
44        [COMPUTER_USE_MCP_SERVER_NAME]: {
45          type: 'stdio',
46          command: process.execPath,
47          args,
48          scope: 'dynamic',
49        } as const,
50      },
51      allowedTools,
52    }
53  }