()
| 89 | * @returns MCP config and allowed tools, or throws an error if platform is unsupported |
| 90 | */ |
| 91 | export function setupClaudeInChrome(): { |
| 92 | mcpConfig: Record<string, ScopedMcpServerConfig> |
| 93 | allowedTools: string[] |
| 94 | systemPrompt: string |
| 95 | } { |
| 96 | const isNativeBuild = isInBundledMode() |
| 97 | const allowedTools = BROWSER_TOOLS.map( |
| 98 | tool => `mcp__claude-in-chrome__${tool.name}`, |
| 99 | ) |
| 100 | |
| 101 | const env: Record<string, string> = {} |
| 102 | if (getSessionBypassPermissionsMode()) { |
| 103 | env.CLAUDE_CHROME_PERMISSION_MODE = 'skip_all_permission_checks' |
| 104 | } |
| 105 | const hasEnv = Object.keys(env).length > 0 |
| 106 | |
| 107 | if (isNativeBuild) { |
| 108 | // Create a wrapper script that calls the same binary with --chrome-native-host. This |
| 109 | // is needed because the native host manifest "path" field cannot contain arguments. |
| 110 | const execCommand = `"${process.execPath}" --chrome-native-host` |
| 111 | |
| 112 | // Run asynchronously without blocking; best-effort so swallow errors |
| 113 | void createWrapperScript(execCommand) |
| 114 | .then(manifestBinaryPath => |
| 115 | installChromeNativeHostManifest(manifestBinaryPath), |
| 116 | ) |
| 117 | .catch(e => |
| 118 | logForDebugging( |
| 119 | `[Claude in Chrome] Failed to install native host: ${e}`, |
| 120 | { level: 'error' }, |
| 121 | ), |
| 122 | ) |
| 123 | |
| 124 | return { |
| 125 | mcpConfig: { |
| 126 | [CLAUDE_IN_CHROME_MCP_SERVER_NAME]: { |
| 127 | type: 'stdio' as const, |
| 128 | command: process.execPath, |
| 129 | args: ['--claude-in-chrome-mcp'], |
| 130 | scope: 'dynamic' as const, |
| 131 | ...(hasEnv && { env }), |
| 132 | }, |
| 133 | }, |
| 134 | allowedTools, |
| 135 | systemPrompt: getChromeSystemPrompt(), |
| 136 | } |
| 137 | } else { |
| 138 | const __filename = fileURLToPath(import.meta.url) |
| 139 | const __dirname = join(__filename, '..') |
| 140 | const cliPath = join(__dirname, 'cli.js') |
| 141 | |
| 142 | void createWrapperScript( |
| 143 | `"${process.execPath}" "${cliPath}" --chrome-native-host`, |
| 144 | ) |
| 145 | .then(manifestBinaryPath => |
| 146 | installChromeNativeHostManifest(manifestBinaryPath), |
| 147 | ) |
| 148 | .catch(e => |
no test coverage detected