fix(integrations): harden fx facade discovery and screenshots - #2791
Merged
Conversation
|
Kylejeong2
approved these changes
Aug 20, 2026
Contributor
There was a problem hiding this comment.
All reported issues were addressed across 10 files
Architecture diagram
sequenceDiagram
participant Agent as AI Agent (fx)
participant Skill as Skill/AGENTS Docs
participant MCP as MCP Client (fx)
participant Server as MCP Server
participant Tool as Tool Registry
participant Facade as Stagehand Facade
participant Budget as Screenshot Budget Guard
participant Browser as Playwright Browser
Note over Agent,Browser: fx discovery flow - PR makes tool names deterministic
Agent->>Skill: Read AGENTS.md + stagehand-facade skill
Skill-->>Agent: Exact 3 tool names + usage patterns
Agent->>MCP: Select tools: mcp_stagehand_run/snapshot/screenshot
MCP->>Server: Initialize MCP stdio connection
Server->>Tool: Register 3 tools (run, snapshot, screenshot)
Tool-->>Agent: Confirm exact tool names
Note over Agent,Server: Snapshot flow (unchanged)
Agent->>MCP: call_tool(stagehand_snapshot)
MCP->>Server: CallToolRequest snapshot
Server->>Tool: tools.snapshot(request)
Tool-->>Server: Page snapshot with element IDs
Server-->>Agent: Snapshot result
Note over Agent,Server: Run / navigate flow - PR clarifies no separate navigate tool
Agent->>MCP: call_tool(stagehand_run) with page.goto()
MCP->>Server: CallToolRequest run
Server->>Tool: tools.run(request)
Tool->>Browser: Execute JavaScript / actions
Browser-->>Tool: Execution result
Tool-->>Server: Result
Server-->>Agent: Run result
Note over Agent,Server: Screenshot with optional budget guard
Agent->>MCP: call_tool(stagehand_screenshot)
MCP->>Server: CallToolRequest screenshot
alt Budget NOT configured (no CLI flag)
Server->>Tool: tools.screenshot(request)
Tool->>Browser: Capture screenshot
Browser-->>Tool: Image data
Tool-->>Server: Image data
Server-->>Agent: Screenshot (no compression)
else Budget configured (--max-screenshot-base64-bytes)
Server->>Budget: captureScreenshotWithinBase64Budget(request, budget)
Note over Budget: Uses requested options first
Budget->>Tool: Capture with requested options
Tool->>Browser: Screenshot capture (original opts)
Browser-->>Tool: Image data
Tool-->>Budget: Base64 result
alt Size exceeds budget
Budget->>Budget: Retry with viewport JPEG q40 → q25 → q10
Budget->>Tool: Capture retry (progressive compression)
Tool->>Browser: Screenshot (smaller JPEG)
Browser-->>Tool: Compressed image
Tool-->>Budget: Image data
Note over Budget: If still exceeds budget after all retries
Budget-->>Server: Throw error (small tool failure)
else Image fits budget
Budget-->>Server: Captured image
end
end
Server-->>Agent: Screenshot (image or error)
Note over MCP,Server: Response frame safety<br/>Raw screenshots can exceed fx MCP frame cap<br/>(separate from max_tool_result_bytes)
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
# why Add the public documentation for the fx integration introduced in #2776 and hardened in #2791. This PR is intentionally stacked on #2791 because the guide documents its deterministic discovery instructions and transport-safe screenshot mode. # what changed - add a complete fx integration guide following the existing v4 integration page structure - add the official fx mark as a local docs asset - add fx immediately after Mastra and before Pi in the integrations sidebar - add the fx overview card in the same Mastra → fx → Pi position - update overview lifecycle and source descriptions to include fx # test plan - pnpm --filter @browserbasehq/stagehand-docs test:unit (27 tests) - pnpm --filter @browserbasehq/stagehand-docs check - Mint build validation - broken links, anchors, redirects, and snippets - accessibility checks - pnpm exec oxfmt --check packages/docs/docs.json - git diff --check <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Adds a complete fx integration guide to the v4 docs, updates the overview and sidebar to include fx, and switches to the dark fx logo. This documents deterministic MCP tool discovery and a transport-safe screenshot mode to keep fx sessions stable. - Verify the fx page renders and all anchors, code blocks, and links resolve, including fx v0.0.3 references. - Confirm the dark fx SVG displays with correct alt/aria and matches other integration icons across themes. - Check sidebar ordering (Mastra → fx → Pi) and the updated overview card copy. - Merge only after the stdio facade exposes the `--max-screenshot-base64-bytes` flag and stable tool names; otherwise the guide will be inaccurate. <sup>Written for commit e9dfbe8. Summary will update on new commits.</sup> <a href="https://cubic.dev/pr/browserbase/stagehand/pull/2792?utm_source=github" target="_blank" rel="noopener noreferrer" data-no-image-dialog="true"><picture><source media="(prefers-color-scheme: dark)" srcset="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://www.cubic.dev/buttons/review-in-cubic-light.svg"><img alt="Review in cubic" src="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"></picture></a> <!-- End of auto-generated description by cubic. -->
antonvishal
added a commit
to antonvishal/stagehand
that referenced
this pull request
Aug 21, 2026
Resolve overview.mdx conflicts to include both Grok Build and fx entries. Keep the screenshot base64 budget from browserbase#2791 alongside the ACP facade launcher changes. Also pass --max-screenshot-base64-bytes=60000 to the facade spawned by the ACP launcher so ACP transports get the same frame-cap protection as fx, mark BROWSERBASE_PROJECT_ID optional in the Grok Build README per browserbase#2777, and update the affected ACP arg assertions.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
why
The fx harness added in #2776 can miss all three Stagehand tools during dynamic search and then invent legacy navigate tool names. Inline full-page PNG responses can also exceed the fx raw MCP frame cap before tool-result truncation runs, which closes the RPC connection.
what changed
test plan
Summary by cubic
Hardens fx Stagehand facade tool discovery and screenshot transport to prevent stalled runs and dropped MCP connections, and publishes a complete fx integration guide. Previously fx could return no tools and models invented legacy navigate names; full‑page PNG screenshots could exceed fx’s raw frame cap and close the connection. Now discovery is deterministic and screenshots respect a configurable base64 budget with safe, clamped JPEG retries.
packages/integrations/fx/AGENTS.md, theskills/stagehand-facadeskill, and new docs (/v4/integrations/fx) instruct agents to callmcp_stagehand_run,mcp_stagehand_snapshot, andmcp_stagehand_screenshotdirectly and navigate withawait page.goto(...).--max-screenshot-base64-bytes=...). The fx template sets--max-screenshot-base64-bytes=60000, defaults unspecified screenshots to a viewport JPEG (quality 40), retries with smaller JPEG qualities (40 → 25 → 10) without ever increasing a requested JPEG quality, and returns a small tool error if none fit. Docs clarify the raw response-frame cap vsmax_tool_result_bytes.--max-screenshot-base64-bytes=60000(or a suitable value) to the Stagehand MCP command; run fx frompackages/integrations/fxso it loads the project guidance; prefer{"type":"jpeg","quality":40,"fullPage":false}for screenshots.Written for commit 9c5d64a. Summary will update on new commits.