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
51 changes: 51 additions & 0 deletions src/lib/mcp/tools/browsers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,57 @@ describe("manage_browsers telemetry", () => {
});
});

describe("manage_browsers region", () => {
test("passes region to create and list", async () => {
const createCalls: unknown[] = [];
const listCalls: unknown[] = [];
const kernelClient = {
browsers: {
create: async (params: unknown) => {
createCalls.push(params);
return { session_id: "brr_123" };
},
list: async (params: unknown) => {
listCalls.push(params);
return {
getPaginatedItems: () => [
{ session_id: "brr_eu", cdp_ws_url: "ws://example.test" },
],
has_more: false,
next_offset: null,
};
},
},
};
const { client, close } = await connectTestMcp(
registerBrowserCapabilities,
kernelClient,
);

try {
const created = toolResultJSON(
await client.callTool({
name: "manage_browsers",
arguments: { action: "create", region: "eu-west", stealth: true },
}),
);
expect(createCalls).toEqual([{ stealth: true, region: "eu-west" }]);
expect(created.browser.session_id).toBe("brr_123");

const listed = toolResultJSON(
await client.callTool({
name: "manage_browsers",
arguments: { action: "list", region: "eu-west" },
}),
);
expect(listCalls).toEqual([{ region: "eu-west" }]);
expect(listed.items).toEqual([{ session_id: "brr_eu" }]);
} finally {
await close();
}
});
});

describe("browser resources", () => {
test("uses injected dependencies", async () => {
const kernelClient = {
Expand Down
9 changes: 9 additions & 0 deletions src/lib/mcp/tools/browsers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,12 @@ export function registerBrowserCapabilities(
.boolean()
.describe("(create) Avoid bot detection. Recommended for scraping.")
.optional(),
region: z
.enum(["us-east", "eu-west"])
.describe(
"(create) Geographic region for the browser session. Fixed once created; requires Start-Up or Enterprise plan, defaults to us-east. (list) Filter sessions by region.",
)
.optional(),
timeout_seconds: z
.number()
.int()
Expand Down Expand Up @@ -660,6 +666,8 @@ export function registerBrowserCapabilities(
if (params.gpu !== undefined) createParams.gpu = params.gpu;
if (params.stealth !== undefined)
createParams.stealth = params.stealth;
if (params.region !== undefined)
createParams.region = params.region;
if (params.timeout_seconds !== undefined)
createParams.timeout_seconds = params.timeout_seconds;
if (params.kiosk_mode !== undefined)
Expand Down Expand Up @@ -743,6 +751,7 @@ export function registerBrowserCapabilities(
case "list": {
const page = await client.browsers.list({
...(params.status && { status: params.status }),
...(params.region && { region: params.region }),
...(params.limit !== undefined && { limit: params.limit }),
...(params.offset !== undefined && { offset: params.offset }),
});
Expand Down
Loading