Skip to content

docs(mastra): use Mastra’s supported integration setup - #2973

Open
shrey150 wants to merge 4 commits into
integrations/claude-pluginfrom
integrations/mastra-setup
Open

shrey150 wants to merge 4 commits into
integrations/claude-pluginfrom
integrations/mastra-setup

Conversation

@shrey150

@shrey150 shrey150 commented Sep 17, 2026

Copy link
Copy Markdown
Collaborator

The Mastra integration already has a supported host tool API: MCPClient. Lead the public guide with that integration route and a portable configuration for an existing application, instead of requiring a full Stagehand checkout.

This is an SDK/MCP integration, not a separate marketplace plugin. The source example remains available.

Stacked on #2971 for the shared @browserbasehq/stagehand-mcp package. The first 0.1.0 release is required before the portable npm command is available; the guide explicitly identifies this prerequisite.

E2E Test Matrix

Command / flow Observed output Confidence / sufficiency
Host-specific example/config check TypeScript example typecheck passed; real Mastra client discovered stagehand_run, stagehand_snapshot, and stagehand_screenshot from the locally packed server and disconnected. Host contract and configuration; no full model-loop benchmark claimed
Shared packed MCP server from #2971 Real Browserbase navigation, persistent snapshot, JPEG, and shutdown passed on example.com Shared browser implementation; npm download awaits publication

Documentation validation: a combined snapshot of all nine updated integration guides passed mint validate and mint broken-links --check-anchors --check-redirects --check-snippets.

@shrey150
shrey150 requested a review from a team as a code owner September 17, 2026 22:30
@changeset-bot

changeset-bot Bot commented Sep 17, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 11b7221

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

@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.

6 issues found and verified against the latest diff

Confidence score: 4/5

  • In packages/docs/v4/integrations/mastra.mdx, the finally cleanup can let a rejecting disconnect() hide the original discovery or agent-generation failure, making diagnosis misleading—catch cleanup errors while preserving and reporting the primary failure.
  • In packages/docs/v4/integrations/mastra.mdx, the claim that only browser configuration crosses the boundary conflicts with forwarding every STAGEHAND_* variable, including STAGEHAND_MODEL_API_KEY, which could mislead users about credential exposure—document the complete allowlist and model-key handling.
  • The integration documentation in packages/docs/v4/integrations/mastra.mdx and packages/integrations/mastra/README.md uses inconsistent or passive descriptions and leaves the runtime/package implicit; name the Stagehand facade MCP server and @browserbasehq/stagehand-mcp@0.1.0, and revise the prose to identify the actor clearly.
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/README.md">

<violation number="1" location="packages/integrations/mastra/README.md:5">
P3: The new route leaves the runtime and npm package implicit by calling it only a “packaged MCP server.” Name the Stagehand facade MCP server and `@browserbasehq/stagehand-mcp@0.1.0` here so this README matches the launched process and linked setup.

