Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/docs/docs.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
"v4/integrations/overview",
"v4/integrations/claude-code",
"v4/integrations/codex",
"v4/integrations/cursor",
"v4/integrations/eve",
"v4/integrations/deep-agents",
"v4/integrations/crewai",
Expand Down
12 changes: 12 additions & 0 deletions packages/docs/images/integrations/cursor.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
101 changes: 101 additions & 0 deletions packages/docs/v4/integrations/cursor.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
---
title: "Cursor"
description: "Give a local Cursor SDK agent persistent Stagehand browser tools over MCP/stdio."
---

The Cursor integration creates a local agent through `@cursor/sdk` and mounts the Stagehand facade as one MCP/stdio server. One Cursor agent and one facade process own the browser across `run`, `snapshot`, and `screenshot` calls, preserving page state and snapshot IDs.

<Note>
Stagehand ships this experimental integration from the repository rather than publishing it as a standalone adapter.
</Note>

## Prerequisites

- Node.js 24 or newer
- pnpm 11.10.0
- A Cursor user or service-account API key
- A current Google Chrome installation for local browser mode

## Quickstart

<Steps>
<Step title="Clone and build Stagehand">
```bash
git clone https://github.com/browserbase/stagehand.git
cd stagehand
pnpm install --frozen-lockfile
pnpm exec turbo run build \
--filter @browserbasehq/stagehand-integrations
```
</Step>
<Step title="Authenticate Cursor">
Create a user API key in the Cursor dashboard or a service-account key in your team settings, then export it:

```bash
export CURSOR_API_KEY="your-cursor-api-key"
```

The example uses `composer-2.5` by default. Set `CURSOR_STAGEHAND_MODEL` to another model ID available to your Cursor account when needed.
</Step>
<Step title="Choose the browser">
The example defaults to Browserbase when `BROWSERBASE_API_KEY` is set, otherwise it uses local Chrome:

```bash
export STAGEHAND_BROWSER="browserbase"
export BROWSERBASE_API_KEY="your-browserbase-api-key"
```
</Step>
<Step title="Run a browser task">
```bash
pnpm --dir packages/integrations/cursor start -- \
"Open https://example.com, snapshot it, and report the heading."
```
</Step>
</Steps>

## Configuration

| Variable | Purpose |
| --- | --- |
| `CURSOR_API_KEY` | Cursor user or service-account key. The example does not forward it to the MCP child. |
| `CURSOR_STAGEHAND_MODEL` | Optional Cursor model ID; defaults to `composer-2.5`. |
| `STAGEHAND_BROWSER` | Select `local` or `browserbase`. Defaults to Browserbase when `BROWSERBASE_API_KEY` is set, otherwise local. |
| `BROWSERBASE_API_KEY` | Required for Browserbase. |
| `BROWSERBASE_PROJECT_ID` | Optional Browserbase project ID. |
| `STAGEHAND_MODEL_NAME` | Optional model for Stagehand AI methods called inside `run`. |
| `STAGEHAND_MODEL_API_KEY` | Required with `STAGEHAND_MODEL_NAME`. |

## SDK and session lifecycle

This V1 integration uses Cursor's local runtime. The agent loop and temporary workspace run locally, while Cursor hosts model inference. Cursor Cloud requires a remotely reachable MCP server and is not part of this example.

The example creates an isolated temporary workspace, disables ambient Cursor setting sources, and enables only Cursor's `mcp` capability group. Its only inline server is the Stagehand facade, so the model receives `run`, `snapshot`, and `screenshot` without shell, file-editing, user MCP, or project MCP tools. The example prefixes the canonical Stagehand tool instructions to the task because the main Cursor agent API does not expose a separate system-prompt option.

The facade process remains attached to one Cursor agent for the full run. On completion or failure, the example disposes the agent and deletes its temporary workspace. `SIGINT` and `SIGTERM` first cancel the active run so in-flight MCP calls stop cleanly.

Only non-empty `STAGEHAND_*` and `BROWSERBASE_*` variables cross into the MCP child. The Cursor API key and unrelated host secrets remain in the agent process.

## Connect a running Cursor CLI

The package ships a project-scoped `.cursor/mcp.json` that mounts the Stagehand facade MCP server in the Cursor CLI. Its `args` path is relative to the package, so start the CLI from that directory:

```bash
cd packages/integrations/cursor
agent mcp list
agent mcp list-tools stagehand
agent
```

Cursor inherits your shell environment, so the exports above are the only configuration. For a headless one-shot run, approve the configured MCP server so tool calls do not wait for an interactive prompt:

```bash
agent -p --approve-mcps "your instruction"
```

