Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion browser-tools-mcp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"main": "dist/index.js",
"bin": {
"browser-tools-mcp": "dist/index.js",
"browser-tools-connector": "dist/connector-bin.js"
"browser-tools-connector": "dist/connector-bin.js",
"browser-tools": "dist/tools-cli-bin.js"
},
"files": [
"dist",
Expand Down
34 changes: 12 additions & 22 deletions browser-tools-mcp/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@ export interface CliOptions {
auditAllowedOrigins?: string[];
/** Let audits reach any loopback/private address but the audits' own ports (not recommended). */
auditAllowPrivateNetwork: boolean;
/** State-changing local API calls, without a panel confirmation. */
allowActions: boolean;
/** Only this extension may pair. Bare id or full origin. */
extensionId?: string;
/**
* Script evaluation. Argv only — not read from the environment — and off
* unless this flag is present.
Expand All @@ -38,6 +34,8 @@ export interface CliOptions {
allowInputOrigins?: string[];
/** http(s) origins that are never acted on. Empty unless set. */
excludeOrigins?: string[];
/** Only this extension may pair. Bare id or full origin. */
extensionId?: string;
}

export function readPackageVersion(): string {
Expand Down Expand Up @@ -80,15 +78,11 @@ export function parseCli(argv: string[], env: NodeJS.ProcessEnv = process.env):
auditAllowPrivateNetwork:
env["BROWSER_TOOLS_AUDIT_ALLOW_PRIVATE_NETWORK"] === "true" ||
env["BROWSER_TOOLS_AUDIT_ALLOW_PRIVATE_NETWORK"] === "1",
allowActions:
env["BROWSER_TOOLS_ALLOW_ACTIONS"] === "true" || env["BROWSER_TOOLS_ALLOW_ACTIONS"] === "1",
allowEval: false,
allowInput: false,
...(env["BROWSER_TOOLS_EXTENSION_ID"]
? { extensionId: env["BROWSER_TOOLS_EXTENSION_ID"] }
: {}),
// Capability flags are argv only. They are intentionally not read from the
// environment, so an inherited variable cannot turn them on.
allowEval: false,
allowInput: false,
...(splitList(env["BROWSER_TOOLS_AUDIT_ALLOW_ORIGINS"])
? { auditAllowedOrigins: splitList(env["BROWSER_TOOLS_AUDIT_ALLOW_ORIGINS"]) }
: {}),
Expand All @@ -108,7 +102,6 @@ export function parseCli(argv: string[], env: NodeJS.ProcessEnv = process.env):
: {}),
};

// Both spellings of the flag, and the variable, add to the same list.
const addAuditOrigins = (value: string | undefined) => {
options.auditAllowedOrigins = [...(options.auditAllowedOrigins ?? []), ...(splitList(value) ?? [])];
};
Expand Down Expand Up @@ -151,12 +144,6 @@ export function parseCli(argv: string[], env: NodeJS.ProcessEnv = process.env):
case "--audit-allow-private-network":
options.auditAllowPrivateNetwork = true;
break;
case "--allow-actions":
options.allowActions = true;
break;
case "--extension-id":
options.extensionId = next();
break;
case "--allow-eval":
options.allowEval = true;
break;
Expand All @@ -169,6 +156,9 @@ export function parseCli(argv: string[], env: NodeJS.ProcessEnv = process.env):
case "--exclude-origins":
addExcludeOrigins(next());
break;
case "--extension-id":
options.extensionId = next();
break;
case "--port":
options.port = numberOrUndefined(next());
break;
Expand Down Expand Up @@ -199,9 +189,11 @@ export function parseCli(argv: string[], env: NodeJS.ProcessEnv = process.env):
else if (arg.startsWith("--token=")) options.token = arg.slice(8);
else if (arg.startsWith("--screenshot-dir=")) options.screenshotDir = arg.slice(17);
else if (arg.startsWith("--audit-allow-origin=")) addAuditOrigins(arg.slice(21));
else if (arg.startsWith("--allow-input-origins="))
addInputOrigins(arg.slice("--allow-input-origins=".length));
else if (arg.startsWith("--exclude-origins="))
addExcludeOrigins(arg.slice("--exclude-origins=".length));
else if (arg.startsWith("--extension-id=")) options.extensionId = arg.slice(15);
else if (arg.startsWith("--allow-input-origins=")) addInputOrigins(arg.slice("--allow-input-origins=".length));
else if (arg.startsWith("--exclude-origins=")) addExcludeOrigins(arg.slice("--exclude-origins=".length));
break;
}
}
Expand All @@ -228,7 +220,6 @@ Options:
--screenshot-dir <p> Where screenshots are written
--only <a,b> Expose only these tools
--exclude <a,b> Hide these tools (also on the local API)
--allow-actions Let the local API reload, capture, wipe and change settings
--extension-id <id> Only this extension may connect
--connect <url> Attach to a connector already running at this URL
--token <t> Auth token to use with --connect
Expand All @@ -255,8 +246,7 @@ Environment:
BROWSER_TOOLS_TOOLS, BROWSER_TOOLS_EXCLUDE_TOOLS, BROWSER_TOOLS_TOKEN,
BROWSER_TOOLS_STATE_DIR, BROWSER_TOOLS_LOG_LEVEL, BROWSER_TOOLS_REDACT,
BROWSER_TOOLS_VERBOSE, BROWSER_TOOLS_AUDIT_ALLOW_ORIGINS,
BROWSER_TOOLS_AUDIT_ALLOW_PRIVATE_NETWORK, BROWSER_TOOLS_ALLOW_ACTIONS,
BROWSER_TOOLS_EXTENSION_ID
BROWSER_TOOLS_AUDIT_ALLOW_PRIVATE_NETWORK, BROWSER_TOOLS_EXTENSION_ID