(Based on your team's feedback about precise facade runtime names in MCP integration docs.)</violation>

<violation number="2" location="packages/integrations/mastra/README.md:5">
P2: Custom agent: **Stagehand docs prose guide**

The added sentence uses passive voice: “No separate host marketplace plugin is needed.” Rewrite it as “You don’t need a separate host marketplace plugin.”</violation>
</file>

<file name="packages/docs/v4/integrations/mastra.mdx">

<violation number="1" location="packages/docs/v4/integrations/mastra.mdx:9">
P3: Use `Stagehand facade MCP server` here instead of `packaged server` so this guide identifies the actual child runtime consistently with the other MCP integration docs.</violation>

<violation number="2" location="packages/docs/v4/integrations/mastra.mdx:9">
P2: Custom agent: **Stagehand docs prose guide**

Use active voice and name the actor in these added sentences: “Stagehand maintains the source example in its repository” and “You forward only browser configuration to the MCP child.”</violation>

<violation number="3" location="packages/docs/v4/integrations/mastra.mdx:26">
P2: Although this sentence says only browser configuration crosses the boundary, the filter forwards every `STAGEHAND_*` variable, including `STAGEHAND_MODEL_API_KEY`. State the full allowlist and explain that Stagehand model credentials are separate from the agent credential, or narrow the filter.</violation>

<violation number="4" location="packages/docs/v4/integrations/mastra.mdx:64">
P2: When discovery or agent generation fails and `disconnect()` also rejects, this `finally` replaces the primary error with the cleanup failure. Catch and report disconnect errors while preserving the original failure.</violation>
</file>

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

Re-trigger cubic

pnpm add @mastra/core @mastra/mcp
```

Configure your agent’s model credentials as usual. The browser uses local Chrome unless you export `BROWSERBASE_API_KEY`. Only browser configuration is forwarded to the MCP child.

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: Although this sentence says only browser configuration crosses the boundary, the filter forwards every STAGEHAND_* variable, including STAGEHAND_MODEL_API_KEY. State the full allowlist and explain that Stagehand model credentials are separate from the agent credential, or narrow the filter.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At packages/docs/v4/integrations/mastra.mdx, line 26:

<comment>Although this sentence says only browser configuration crosses the boundary, the filter forwards every `STAGEHAND_*` variable, including `STAGEHAND_MODEL_API_KEY`. State the full allowlist and explain that Stagehand model credentials are separate from the agent credential, or narrow the filter.</comment>

<file context>
@@ -6,17 +6,75 @@ description: "Give a Mastra agent persistent Stagehand browser tools over MCP/st
+pnpm add @mastra/core @mastra/mcp
+```
+
+Configure your agent’s model credentials as usual. The browser uses local Chrome unless you export `BROWSERBASE_API_KEY`. Only browser configuration is forwarded to the MCP child.
+
+```typescript
</file context>
Suggested change
Configure your agent’s model credentials as usual. The browser uses local Chrome unless you export `BROWSERBASE_API_KEY`. Only browser configuration is forwarded to the MCP child.
Configure your agent’s model credentials as usual. The browser uses local Chrome unless you export `BROWSERBASE_API_KEY`. The MCP child receives exported `STAGEHAND_*` and `BROWSERBASE_*` variables, including separate Stagehand model credentials when configured.

});
console.log(result.text);
} finally {
await client.disconnect();

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: When discovery or agent generation fails and disconnect() also rejects, this finally replaces the primary error with the cleanup failure. Catch and report disconnect errors while preserving the original failure.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At packages/docs/v4/integrations/mastra.mdx, line 64:

<comment>When discovery or agent generation fails and `disconnect()` also rejects, this `finally` replaces the primary error with the cleanup failure. Catch and report disconnect errors while preserving the original failure.</comment>

<file context>
@@ -6,17 +6,75 @@ description: "Give a Mastra agent persistent Stagehand browser tools over MCP/st
+  });
+  console.log(result.text);
+} finally {
+  await client.disconnect();
+}
+```
</file context>
Suggested change
await client.disconnect();
await client.disconnect().catch((disconnectError) => {
console.error(
`Warning: failed to disconnect MCP client: ${disconnectError instanceof Error ? disconnectError.message : String(disconnectError)}`,
);
});

Comment thread packages/integrations/mastra/README.md Outdated

## Supported integration route

Use `MCPClient` from `@mastra/mcp`, as described in the [official Mastra documentation](https://mastra.ai/docs/agents/tools). No separate host marketplace plugin is needed. The [Stagehand guide](https://docs.stagehand.dev/v4/integrations/mastra#add-stagehand-to-an-existing-agent) includes a portable setup using the packaged MCP server, pending its first 0.1.0 release. The source example below remains available before publication.

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: Custom agent: Stagehand docs prose guide

The added sentence uses passive voice: “No separate host marketplace plugin is needed.” Rewrite it as “You don’t need a separate host marketplace plugin.”

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At packages/integrations/mastra/README.md, line 5:

<comment>The added sentence uses passive voice: “No separate host marketplace plugin is needed.” Rewrite it as “You don’t need a separate host marketplace plugin.”</comment>

<file context>
@@ -1,5 +1,10 @@
 
+## Supported integration route
+
+Use `MCPClient` from `@mastra/mcp`, as described in the [official Mastra documentation](https://mastra.ai/docs/agents/tools). No separate host marketplace plugin is needed. The [Stagehand guide](https://docs.stagehand.dev/v4/integrations/mastra#add-stagehand-to-an-existing-agent) includes a portable setup using the packaged MCP server, pending its first 0.1.0 release. The source example below remains available before publication.
+
+
</file context>


<Note>
Stagehand ships this experimental integration from the repository rather than publishing it as a standalone adapter.
The source example is maintained in the Stagehand repository. For an existing application, prefer the host’s MCP client and the packaged server described below.

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: Custom agent: Stagehand docs prose guide

Use active voice and name the actor in these added sentences: “Stagehand maintains the source example in its repository” and “You forward only browser configuration to the MCP child.”

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At packages/docs/v4/integrations/mastra.mdx, line 9:

<comment>Use active voice and name the actor in these added sentences: “Stagehand maintains the source example in its repository” and “You forward only browser configuration to the MCP child.”</comment>

<file context>
@@ -6,17 +6,75 @@ description: "Give a Mastra agent persistent Stagehand browser tools over MCP/st
 
 <Note>
-Stagehand ships this experimental integration from the repository rather than publishing it as a standalone adapter.
+The source example is maintained in the Stagehand repository. For an existing application, prefer the host’s MCP client and the packaged server described below.
 </Note>
 
</file context>

Comment thread packages/integrations/mastra/README.md Outdated

## Supported integration route

Use `MCPClient` from `@mastra/mcp`, as described in the [official Mastra documentation](https://mastra.ai/docs/agents/tools). No separate host marketplace plugin is needed. The [Stagehand guide](https://docs.stagehand.dev/v4/integrations/mastra#add-stagehand-to-an-existing-agent) includes a portable setup using the packaged MCP server, pending its first 0.1.0 release. The source example below remains available before publication.

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.

P3: The new route leaves the runtime and npm package implicit by calling it only a “packaged MCP server.” Name the Stagehand facade MCP server and @browserbasehq/stagehand-mcp@0.1.0 here so this README matches the launched process and linked setup.

(Based on your team's feedback about precise facade runtime names in MCP integration docs.)

View Feedback

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At packages/integrations/mastra/README.md, line 5:

<comment>The new route leaves the runtime and npm package implicit by calling it only a “packaged MCP server.” Name the Stagehand facade MCP server and `@browserbasehq/stagehand-mcp@0.1.0` here so this README matches the launched process and linked setup.

(Based on your team's feedback about precise facade runtime names in MCP integration docs.) </comment>

<file context>
@@ -1,5 +1,10 @@
 
+## Supported integration route
+
+Use `MCPClient` from `@mastra/mcp`, as described in the [official Mastra documentation](https://mastra.ai/docs/agents/tools). No separate host marketplace plugin is needed. The [Stagehand guide](https://docs.stagehand.dev/v4/integrations/mastra#add-stagehand-to-an-existing-agent) includes a portable setup using the packaged MCP server, pending its first 0.1.0 release. The source example below remains available before publication.
+
+
</file context>
Suggested change
Use `MCPClient` from `@mastra/mcp`, as described in the [official Mastra documentation](https://mastra.ai/docs/agents/tools). No separate host marketplace plugin is needed. The [Stagehand guide](https://docs.stagehand.dev/v4/integrations/mastra#add-stagehand-to-an-existing-agent) includes a portable setup using the packaged MCP server, pending its first 0.1.0 release. The source example below remains available before publication.
Use `MCPClient` from `@mastra/mcp`, as described in the [official Mastra documentation](https://mastra.ai/docs/agents/tools). No separate host marketplace plugin is needed. The [Stagehand guide](https://docs.stagehand.dev/v4/integrations/mastra#add-stagehand-to-an-existing-agent) includes a portable setup using the packaged Stagehand facade MCP server (`@browserbasehq/stagehand-mcp@0.1.0`), pending its first release. The source example below remains available before publication.


<Note>
Stagehand ships this experimental integration from the repository rather than publishing it as a standalone adapter.
The source example is maintained in the Stagehand repository. For an existing application, prefer the host’s MCP client and the packaged server described below.

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.

P3: Use Stagehand facade MCP server here instead of packaged server so this guide identifies the actual child runtime consistently with the other MCP integration docs.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At packages/docs/v4/integrations/mastra.mdx, line 9:

<comment>Use `Stagehand facade MCP server` here instead of `packaged server` so this guide identifies the actual child runtime consistently with the other MCP integration docs.</comment>

<file context>
@@ -6,17 +6,75 @@ description: "Give a Mastra agent persistent Stagehand browser tools over MCP/st
 
 <Note>
-Stagehand ships this experimental integration from the repository rather than publishing it as a standalone adapter.
+The source example is maintained in the Stagehand repository. For an existing application, prefer the host’s MCP client and the packaged server described below.
 </Note>
 
</file context>
Suggested change
The source example is maintained in the Stagehand repository. For an existing application, prefer the host’s MCP client and the packaged server described below.
The source example is maintained in the Stagehand repository. For an existing application, prefer the host’s MCP client and the Stagehand facade MCP server described below.

@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.

2 issues found across 2 files

Confidence score: 3/5

  • packages/docs/v4/integrations/mastra.mdx documents an OpenAI credential while the model string routes through Mastra’s gateway, so users may see authentication failures or requests sent through the wrong provider—import openai from @ai-sdk/openai and install it, or document the required gateway credential.
  • packages/docs/v4/integrations/mastra.mdx uses a fixed client ID, allowing multiple clients in one process to reuse or disconnect each other and terminate MCP/browser sessions—generate a unique ID for each client.
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/docs/v4/integrations/mastra.mdx">

<violation number="1" location="packages/docs/v4/integrations/mastra.mdx:40">
P2: When an application creates multiple clients in one process, this fixed ID lets `@mastra/mcp` reuse or disconnect another client, terminating its MCP/browser session. Generate a unique ID for each client or explicitly share one singleton client.</violation>

<violation number="2" location="packages/docs/v4/integrations/mastra.mdx:56">
P1: With the documented OpenAI credential, this model string routes through Mastra’s gateway instead of the OpenAI provider. Import `openai` from `@ai-sdk/openai` and install it, or document the required gateway credential.</violation>
</file>
Architecture diagram
sequenceDiagram
    participant User as User/Agent
    participant Mastra as Mastra Agent
    participant MCPClient as MCPClient (@mastra/mcp)
    participant MCP as @browserbasehq/stagehand-mcp
    participant Browserbase as Browserbase
    participant Chrome as Local Chrome

    Note over User,Chrome: Current State Architecture

    User->>Mastra: generate("Open example.com...")
    Mastra->>MCPClient: listTools()
    MCPClient->>MCP: Spawn process (npx -y @browserbasehq/stagehand-mcp@0.1.0)
    Note over MCPClient,MCP: stdio transport (MCP protocol)
    MCP-->>MCPClient: Run, Snapshot, Screenshot tools
    MCPClient-->>Mastra: Tool list
    Mastra->>MCP: run(url="https://example.com")
    alt BROWSERBASE_API_KEY set
        MCP->>Browserbase: Remote browser session
        Browserbase-->>MCP: Page snapshot
    else Local Chrome
        MCP->>Chrome: Local browser session
        Chrome-->>MCP: Page snapshot
    end
    MCP-->>Mastra: Result content
    Mastra->>MCP: snapshot()
    MCP-->>Mastra: Page state
    Mastra->>MCP: screenshot()
    MCP-->>Mastra: Screenshot JPEG
    Mastra-->>User: Final response
    Note over Mastra,MCP: Connection stays open through agent run
    Mastra->>MCPClient: disconnect()
    MCPClient->>MCP: Shutdown / kill process
Loading

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

Re-trigger cubic

id: "browser-agent",
name: "Browser agent",
instructions: "Use the Stagehand tools to browse. Take a snapshot before interacting with page elements.",
model: "openai/gpt-5.6-luna",

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.

P1: With the documented OpenAI credential, this model string routes through Mastra’s gateway instead of the OpenAI provider. Import openai from @ai-sdk/openai and install it, or document the required gateway credential.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At packages/docs/v4/integrations/mastra.mdx, line 56:

<comment>With the documented OpenAI credential, this model string routes through Mastra’s gateway instead of the OpenAI provider. Import `openai` from `@ai-sdk/openai` and install it, or document the required gateway credential.</comment>

<file context>
@@ -6,17 +6,75 @@ description: "Give a Mastra agent persistent Stagehand browser tools over MCP/st
+    id: "browser-agent",
+    name: "Browser agent",
+    instructions: "Use the Stagehand tools to browse. Take a snapshot before interacting with page elements.",
+    model: "openai/gpt-5.6-luna",
+    tools,
+  });
</file context>

),
);
const client = new MCPClient({
id: "stagehand-browser",

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: When an application creates multiple clients in one process, this fixed ID lets @mastra/mcp reuse or disconnect another client, terminating its MCP/browser session. Generate a unique ID for each client or explicitly share one singleton client.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At packages/docs/v4/integrations/mastra.mdx, line 40:

<comment>When an application creates multiple clients in one process, this fixed ID lets `@mastra/mcp` reuse or disconnect another client, terminating its MCP/browser session. Generate a unique ID for each client or explicitly share one singleton client.</comment>

<file context>
@@ -6,17 +6,75 @@ description: "Give a Mastra agent persistent Stagehand browser tools over MCP/st
+  ),
+);
+const client = new MCPClient({
+  id: "stagehand-browser",
+  servers: {
+    stagehand: {
</file context>

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.

1 participant