<Warning>
`run` executes model-authored JavaScript in the browser. Use Browserbase for untrusted tasks and review the [integration security boundary](/v4/integrations/overview#security-boundary).
</Warning>

<Card title="Cursor integration source" icon="github" href="https://github.com/browserbase/stagehand/tree/main/packages/integrations/cursor">
Read the isolated Cursor agent setup, MCP mount, lifecycle handling, and unit tests.
</Card>
9 changes: 6 additions & 3 deletions packages/docs/v4/integrations/overview.mdx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
title: "Integrations"
sidebarTitle: "Overview"
description: "Connect Claude Code, Codex, CrewAI, Deep Agents, Eve, Mastra, fx, Pi, or the Vercel AI SDK to a persistent Stagehand browser."
description: "Connect Claude Code, Codex, Cursor, CrewAI, Deep Agents, Eve, Mastra, fx, Pi, or the Vercel AI SDK to a persistent Stagehand browser."
---

Each integration gives your agent one persistent browser and three tools: `run`, `snapshot`, and `screenshot`. Your agent decides how to navigate and interact while Stagehand manages the browser session.
Expand All @@ -19,6 +19,9 @@ Stagehand ships these experimental integrations from the monorepo and does not p
<Card title="Codex" icon="/images/integrations/codex.svg" href="/v4/integrations/codex">
Give a Codex agent persistent Stagehand browser tools over MCP/stdio.
</Card>
<Card title="Cursor" icon="/images/integrations/cursor.svg" href="/v4/integrations/cursor">
Give a local Cursor SDK agent persistent Stagehand browser tools over MCP/stdio.
</Card>
<Card title="Eve by Vercel" icon="/images/integrations/eve.svg" href="/v4/integrations/eve">
Give Vercel's framework for building durable agents native Stagehand tools.
</Card>
Expand Down Expand Up @@ -78,7 +81,7 @@ Every integration exposes the same browser capabilities.

The tools share a browser for the lifetime of the integration's client session. A navigation performed by `run` is visible to the next `snapshot`, and authentication and page state remain available across calls.

The Claude Code, Codex, CrewAI, Mastra, fx, Vercel AI SDK, and local Deep Agents examples keep one MCP client session open so the stdio server and browser stay alive. Eve, Pi, and Managed Deep Agents bind equivalent tools in-process.
The Claude Code, Codex, Cursor, CrewAI, Mastra, fx, Vercel AI SDK, and local Deep Agents examples keep one MCP client session open so the stdio server and browser stay alive. Eve, Pi, and Managed Deep Agents bind equivalent tools in-process.

The private [`core/` workspace package](https://github.com/browserbase/stagehand/tree/main/packages/integrations/core) owns the shared TypeScript tool contract, browser runtime, native bindings, and stdio MCP server. The TypeScript integrations and CrewAI use this package.

Expand All @@ -88,7 +91,7 @@ Do not create a new MCP process for every tool call. Doing so starts a new brows

## Run the integrations from source

Claude Code, Codex, CrewAI, Mastra, fx, and the Vercel AI SDK use the shared TypeScript Stagehand facade MCP server. Eve and Pi use native in-process bindings from the same package. These integrations require Node.js 24 or newer and [pnpm](https://pnpm.io/installation) 11.10.0. CrewAI also requires Python 3.11–3.13 and [uv](https://docs.astral.sh/uv/).
Claude Code, Codex, Cursor, CrewAI, Mastra, fx, and the Vercel AI SDK use the shared TypeScript Stagehand facade MCP server. Eve and Pi use native in-process bindings from the same package. These integrations require Node.js 24 or newer and [pnpm](https://pnpm.io/installation) 11.10.0. CrewAI also requires Python 3.11–3.13 and [uv](https://docs.astral.sh/uv/).

<Steps>
<Step title="Clone and install Stagehand">
Expand Down
1 change: 1 addition & 0 deletions packages/integrations/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ else, never restated.
| `claude-code/` | Claude Agent SDK example (programmatic MCP mount) plus a `.mcp.json` for connecting a running Claude Code CLI. |
| `codex/` | Codex SDK example (config-override MCP mount) plus a `config.toml` template for the codex CLI. |
| `crewai/` | Python CrewAI example over MCP/stdio (uv project). |
| `cursor/` | Cursor SDK example over MCP/stdio via the Cursor Agent SDK. |
| `deepagents/` | Python LangChain Deep Agents integrations: a local stdio MCP server and a Managed Deep Agents project with native tools. |
| `eve/` | Eve example with the tools bound natively via `defineTool` (Eve has no external-process tool mounting). |
| `fx/` | fx configuration templates and skill — fx consumes the facade via its user-global MCP config. |
Expand Down
8 changes: 8 additions & 0 deletions packages/integrations/cursor/.cursor/mcp.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"mcpServers": {
"stagehand": {
"command": "node",
"args": ["../core/dist/facade/stdio-server.mjs"]
Comment thread
antonvishal marked this conversation as resolved.
}
}
}
87 changes: 87 additions & 0 deletions packages/integrations/cursor/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
# Cursor SDK + Stagehand facade over MCP/stdio

A runnable example embedding Cursor through `@cursor/sdk`, with the Stagehand facade
(`run` / `snapshot` / `screenshot`) mounted as the local agent's only MCP server. One Cursor
agent and one facade process stay alive for the full task, so browser state and snapshot IDs
survive across tool calls.

## Setup

Use Node.js 24 or later. From the repository root, install dependencies and build the shared
integration package:

```bash
pnpm install
Comment thread
antonvishal marked this conversation as resolved.
pnpm exec turbo run build --filter @browserbasehq/stagehand-integrations
```

Export a Cursor user or service-account API key. Browserbase is the recommended browser backend
for untrusted tasks:

```bash
export CURSOR_API_KEY=key_...
export BROWSERBASE_API_KEY=bb_live_...
export BROWSERBASE_PROJECT_ID=...
```

## Run

With local Chrome:

```bash
STAGEHAND_BROWSER=local pnpm --dir packages/integrations/cursor start -- \
"Open https://example.com, snapshot it, and report the heading."
```

With Browserbase:

```bash
STAGEHAND_BROWSER=browserbase pnpm --dir packages/integrations/cursor start -- \
"Open https://example.com, take a screenshot, and report the page title."
```

| Variable | Purpose |
| ------------------------- | -------------------------------------------------------------------------------------------- |
| `CURSOR_API_KEY` | Cursor user or service-account key. Never forwarded to the browser process. |
| `CURSOR_STAGEHAND_MODEL` | Optional Cursor model ID. Defaults to `composer-2.5`. |
| `STAGEHAND_BROWSER` | Browser backend. Defaults to Browserbase when `BROWSERBASE_API_KEY` is set, otherwise local. |
| `BROWSERBASE_API_KEY` | Browserbase credential for the browser session. |
| `BROWSERBASE_PROJECT_ID` | Optional Browserbase project. |
| `STAGEHAND_MODEL_NAME` | Optional model for Stagehand AI methods called inside `run`. |
| `STAGEHAND_MODEL_API_KEY` | Credential for `STAGEHAND_MODEL_NAME`. |

This example intentionally uses Cursor's local agent runtime. "Local" means the agent loop and
workspace run on your machine; model inference remains hosted by Cursor. The temporary workspace
loads no ambient Cursor settings, and the agent's built-in tool allowlist contains only the `mcp`
capability. Its one inline MCP server is the Stagehand facade, so Cursor does not offer shell and
file-editing tools to the model.

The MCP child receives only non-empty `STAGEHAND_*` and `BROWSERBASE_*` variables. The Cursor API
key and unrelated host secrets remain in the agent process. `SIGINT` and `SIGTERM` cancel the
active Cursor run before the agent, MCP process, and temporary workspace are cleaned up.

## Connecting a running Cursor CLI instead

To use the facade from the interactive `agent` CLI rather than the SDK, the project-scoped
`.cursor/mcp.json` in this directory is all that's needed. Cursor automatically discovers it and
inherits the Stagehand and Browserbase exports above. Start the CLI from this directory:

```bash
cd packages/integrations/cursor
agent mcp list
agent mcp list-tools stagehand
agent
```

For a headless one-shot run, approve the configured MCP server so tool calls do not wait for an
interactive prompt:

```bash
agent -p --approve-mcps "your instruction"
```

## Security model

The `run` tool executes model-authored JavaScript inside the Stagehand browser extension's service
worker, not in the Cursor agent process. Browserbase is the recommended isolation boundary: the
privileged execution environment is a disposable cloud browser.
24 changes: 24 additions & 0 deletions packages/integrations/cursor/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"name": "@browserbasehq/stagehand-integrations-example-cursor-facade",
"version": "4.0.1",
"private": true,
"type": "module",
"scripts": {
"start": "node src/agent.ts",
"test": "pnpm -w exec turbo run build --filter @browserbasehq/stagehand-integrations && vitest run",
"test:unit": "vitest run",
"typecheck": "tsc --noEmit"
},
"dependencies": {
"@browserbasehq/stagehand-integrations": "workspace:*",
"@cursor/sdk": "catalog:"
},
"devDependencies": {
"@types/node": "catalog:",
"typescript": "catalog:",
"vitest": "catalog:"
},
"engines": {
"node": ">=24"
}
}
Loading
Loading