Skip to content

feat(integrations): Mastra example (MCP over stdio) - #2679

Merged
shrey150 merged 21 commits into
mainfrom
miguel/facade-mastra-example
Aug 10, 2026
Merged

feat(integrations): Mastra example (MCP over stdio)#2679
shrey150 merged 21 commits into
mainfrom
miguel/facade-mastra-example

Conversation

@miguelg719

@miguelg719 miguelg719 commented Aug 10, 2026

Copy link
Copy Markdown
Collaborator

Mastra example for the Stagehand facade tool surface, consuming it as a standard MCP server over stdio.

  • Tools: run / snapshot / screenshot — the shared facade contract; system prompt from FACADE_AGENT_INSTRUCTIONS.
  • Transport: Mastra MCPClient + stdio, spawning the workspace stagehand-facade bin with an env allowlist (STAGEHAND_*/BROWSERBASE_* only); client.disconnect() in finally.
  • Run: 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.

@changeset-bot

changeset-bot Bot commented Aug 10, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 24f36e8

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@socket-security

socket-security Bot commented Aug 10, 2026

Copy link
Copy Markdown

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Addednpm/​@​mastra/​core@​1.57.06610093100100
Addednpm/​@​mastra/​mcp@​1.15.1981008310080

View full report

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread packages/integrations/mastra/src/agent.ts
Comment thread packages/integrations/mastra/src/client.ts
Comment thread packages/integrations/mastra/src/agent.ts Outdated
Comment thread packages/integrations/mastra/README.md
…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.
@miguelg719
miguelg719 requested a review from a team as a code owner August 10, 2026 07:12
…ol surface

Rebased onto main post-v4-release (squashed; original review + smoke
history on PR #2679).
@miguelg719
miguelg719 force-pushed the miguel/facade-mastra-example branch from 59ede76 to da72831 Compare August 10, 2026 07:15
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

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 5 files (changes from recent commits).

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread packages/integrations/mastra/src/agent.ts
Comment thread packages/integrations/mastra/tests/client.test.ts
Comment thread packages/integrations/mastra/README.md

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Comment thread packages/integrations/mastra/README.md Outdated
@miguelg719 miguelg719 changed the title feat(integrations): Mastra example (MCP over stdio) for the facade tool surface feat(integrations): Mastra example (MCP over stdio) Aug 10, 2026

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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>

@shrey150
shrey150 changed the base branch from miguel/facade-core to main August 10, 2026 16:04
@shrey150
shrey150 merged commit 45d1425 into main Aug 10, 2026
51 of 64 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants