Skip to main content
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.
Stagehand ships this experimental integration from the repository rather than publishing it as a standalone adapter.

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

1

Clone and build Stagehand

2

Configure the Mastra agent

Set MASTRA_STAGEHAND_MODEL to select another model supported by the example.
3

Choose the browser

The example uses local Chrome by default. To use Browserbase instead:
4

Run a browser task

Configuration

Keep the browser session alive

The example creates one MCP client and one facade MCP server for the entire model loop. Preserve that lifetime if you adapt the integration; a new process per tool call starts a new browser. The MCP child receives only Stagehand and Browserbase configuration plus the process values required to launch Node. The host’s model credential remains in the Mastra process.
run executes model-authored JavaScript in the browser. Use Browserbase for untrusted tasks and review the integration security boundary.

Mastra integration source

Read the MCP client setup, agent prompt, and contract tests.