Skip to content
Open
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
4 changes: 2 additions & 2 deletions bun.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"@modelcontextprotocol/core": "2.0.0",
"@modelcontextprotocol/server": "2.0.0",
"@onkernel/managed-auth-react": "0.5.5",
"@onkernel/sdk": "0.152.0",
"@onkernel/sdk": "0.154.0",
"@posthog/mcp": "0.17.0",
"@types/jsonwebtoken": "^9.0.10",
"@types/redis": "^4.0.11",
Expand Down
2 changes: 2 additions & 0 deletions src/lib/mcp/tools/apps.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ describe("manage_apps invocation contract", () => {
captcha_solver: { enabled: true },
stealth: true,
fingerprint: { os: "linux" },
platform: { os: "macos" },
memory: "2GiB",
timeout_seconds: 600,
region: "us-east",
Expand Down Expand Up @@ -161,6 +162,7 @@ describe("manage_apps invocation contract", () => {
"https://api.onkernel.com/browser/live/signed",
captcha_solver: { enabled: true },
fingerprint: { os: "linux" },
platform: { os: "macos" },
leased_at: "2026-08-08T00:05:00Z",
location: {
timezone: "America/New_York",
Expand Down
3 changes: 3 additions & 0 deletions src/lib/mcp/tools/apps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,9 @@ export function registerAppCapabilities(
...(browser.fingerprint !== undefined && {
fingerprint: browser.fingerprint,
}),
...(browser.platform !== undefined && {
platform: browser.platform,
}),
...(browser.leased_at !== undefined && {
leased_at: browser.leased_at,
}),
Expand Down
4 changes: 3 additions & 1 deletion src/lib/mcp/tools/browser-pools.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ describe("browser-pool contract parity", () => {
});
});

test("forwards acquire overrides and returns leased time, network, memory, and location", async () => {
test("forwards acquire overrides and returns leased time, platform, network, memory, and location", async () => {
const network = { allowed_hosts: ["example.com"] };
const location = {
timezone: "America/New_York",
Expand All @@ -491,6 +491,7 @@ describe("browser-pool contract parity", () => {
memory: "2GiB",
captcha_solver: { enabled: true },
fingerprint: { os: "linux" },
platform: { os: "linux" },
location,
};
},
Expand Down Expand Up @@ -535,6 +536,7 @@ describe("browser-pool contract parity", () => {
memory: "2GiB",
captcha_solver: { enabled: true },
fingerprint: { os: "linux" },
platform: { os: "linux" },
location,
replay: {
replay_id: "rpl_1",
Expand Down
1 change: 1 addition & 0 deletions src/lib/mcp/tools/browser-pools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,7 @@ function summarizeAcquiredBrowser(browser: BrowserPoolAcquireResponse) {
captcha_solver: browser.captcha_solver,
stealth: browser.stealth,
fingerprint: browser.fingerprint,
platform: browser.platform,
timeout_seconds: browser.timeout_seconds,
memory: browser.memory,
location: browser.location,
Expand Down
217 changes: 214 additions & 3 deletions src/lib/mcp/tools/browsers.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/// <reference types="bun-types" />

import { describe, expect, test } from "bun:test";
import { APIError } from "@onkernel/sdk";
import {
connectTestMcp,
toolResultJSON,
Expand Down Expand Up @@ -1189,15 +1190,15 @@ describe("manage_browsers location, memory, and conditional allowlists", () => {
}
});

test("forwards include_deleted=false on get", async () => {
test("forwards explicit detail flags and leaves opt-in cost off by default", async () => {
const calls: unknown[] = [];
const { client, close } = await connectTestMcp(
registerBrowserCapabilities,
{
browsers: {
retrieve: async (...args: unknown[]) => {
calls.push(args);
return { session_id: "brr_deleted" };
return { session_id: String(args[0]) };
},
},
},
Expand All @@ -1210,9 +1211,29 @@ describe("manage_browsers location, memory, and conditional allowlists", () => {
action: "get",
session_id: "brr_deleted",
include_deleted: false,
include_cost: false,
},
});
expect(calls).toEqual([["brr_deleted", { include_deleted: false }]]);
await client.callTool({
name: "manage_browsers",
arguments: {
action: "get",
session_id: "brr_active",
},
});
await client.callTool({
name: "manage_browsers",
arguments: {
action: "get",
session_id: "brr_costed",
include_cost: true,
},
});
expect(calls).toEqual([
["brr_deleted", { include_cost: false, include_deleted: false }],
["brr_active"],
["brr_costed", { include_cost: true }],
]);
} finally {
await close();
}
Expand Down Expand Up @@ -1441,6 +1462,110 @@ describe("manage_browsers captcha solving and fingerprint overrides", () => {
});
});

describe("manage_browsers host platform", () => {
test("advertises and forwards the browser host operating system", async () => {
const creates: unknown[] = [];
let updates = 0;
const { client, close } = await connectTestMcp(
registerBrowserCapabilities,
{
browsers: {
create: async (params: unknown) => {
creates.push(params);
return { session_id: "brr_macos", platform: { os: "macos" } };
},
update: async () => {
updates++;
return { session_id: "brr_macos" };
},
},
},
);

try {
const tool = (await client.listTools()).tools.find(
({ name }) => name === "manage_browsers",
);
const platform = tool?.inputSchema.properties?.platform as
| {
description?: string;
properties?: { os?: { enum?: string[] } };
}
| undefined;
expect(platform?.properties?.os?.enum).toEqual(["linux", "macos"]);
expect(platform?.description).toContain(
"reported browser os override does not change the host",
);
expect(platform?.description).toContain("profile_id/profile_name");
expect(platform?.description).toContain("platform_unavailable");
expect(platform?.description).toContain("unsupported_configuration");
expect(platform?.description).toContain("unsupported_fields");

const created = toolResultJSON(
await client.callTool({
name: "manage_browsers",
arguments: { action: "create", platform: { os: "macos" } },
}),
);
expect(creates).toEqual([{ platform: { os: "macos" } }]);
expect(created.browser.platform).toEqual({ os: "macos" });

const update = await client.callTool({
name: "manage_browsers",
arguments: {
action: "update",
session_id: "brr_macos",
platform: { os: "linux" },
},
});
expect(update.isError).toBe(true);
expect(updates).toBe(0);
} finally {
await close();
}
});

test("surfaces safe unsupported platform fields from API errors", async () => {
const { client, close } = await connectTestMcp(
registerBrowserCapabilities,
{
browsers: {
create: async () => {
throw APIError.generate(
400,
{
code: "unsupported_configuration",
message: "The requested platform configuration is unsupported.",
unsupported_fields: ["headless", "profile"],
},
undefined,
new Headers(),
);
},
},
},
);

try {
const result = await client.callTool({
name: "manage_browsers",
arguments: {
action: "create",
platform: { os: "macos" },
headless: true,
profile_id: "profile_1",
},
});
expect(result.isError).toBe(true);
expect(toolResultText(result)).toContain(
"unsupported fields: headless, profile.",
);
} finally {
await close();
}
});
});

describe("manage_browsers region", () => {
test("passes region to create and list", async () => {
const createCalls: unknown[] = [];
Expand Down Expand Up @@ -1501,6 +1626,92 @@ describe("manage_browsers region", () => {
});
});

describe("manage_browsers cost details", () => {
test("opts into detail cost, returns guidance, and preserves zero spend", async () => {
const costs = {
brr_provisional: {
status: "provisional",
estimated_usage_spend_usd: "0",
as_of: "2026-11-20T12:34:56Z",
},
brr_pending: { status: "pending" },
brr_unavailable: { status: "unavailable" },
} as const;
const calls: unknown[] = [];
const { client, close } = await connectTestMcp(
registerBrowserCapabilities,
{
browsers: {
retrieve: async (...args: unknown[]) => {
calls.push(args);
const [sessionId, query] = args as [
keyof typeof costs,
{ include_cost?: boolean } | undefined,
];
return {
session_id: sessionId,
...(query?.include_cost && { cost: costs[sessionId] }),
};
},
},
},
);

try {
const results = [];
for (const session_id of Object.keys(costs)) {
results.push(
toolResultJSON(
await client.callTool({
name: "manage_browsers",
arguments: { action: "get", session_id, include_cost: true },
}),
),
);
}

expect(results.map(({ cost }) => cost)).toEqual(Object.values(costs));
expect(results[0].cost).toEqual({
status: "provisional",
estimated_usage_spend_usd: "0",
as_of: "2026-11-20T12:34:56Z",
});
for (const { note } of results) {
expect(note).toContain("gross provisional usd browser-meter cost");
expect(note).toContain("not an invoice total");
expect(note).toContain('status "pending"');
expect(note).toContain('"unavailable"');
expect(note).toContain("may accrue additional usage");
}

const resource = (await client.readResource({
uri: "kernel://orgs/org_test/projects/proj_test/browsers/brr_provisional",
})) as TextResourceResult;
expect(JSON.parse(resource.contents[0].text)).toEqual({
session_id: "brr_provisional",
});
expect(calls).toEqual([
["brr_provisional", { include_cost: true }],
["brr_pending", { include_cost: true }],
["brr_unavailable", { include_cost: true }],
["brr_provisional"],
]);

const browserTool = (await client.listTools()).tools.find(
({ name }) => name === "manage_browsers",
);
expect(browserTool?.description).toContain(
'"get" for full details and optional provisional browser-session usage cost',
);
expect(browserTool?.inputSchema.properties?.include_cost).toMatchObject({
description: expect.stringContaining("default is off"),
});
} finally {
await close();
}
});
});

describe("manage_browsers replay creation and live view", () => {
test("forwards start_replay=false and returns replay metadata", async () => {
const calls: unknown[] = [];
Expand Down
Loading
Loading