Skip to content

Open-source Grok Bot alternative with a virtual machine that bots can use

fix(browser): agent_browser_read no longer offers a url it refuses

AdityaUmale5de81fddc262
diff --git a/server/browser-tool-shape.test.ts b/server/browser-tool-shape.test.ts
index 73cff11881..b4e2052c63 100644
--- a/server/browser-tool-shape.test.ts
+++ b/server/browser-tool-shape.test.ts
@@ -39,6 +39,9 @@ describe("browser tool shaping", () => {
expect(Object.keys(slimRead!.inputSchema.properties)).toEqual(["filter"]);
expect(slimRead!.inputSchema.required).toEqual([]);
expect(Object.keys(slimOpen!.inputSchema.properties)).toEqual(["url"]);
+ // agent-browser's own description offers the hidden url; the bot reads the open page's instead (email bug 1a1cb892)
+ expect((slimRead as { description?: string }).description).toBe("Read the page open in this browser as agent-readable text. To read another address, open it with agent_browser_open first.");
+ expect(slimOpen).not.toHaveProperty("description");
expect(readsAroundBrowser({ name: "agent_browser_read", arguments: { url: "http://127.0.0.1:8799/api/config" } })).toBe(true);
expect(readsAroundBrowser({ name: "agent_browser_read", arguments: { url: "" } })).toBe(true);
expect(readsAroundBrowser({ name: "agent_browser_read", arguments: { filter: "main" } })).toBe(false);
diff --git a/server/browser-tool-shape.ts b/server/browser-tool-shape.ts
index 435a2b824b..a3466fea9b 100644
--- a/server/browser-tool-shape.ts
+++ b/server/browser-tool-shape.ts
@@ -39,6 +39,8 @@ export function verifiedBrowserNavigation(args: unknown, observation: unknown):
* egress gate, and ignores every proxy setting; without one it reads the open tab. */
const READ_TOOL = "agent_browser_read";
export const READ_OPEN_PAGE_ONLY = "agent_browser_read reads the page open in this browser. Open the address with agent_browser_open first, then call agent_browser_read without url.";
+/** agent-browser's own description ("Fetch a URL … Omit url to read the active tab.") offers the `url` hidden below. */
+const READ_DESCRIPTION = "Read the page open in this browser as agent-readable text. To read another address, open it with agent_browser_open first.";
export function readsAroundBrowser(params: unknown): boolean {
return isRecord(params) && params.name === READ_TOOL && isRecord(params.arguments) && params.arguments.url !== undefined;
@@ -56,7 +58,8 @@ export function slimBrowserToolList(result: unknown): unknown {
const required = Array.isArray(schema.required)
? schema.required.filter((name) => typeof name !== "string" || !hidden(name))
: schema.required;
- return { ...tool, inputSchema: { ...schema, ...(properties === undefined ? {} : { properties }), ...(required === undefined ? {} : { required }) } };
+ return { ...tool, ...(tool.name === READ_TOOL ? { description: READ_DESCRIPTION } : {}),
+ inputSchema: { ...schema, ...(properties === undefined ? {} : { properties }), ...(required === undefined ? {} : { required }) } };
});
return { ...result, tools };
}
diff --git a/server/drivers/chat-mcp-tools.test.ts b/server/drivers/chat-mcp-tools.test.ts
index 9bb9f04b91..6d99d5eaef 100644
--- a/server/drivers/chat-mcp-tools.test.ts
+++ b/server/drivers/chat-mcp-tools.test.ts
@@ -204,6 +204,21 @@ describe("Chat MCP session", () => {
expect(calls).toEqual([dropped ? {} : { url: " " }, { url: "https://example.com" }]);
});
+ it.each([
+ ["browser", "Open the address with agent_browser_open first"],
+ ["custom", "input schema"],
+ ] as const)("names the way to read an address when agent_browser_read's url is hidden (%s)", async (mountAs, error) => {
+ // agent-browser's read with its url hidden by slimBrowserToolList (email bug 1a1cb892)
+ const readSchema = { type: "object", properties: { filter: { type: "string" } }, additionalProperties: false };
+ const f = fixture(`if (message.method === "tools/list") { reply(message, {tools:[{name:"agent_browser_read",description:"Read the open page.",inputSchema:schema}]}); continue; }`, readSchema);
+ const session = await mountChatTools(mountAs === "browser" ? { browser: f.server } : { custom: { browser: f.server } }, f.controller.signal, true);
+ sessions.push(session);
+ const name = session.definitions[0]!.function.name;
+ expect(() => session.validate(name, { url: "https://example.com/swagger.json" })).toThrow(error);
+ expect(() => session.validate(name, { filter: 7 })).toThrow("input schema");
+ expect(() => session.validate(name, {})).not.toThrow();
+ });
+
it("shows a model behind Moonshot each schema fitted to its limit, and still checks calls against the full one", async () => {
const full = wideSchema(110);
const f = fixture("", full);
diff --git a/server/drivers/chat-mcp-tools.ts b/server/drivers/chat-mcp-tools.ts
index e6770f0d6b..0d74305e37 100644
--- a/server/drivers/chat-mcp-tools.ts
+++ b/server/drivers/chat-mcp-tools.ts
@@ -22,6 +22,7 @@ import { REMOTE_MCP_STARTUP_MS, remoteMcpSpec } from "../mcp-http.ts";
import { compileToolSchema, schemaProblems, serverToolValidator, type ServerToolCheck } from "../mcp-schema-validator.ts";
import { fitToolList, withoutDanglingReferences } from "../mcp-tool-schema.ts";
import { listsComputerTool } from "../computer-tool-list.ts";
+import { READ_OPEN_PAGE_ONLY, readsAroundBrowser } from "../browser-tool-shape.ts";
import { capToolList, learnToolCountLimit, shareToolBudget, toolCountLimitFromError } from "../tool-count-limit.ts";
import type { ToolSchemaProfile } from "../tool-schema-profile.ts";
import { allowsTool, canUseMcpServer, parseToolScope, type ToolScope } from "../../shared/tool-scope.ts";
@@ -708,7 +709,10 @@ export async function mountChatTools(integrations: SendTurnInput["integrations"]
if (!tool) throw new Error("The requested tool was not advertised for this turn");
if (selectionExcludes(tool, args)) throw new Error("Tool selection excludes this tool");
omitBlankDefaults(tool.builtInBrowser, tool.name, args);
- if (!object(args) || (!(tool.searched && isDirectoryTool(tool.name)) && !tool.schema(args))) throw new Error(ARGUMENTS_MISFIT);
+ if (!object(args) || (!(tool.searched && isDirectoryTool(tool.name)) && !tool.schema(args))) {
+ // agent-browser's read hides `url`; name the way to read an address instead of the bare schema misfit.
+ throw new Error(tool.builtInBrowser && readsAroundBrowser({ name: tool.name, arguments: args }) ? READ_OPEN_PAGE_ONLY : ARGUMENTS_MISFIT);
+ }
};
const viewOf = (tool: RegisteredTool, args: Record<string, unknown>, title: string): ChatToolCallView => {
const runs = target(tool, args);