-
Notifications
You must be signed in to change notification settings - Fork 1.7k
docs(mastra): use Mastra’s supported integration setup #2973
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: integrations/claude-plugin
Are you sure you want to change the base?
Changes from all commits
341d031
5a08fb6
d41e272
11b7221
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -6,17 +6,75 @@ description: "Give a Mastra agent persistent Stagehand browser tools over MCP/st | |||||||||||||
| The Mastra integration connects an agent to the Stagehand facade MCP server over MCP/stdio. The MCP client remains open for the agent run, so browser state survives across tool calls. | ||||||||||||||
|
|
||||||||||||||
| <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 Stagehand facade MCP server described below. | ||||||||||||||
| </Note> | ||||||||||||||
|
|
||||||||||||||
| ## Add Stagehand to an existing agent | ||||||||||||||
|
|
||||||||||||||
| Use Mastra’s supported tool integration: `MCPClient` from `@mastra/mcp`. This is an [official SDK/MCP extension point](https://mastra.ai/docs/agents/tools); you do not need a separate host marketplace plugin. | ||||||||||||||
|
|
||||||||||||||
| <Note> | ||||||||||||||
| The portable setup below requires the first `@browserbasehq/stagehand-mcp@0.1.0` release. Until that release is published, use the source example further down this page. Node.js 24+ is required to run the MCP server. | ||||||||||||||
| </Note> | ||||||||||||||
|
|
||||||||||||||
| Install the host libraries in your application: | ||||||||||||||
|
|
||||||||||||||
| ```bash | ||||||||||||||
| 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`. The Mastra host forwards the `STAGEHAND_*` and `BROWSERBASE_*` variables to the MCP child, including any separate Stagehand model configuration. Your agent’s model-provider credential stays in the host. | ||||||||||||||
|
|
||||||||||||||
| ```typescript | ||||||||||||||
| import { MCPClient } from "@mastra/mcp"; | ||||||||||||||
| import { Agent } from "@mastra/core/agent"; | ||||||||||||||
|
|
||||||||||||||
| const env = Object.fromEntries( | ||||||||||||||
| Object.entries(process.env).filter( | ||||||||||||||
| (entry): entry is [string, string] => | ||||||||||||||
| (entry[0].startsWith("STAGEHAND_") || entry[0].startsWith("BROWSERBASE_")) && | ||||||||||||||
| entry[1] !== undefined, | ||||||||||||||
| ), | ||||||||||||||
| ); | ||||||||||||||
| const client = new MCPClient({ | ||||||||||||||
| id: "stagehand-browser", | ||||||||||||||
| servers: { | ||||||||||||||
| stagehand: { | ||||||||||||||
| command: "npx", | ||||||||||||||
| args: ["-y", "@browserbasehq/stagehand-mcp@0.1.0"], | ||||||||||||||
| env, | ||||||||||||||
| }, | ||||||||||||||
| }, | ||||||||||||||
| }); | ||||||||||||||
|
|
||||||||||||||
| try { | ||||||||||||||
| const tools = await client.listTools(); | ||||||||||||||
| const agent = new Agent({ | ||||||||||||||
| 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", | ||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 Prompt for AI agents |
||||||||||||||
| tools, | ||||||||||||||
| }); | ||||||||||||||
| const result = await agent.generate("Open https://example.com and report its title.", { | ||||||||||||||
| maxSteps: 20, | ||||||||||||||
| }); | ||||||||||||||
| console.log(result.text); | ||||||||||||||
| } finally { | ||||||||||||||
| await client.disconnect(); | ||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P2: When discovery or agent generation fails and Prompt for AI agents
Suggested change
|
||||||||||||||
| } | ||||||||||||||
| ``` | ||||||||||||||
|
|
||||||||||||||
| Keep the connection open until the entire agent run finishes. Closing it releases the server and its browser. | ||||||||||||||
|
|
||||||||||||||
| ## Prerequisites | ||||||||||||||
|
|
||||||||||||||
| - Node.js 24 or newer | ||||||||||||||
| - pnpm 11.10.0 | ||||||||||||||
| - An OpenAI API key for the example agent | ||||||||||||||
| - A current Google Chrome installation for local browser mode | ||||||||||||||
|
|
||||||||||||||
| ## Quickstart | ||||||||||||||
| ## Run the source example | ||||||||||||||
|
|
||||||||||||||
| <Steps> | ||||||||||||||
| <Step title="Clone and build Stagehand"> | ||||||||||||||
|
|
||||||||||||||
There was a problem hiding this comment.
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/mcpreuse 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