feat: give owner runs a headless chrome-devtools MCP
Adds chrome-devtools-mcp 1.11.0 to the Claude runner so the owner (or a single-mode room) can open pages, click/fill, take screenshots and read console/network errors. Reviewer, arbiter and read-only runtimes do not get it. Chrome runs headless with an isolated temp profile under TMPDIR, Google usage statistics and CrUX lookups are off. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
3
bun.lock
3
bun.lock
@@ -34,6 +34,7 @@
|
||||
"@anthropic-ai/claude-agent-sdk": "0.3.286",
|
||||
"@anthropic-ai/sdk": "0.100.0",
|
||||
"@modelcontextprotocol/sdk": "1.29.0",
|
||||
"chrome-devtools-mcp": "1.11.0",
|
||||
"cron-parser": "^5.0.0",
|
||||
"ejclaw-runners-shared": "workspace:*",
|
||||
"zod": "^4.0.0",
|
||||
@@ -305,6 +306,8 @@
|
||||
|
||||
"chownr": ["chownr@1.1.4", "", {}, "sha512-jJ0bqzaylmJtVnNgzTeSOs8DPavpbYgEr/b0YL8/2GO3xJEhInFmhKMUnEJQjZumK7KXGFhUy89PrsJWlakBVg=="],
|
||||
|
||||
"chrome-devtools-mcp": ["chrome-devtools-mcp@1.11.0", "", { "peerDependencies": { "@blackwell-systems/gcf": "^2.2.2", "@toon-format/toon": "^4.1.0" }, "optionalPeers": ["@blackwell-systems/gcf", "@toon-format/toon"], "bin": { "chrome-devtools": "build/src/bin/chrome-devtools.js", "chrome-devtools-mcp": "build/src/bin/chrome-devtools-mcp.js" } }, "sha512-CytJ/5tnzrS+J/74be2P5aCOsS/mmGRHys/Si+IYC4ucrbnWAmES/dYdxGJjeUCECRcoFUilZAysdjlwqUjXIA=="],
|
||||
|
||||
"colorette": ["colorette@2.0.20", "", {}, "sha512-IfEDxwoWIjkeXL1eXcDiow4UbKjhLdq6/EuSVR9GMN7KVH3r9gQ83e73hsz1Nd1T3ijd5xv1wcWRYO+D6kCI2w=="],
|
||||
|
||||
"content-disposition": ["content-disposition@1.0.1", "", {}, "sha512-oIXISMynqSqm241k6kcQ5UwttDILMK4BiurCfGEREw6+X9jkkpEe5T9FZaApyLGGOnFuyMWZpdolTXMtvEJ08Q=="],
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
"@anthropic-ai/claude-agent-sdk": "0.3.286",
|
||||
"@anthropic-ai/sdk": "0.100.0",
|
||||
"@modelcontextprotocol/sdk": "1.29.0",
|
||||
"chrome-devtools-mcp": "1.11.0",
|
||||
"cron-parser": "^5.0.0",
|
||||
"ejclaw-runners-shared": "workspace:*",
|
||||
"zod": "^4.0.0"
|
||||
|
||||
@@ -1,10 +1,20 @@
|
||||
import { query } from '@anthropic-ai/claude-agent-sdk';
|
||||
import { EJCLAW_ENV, IPC_POLL_MS } from 'ejclaw-runners-shared';
|
||||
import {
|
||||
EJCLAW_ENV,
|
||||
IPC_POLL_MS,
|
||||
isArbiterRuntimeEnvEnabled,
|
||||
} from 'ejclaw-runners-shared';
|
||||
|
||||
import { compactBoundaryFromMessage } from './compaction-boundary.js';
|
||||
import { getClaudeCliPath } from './claude-cli.js';
|
||||
import { drainIpcInput, shouldClose } from './ipc-input.js';
|
||||
import { buildEjclawMcpServerConfig } from './mcp-config.js';
|
||||
import {
|
||||
buildChromeDevtoolsMcpServerConfig,
|
||||
buildEjclawMcpServerConfig,
|
||||
CHROME_DEVTOOLS_MCP_SERVER_NAME,
|
||||
resolveChromeDevtoolsMcpEntry,
|
||||
shouldEnableChromeDevtoolsMcp,
|
||||
} from './mcp-config.js';
|
||||
import {
|
||||
MessageStream,
|
||||
buildCompactionOutput,
|
||||
@@ -186,6 +196,11 @@ class ClaudeQueryRunner {
|
||||
)
|
||||
: undefined;
|
||||
|
||||
const chromeDevtoolsMcp = this.buildChromeDevtoolsMcp(
|
||||
readonlyReviewerRuntime,
|
||||
readonlyProtectedPaths,
|
||||
);
|
||||
|
||||
return {
|
||||
pathToClaudeCodeExecutable: getClaudeCliPath(this.args.log),
|
||||
cwd: this.effectiveCwd,
|
||||
@@ -195,7 +210,10 @@ class ClaudeQueryRunner {
|
||||
additionalDirectories:
|
||||
this.extraDirs.length > 0 ? this.extraDirs : undefined,
|
||||
resume: this.args.sessionId,
|
||||
allowedTools: this.buildAllowedTools(readonlyReviewerRuntime),
|
||||
allowedTools: this.buildAllowedTools(
|
||||
readonlyReviewerRuntime,
|
||||
Boolean(chromeDevtoolsMcp),
|
||||
),
|
||||
env: this.args.sdkEnv,
|
||||
permissionMode: 'bypassPermissions' as const,
|
||||
allowDangerouslySkipPermissions: true,
|
||||
@@ -213,6 +231,9 @@ class ClaudeQueryRunner {
|
||||
ipcDir: process.env[EJCLAW_ENV.ipcDir],
|
||||
hostIpcDir: process.env[EJCLAW_ENV.hostIpcDir],
|
||||
}),
|
||||
...(chromeDevtoolsMcp
|
||||
? { [CHROME_DEVTOOLS_MCP_SERVER_NAME]: chromeDevtoolsMcp }
|
||||
: {}),
|
||||
},
|
||||
hooks: {
|
||||
PreCompact: [
|
||||
@@ -242,6 +263,24 @@ class ClaudeQueryRunner {
|
||||
};
|
||||
}
|
||||
|
||||
private buildChromeDevtoolsMcp(readonlyRuntime: boolean, workDirs: string[]) {
|
||||
const enabled = shouldEnableChromeDevtoolsMcp(
|
||||
this.args.runnerInput.roomRoleContext?.role,
|
||||
readonlyRuntime || isArbiterRuntimeEnvEnabled(process.env),
|
||||
);
|
||||
if (!enabled) return null;
|
||||
const entry = resolveChromeDevtoolsMcpEntry();
|
||||
if (!entry) {
|
||||
this.args.log('chrome-devtools-mcp not installed, browser MCP disabled');
|
||||
return null;
|
||||
}
|
||||
const tmpDir = process.env.TMPDIR;
|
||||
return buildChromeDevtoolsMcpServerConfig(entry, [
|
||||
...workDirs,
|
||||
...(tmpDir ? [tmpDir] : []),
|
||||
]);
|
||||
}
|
||||
|
||||
private logRuntimeConfig(): void {
|
||||
const model = this.resolveModel();
|
||||
const thinking = this.resolveThinking();
|
||||
@@ -293,7 +332,10 @@ class ClaudeQueryRunner {
|
||||
);
|
||||
}
|
||||
|
||||
private buildAllowedTools(readonlyRuntime: boolean): string[] {
|
||||
private buildAllowedTools(
|
||||
readonlyRuntime: boolean,
|
||||
chromeDevtools: boolean,
|
||||
): string[] {
|
||||
const readonlyTools = [
|
||||
'Bash',
|
||||
'Read',
|
||||
@@ -333,7 +375,10 @@ class ClaudeQueryRunner {
|
||||
'NotebookEdit',
|
||||
'mcp__ejclaw__*',
|
||||
];
|
||||
return readonlyRuntime ? readonlyTools : writeTools;
|
||||
if (readonlyRuntime) return readonlyTools;
|
||||
return chromeDevtools
|
||||
? [...writeTools, `mcp__${CHROME_DEVTOOLS_MCP_SERVER_NAME}__*`]
|
||||
: writeTools;
|
||||
}
|
||||
|
||||
private handleMessage(message: unknown): boolean {
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
import { createRequire } from 'module';
|
||||
import path from 'path';
|
||||
|
||||
import type { McpStdioServerConfig } from '@anthropic-ai/claude-agent-sdk';
|
||||
import { EJCLAW_ENV } from 'ejclaw-runners-shared';
|
||||
|
||||
@@ -32,3 +35,57 @@ export function buildEjclawMcpServerConfig(
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
export const CHROME_DEVTOOLS_MCP_SERVER_NAME = 'chrome-devtools';
|
||||
|
||||
/**
|
||||
* Browser automation is a write-capable tool (click/fill/upload on live
|
||||
* sites), so it is only given to agents that are allowed to act: the paired
|
||||
* owner, or a single-mode room (no role). Reviewer/arbiter stay read-only.
|
||||
*/
|
||||
export function shouldEnableChromeDevtoolsMcp(
|
||||
roomRole: string | undefined,
|
||||
readonlyRuntime: boolean,
|
||||
): boolean {
|
||||
if (readonlyRuntime) return false;
|
||||
return !roomRole || roomRole === 'owner';
|
||||
}
|
||||
|
||||
export function resolveChromeDevtoolsMcpEntry(): string | null {
|
||||
try {
|
||||
const require = createRequire(import.meta.url);
|
||||
const pkgJson = require.resolve('chrome-devtools-mcp/package.json');
|
||||
return path.join(
|
||||
path.dirname(pkgJson),
|
||||
'build/src/bin/chrome-devtools-mcp.js',
|
||||
);
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Headless Chrome with a throwaway profile (no shared cookies/logins), no
|
||||
* Google usage statistics and no CrUX lookups. Chrome is launched lazily on the
|
||||
* first browser tool call; the temp profile lives under TMPDIR (disk, not
|
||||
* tmpfs, on this host).
|
||||
*/
|
||||
export function buildChromeDevtoolsMcpServerConfig(
|
||||
entryPath: string,
|
||||
workspaceDirs: string[],
|
||||
): McpStdioServerConfig {
|
||||
return {
|
||||
command: 'node',
|
||||
args: [
|
||||
entryPath,
|
||||
'--headless',
|
||||
'--isolated',
|
||||
'--no-usage-statistics',
|
||||
'--no-performance-crux',
|
||||
...workspaceDirs.map((dir) => `--workspace=${dir}`),
|
||||
],
|
||||
env: {
|
||||
CHROME_DEVTOOLS_MCP_NO_USAGE_STATISTICS: '1',
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,7 +1,13 @@
|
||||
import fs from 'fs';
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { EJCLAW_ENV } from 'ejclaw-runners-shared';
|
||||
|
||||
import { buildEjclawMcpServerConfig } from '../src/mcp-config.js';
|
||||
import {
|
||||
buildChromeDevtoolsMcpServerConfig,
|
||||
buildEjclawMcpServerConfig,
|
||||
resolveChromeDevtoolsMcpEntry,
|
||||
shouldEnableChromeDevtoolsMcp,
|
||||
} from '../src/mcp-config.js';
|
||||
|
||||
describe('ejclaw MCP config', () => {
|
||||
it('always loads EJClaw MCP tools on turn one and preserves runtime env', () => {
|
||||
@@ -29,3 +35,39 @@ describe('ejclaw MCP config', () => {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('chrome-devtools MCP config', () => {
|
||||
it('is enabled only for the owner or a single-mode room', () => {
|
||||
expect(shouldEnableChromeDevtoolsMcp('owner', false)).toBe(true);
|
||||
expect(shouldEnableChromeDevtoolsMcp(undefined, false)).toBe(true);
|
||||
expect(shouldEnableChromeDevtoolsMcp('reviewer', false)).toBe(false);
|
||||
expect(shouldEnableChromeDevtoolsMcp('arbiter', false)).toBe(false);
|
||||
expect(shouldEnableChromeDevtoolsMcp('owner', true)).toBe(false);
|
||||
});
|
||||
|
||||
it('resolves the installed server entry', () => {
|
||||
const entry = resolveChromeDevtoolsMcpEntry();
|
||||
expect(entry).toMatch(
|
||||
/chrome-devtools-mcp\/build\/src\/bin\/chrome-devtools-mcp\.js$/,
|
||||
);
|
||||
expect(fs.existsSync(entry!)).toBe(true);
|
||||
});
|
||||
|
||||
it('runs headless with an isolated profile and telemetry off', () => {
|
||||
const config = buildChromeDevtoolsMcpServerConfig('/x/entry.js', [
|
||||
'/work',
|
||||
'/home/claude/.tmp',
|
||||
]);
|
||||
expect(config.command).toBe('node');
|
||||
expect(config.args).toEqual([
|
||||
'/x/entry.js',
|
||||
'--headless',
|
||||
'--isolated',
|
||||
'--no-usage-statistics',
|
||||
'--no-performance-crux',
|
||||
'--workspace=/work',
|
||||
'--workspace=/home/claude/.tmp',
|
||||
]);
|
||||
expect(config.env?.CHROME_DEVTOOLS_MCP_NO_USAGE_STATISTICS).toBe('1');
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user