feat(integrations): Mastra example (MCP over stdio) - #2679
Conversation
|
|
Review the following changes in direct dependencies. Learn more about Socket for GitHub.
|
There was a problem hiding this comment.
All reported issues were addressed
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
…screenshot) with stdio MCP host Promotes the playwrightCompatRuntime and the run/snapshot/screenshot tool contract from the facade experiment into packages/integrations as product code: contract.ts carries the reference tool definitions verbatim (schemas, descriptions, error strings), tools.ts adapts StagehandFacadeTools to a live Stagehand handle with per-page snapshot state and a serialized call queue, and a new stagehand-facade stdio bin exposes the three tools over MCP with screenshots as image content blocks.
AI-SDK-based MCP clients (Eve, Vercel AI SDK) reject tool input schemas with a top-level oneOf, failing every run call client-side before it reaches the server. The code/actions exclusivity stays in the tool description and is enforced at runtime by CodeModeRunInputSchema.
Native consumers (Eve defineTool, Vercel AI SDK tools) need direct access to StagehandFacadeTools and the pinned contract, not just the stdio bin.
- widen credential redaction (Browserbase, Google, bearer tokens) - bound shutdown against an in-flight launch (5s race) - surface unsupported model names as StagehandFacadeConfigError - only forward integral jpeg quality to page.screenshot - fail waitForOutput fast when the host exits before ready
One system prompt shared by every host example instead of three hand-authored variants.
…mples packages/integrations/ becomes a grouping directory: core/ is the @browserbasehq/stagehand-integrations package, and integration examples (deepagents, eve, vercel-ai) sit beside it. Fixes eve dev's snapshot EINVAL: eve copies a workspace dependency's package root, which previously contained the eve example itself.
9010314 to
6ab64c8
Compare
…ol surface Rebased onto main post-v4-release (squashed; original review + smoke history on PR #2679).
59ede76 to
da72831
Compare
The protocol commits on this branch updated the schema without running the Python generator; CI's generate.py --check caught the drift.
The Gemini 3.6 Flash protocol change on this branch made the Go-embedded extension stale (extensionpack --check and the wheel-smoke build both fail on it). The docs sdk-reference parity test times out at its 5s default on cold PR runners (observed 5090ms) — give the multi-language surface extraction a real budget.
- README start command no longer injects a literal -- (usage string and argv handling updated to match) - README env claim corrected: MCP transport defaults are also inherited - turbo typecheck entry so CI typechecks the package - allowlist helper extracted and tested for exclusion; contract assertions now compare against FACADE_TOOLS instead of copied literals
There was a problem hiding this comment.
All reported issues were addressed across 5 files (changes from recent commits).
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
There was a problem hiding this comment.
All reported issues were addressed across 2 files (changes from recent commits).
Tip: Review your code locally with the cubic CLI to iterate faster.
Re-trigger cubic
There was a problem hiding this comment.
1 issue found across 2 files (changes from recent commits).
Confidence score: 3/5
- In
packages/integrations/mastra/src/agent.ts, a disconnect failure after a successful run still returns a success exit status, so CI/scripts can report a pass while leaving the facade process uncleanly shut down; this risks hidden resource leaks and flaky follow-on jobs — set a nonzero exit code when disconnect/cleanup fails after logging the error.
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="packages/integrations/mastra/src/agent.ts">
<violation number="1" location="packages/integrations/mastra/src/agent.ts:43">
P2: A disconnect failure after a successful agent run is reported but still exits successfully, so scripts/CI can treat a leaked or uncleanly shut down facade process as a pass. Set a nonzero exit code after logging cleanup-only failures while retaining the catch so an agent failure is not replaced.</violation>
</file>
Tip: Review your code locally with the cubic CLI to iterate faster.
Re-trigger cubic
| await client.disconnect(); | ||
| } catch (disconnectError: unknown) { | ||
| // oxlint-disable-next-line no-console -- CLI example warns about cleanup failures without masking the original error. | ||
| console.error( |
There was a problem hiding this comment.
P2: A disconnect failure after a successful agent run is reported but still exits successfully, so scripts/CI can treat a leaked or uncleanly shut down facade process as a pass. Set a nonzero exit code after logging cleanup-only failures while retaining the catch so an agent failure is not replaced.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At packages/integrations/mastra/src/agent.ts, line 43:
<comment>A disconnect failure after a successful agent run is reported but still exits successfully, so scripts/CI can treat a leaked or uncleanly shut down facade process as a pass. Set a nonzero exit code after logging cleanup-only failures while retaining the catch so an agent failure is not replaced.</comment>
<file context>
@@ -36,7 +36,14 @@ async function main() {
+ await client.disconnect();
+ } catch (disconnectError: unknown) {
+ // oxlint-disable-next-line no-console -- CLI example warns about cleanup failures without masking the original error.
+ console.error(
+ `Warning: failed to disconnect MCP client: ${disconnectError instanceof Error ? disconnectError.message : String(disconnectError)}`,
+ );
</file context>
Mastra example for the Stagehand facade tool surface, consuming it as a standard MCP server over stdio.
run/snapshot/screenshot— the shared facade contract; system prompt fromFACADE_AGENT_INSTRUCTIONS.MCPClient+ stdio, spawning the workspacestagehand-facadebin with an env allowlist (STAGEHAND_*/BROWSERBASE_*only);client.disconnect()infinally.packages/integrations/mastra/README.md.Verified: contract test in CI; Browserbase smoke passed ("Heading (from snapshot [0-19]): Example Domain", no zombie processes).
Stacked on #2665.