Skip to content

Commit e25ac1e

Browse files
author
Hanzo AI
committed
fix(browser): route MCP register through _result_to_mcp — ToolImage→ImageContent
The browser tool's bespoke register() returned execute()'s dict RAW, so FastMCP flat-JSON-serialized a screenshot's ToolImage (base64 inline, 250K chars) → overflowed the agent context and wedged the run — the SAME bug main's ImageContent converter (c8dfb45) fixed for every OTHER tool via BaseTool.register→_result_to_mcp, but the browser tool bypassed that path. Now both registration paths share the one converter: nested ToolImage anywhere in the result becomes a native MCP ImageContent block the client SEES. One way.
1 parent 7d44d89 commit e25ac1e

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

‎pkg/hanzo-tools-browser/hanzo_tools/browser/browser_tool.py‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
from mcp.server import FastMCP
3333

3434
from hanzo_tools.core import BaseTool, ToolImage
35+
from hanzo_tools.core.unified import _result_to_mcp
3536

3637
# Playwright import with graceful fallback
3738
try:
@@ -2508,9 +2509,13 @@ async def browser(
25082509
Optional[str], Field(description="Trace output")
25092510
] = None,
25102511
level: Annotated[Optional[str], Field(description="Console level")] = None,
2511-
) -> dict[str, Any]:
2512+
) -> Any:
25122513
"""Complete browser automation with full Playwright API surface area."""
2513-
return await tool_instance.execute(
2514+
# One way for images: route through the SAME converter BaseTool.register
2515+
# uses, so a screenshot's ToolImage becomes a native MCP ImageContent
2516+
# block the client SEES — never a 250K-char base64 blob flattened into
2517+
# JSON text (which overflows the agent context and wedges the run).
2518+
result = await tool_instance.execute(
25142519
action=action,
25152520
url=url,
25162521
selector=selector,
@@ -2570,6 +2575,7 @@ async def browser(
25702575
trace_path=trace_path,
25712576
level=level,
25722577
)
2578+
return _result_to_mcp(result)
25732579

25742580

25752581
def create_browser_tool(

0 commit comments

Comments
 (0)