setup.ts 2.0 KB

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