Available tools:
${ALL_TOOL_NAMES.join(", ")}
Expand Down
14 changes: 4 additions & 10 deletions browser-tools-mcp/src/connector-bin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,19 +42,14 @@ async function main(): Promise<void> {
` Let audits reach any loopback or private address, except the\n` +
` audits' own ports (not recommended). Also needed behind a\n` +
` fake-IP proxy (198.18.0.0/15 answers are refused otherwise)\n` +
` --only <a,b> Serve only these tools on the local API\n` +
` --exclude <a,b> Do not serve these tools on the local API\n` +
` --allow-actions Allow reload, screenshot, wipe, settings and tab select\n` +
` --extension-id <id> Only this extension may connect\n` +
` --allow-eval Allow script evaluation. Off unless passed. No environment variable.\n` +
` --allow-input Allow click, type, navigation, and soft input. Off unless passed.\n` +
` No environment variable.\n` +
` --allow-input-origins <o,o>\n` +
` http(s) origins where input and navigation are allowed besides local addresses\n` +
` --exclude-origins <o,o>\n` +
` http(s) origins that are never acted on. Empty unless set.\n\n` +
`Audit settings, tool filters, --allow-actions and capability flags apply to every MCP\n` +
`client that attaches to this connector.\n`
`Audit and capability settings apply to every MCP client that attaches to this connector.\n`
);
return;
}
Expand All @@ -68,14 +63,13 @@ async function main(): Promise<void> {
verbose: options.verbose,
...(options.auditAllowedOrigins ? { auditAllowedOrigins: options.auditAllowedOrigins } : {}),
auditAllowPrivateNetwork: options.auditAllowPrivateNetwork,
...(options.enabledTools ? { enabledTools: options.enabledTools } : {}),
...(options.disabledTools ? { disabledTools: options.disabledTools } : {}),
allowActions: options.allowActions,
...(options.extensionId ? { extensionId: options.extensionId } : {}),
allowEval: options.allowEval,
allowInput: options.allowInput,
...(options.allowInputOrigins ? { allowInputOrigins: options.allowInputOrigins } : {}),
...(options.excludeOrigins ? { excludeOrigins: options.excludeOrigins } : {}),
...(options.enabledTools ? { enabledTools: options.enabledTools } : {}),
...(options.disabledTools ? { disabledTools: options.disabledTools } : {}),
...(options.extensionId ? { extensionId: options.extensionId } : {}),
});

writeSessionFile({
Expand Down
6 changes: 5 additions & 1 deletion browser-tools-mcp/src/connector/api-policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export const API_TOOL_NAMES: readonly string[] = [
"getConnectionStatus",
"takeScreenshot",
"refreshBrowser",
"navigateBrowser",
"getBrowserStorage",
"wipeLogs",
...AUDIT_CATEGORIES.map((category) => AUDIT_TOOL[category]),
Expand All @@ -59,7 +60,8 @@ export interface ApiDecision {

const TOOL_DISABLED = "This call is not enabled (--only / --exclude).";
const ACTION_NOT_CONFIRMED =
"State-changing calls need --allow-actions, or confirmation in the BrowserTools panel.";
"State-changing calls need --allow-input on the connector (browser-tools CLI: --allow-actions), " +
"or confirmation in the BrowserTools panel.";

function truthyFlag(value: unknown): boolean {
if (value === true) return true;
Expand Down Expand Up @@ -97,6 +99,7 @@ function toolsForRequest(method: string, path: string, query: Record<string, unk
if (method === "GET" && path === "/tabs") return ["listBrowserTabs"];
if (method === "POST" && path === "/screenshot") return ["takeScreenshot"];
if (method === "POST" && path === "/refresh") return ["refreshBrowser"];
if (method === "POST" && path === "/navigate") return ["navigateBrowser"];
if (method === "POST" && path === "/storage") return ["getBrowserStorage"];
if (method === "POST" && path === "/wipe") return ["wipeLogs"];
if (method === "GET" && path === "/export/console") return ["getConsoleLogs", "getConsoleErrors"];
Expand Down Expand Up @@ -131,6 +134,7 @@ export function isStateChangingRequest(method: string, path: string): boolean {
(path === "/wipe" ||
path === "/screenshot" ||
path === "/refresh" ||
path === "/navigate" ||
path === "/settings" ||
path === "/tabs/select")
);
Expand Down
Loading
Loading