feat(integrations): add Cursor SDK integration - #2771
Conversation
|
|
This PR is from an external contributor and must be approved by a stagehand team member with write access before CI can run. |
|
Review the following changes in direct dependencies. Learn more about Socket for GitHub.
|
There was a problem hiding this comment.
All reported issues were addressed across 13 files
Architecture diagram
sequenceDiagram
participant CLI as CLI Entry (agent.ts main)
participant RC as runCursor()
participant CursorSDK as Cursor Agent (@cursor/sdk)
participant MCPChild as Stagehand Facade MCP Server
participant StagehandCore as Stagehand Core (Browser Tools)
participant Browser as Browser (local/Browserbase)
participant FS as Temp Workspace
Note over CLI,FS: Cursor SDK Integration - Runtime Architecture
CLI->>RC: runCursor(instruction)
RC->>FS: mkdtemp (isolated workspace)
RC->>RC: buildCursorAgentOptions(allowlist env STAGEHAND_*/BROWSERBASE_*)
RC->>CursorSDK: Agent.create(options)
CursorSDK->>CursorSDK: Local store in workspace, settingSources=[], tools=["mcp"]
CursorSDK->>MCPChild: spawn stdio (facade server path, filtered env)
MCPChild->>StagehandCore: Initialize shared browser session
RC->>CursorSDK: agent.send(prompt + FACADE_AGENT_INSTRUCTIONS)
CursorSDK->>CursorSDK: Agent loop (model inference hosted by Cursor)
CursorSDK->>MCPChild: run "run" tool (browser task)
MCPChild->>StagehandCore: Execute browser automation
StagehandCore->>Browser: Navigate/interact via extension
Browser-->>StagehandCore: Page state
StagehandCore-->>MCPChild: run result
MCPChild-->>CursorSDK: tool result
CursorSDK->>MCPChild: run "snapshot" tool (same session)
MCPChild->>StagehandCore: Get current snapshot
StagehandCore->>Browser: Read DOM/state
Browser-->>StagehandCore: Snapshot data
StagehandCore-->>MCPChild: snapshot result
MCPChild-->>CursorSDK: tool result
CursorSDK->>MCPChild: run "screenshot" tool (same browser)
MCPChild->>StagehandCore: Capture screenshot
StagehandCore->>Browser: Render capture
Browser-->>StagehandCore: Screenshot image
StagehandCore-->>MCPChild: screenshot result
MCPChild-->>CursorSDK: tool result
CursorSDK-->>RC: RunResult (finished)
alt RunResult error or cancelled
RC->>RC: Throw descriptive error
end
RC->>CLI: Return assistant text
Note over RC,FS: Shutdown & Cleanup
RC->>CursorSDK: asyncDispose()
CursorSDK->>MCPChild: Terminate stdio process
MCPChild->>StagehandCore: Release browser session
RC->>FS: rm -rf workspace
rect rgb(50,50,50)
Note over RC,CursorSDK: Signal handling (SIGINT/SIGTERM)
CursorSDK->>RC: Signal received
RC->>CursorSDK: activeRun.cancel()
CursorSDK-->>RC: Run cancelled
RC->>RC: Throw "Cursor run interrupted"
end
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
There was a problem hiding this comment.
All reported issues were addressed across 4 files (changes from recent commits).
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
There was a problem hiding this comment.
All reported issues were addressed across 3 files (changes from recent commits).
Tip: Review your code locally with the cubic CLI to iterate faster.
Re-trigger cubic
There was a problem hiding this comment.
All reported issues were addressed across 3 files (changes from recent commits).
Tip: Review your code locally with the cubic CLI to iterate faster.
Re-trigger cubic
There was a problem hiding this comment.
All reported issues were addressed across 4 files (changes from recent commits).
Tip: Review your code locally with the cubic CLI to iterate faster.
Re-trigger cubic
why
Add a Cursor SDK example alongside the existing Claude Code and Codex integrations, giving local Cursor agents persistent Stagehand browser tools over MCP/stdio.
what changed
@cursor/sdkintegration using Cursor's local runtime.run,snapshot, andscreenshot.STAGEHAND_*andBROWSERBASE_*variables to the MCP child.SIGINTandSIGTERMand cleans up all temporary resources.Summary by cubic
Adds a Cursor SDK integration so a local
@cursor/sdkagent or the Cursor CLI can use persistent Stagehand browser tools over MCP/stdio. Previously Cursor was unsupported; now one agent and one facade share one browser acrossrun,snapshot, andscreenshot, with signal handling that preserves CLI exit signals.packages/integrations/cursor(@browserbasehq/stagehand-integrations-example-cursor-facade) that launches a local Cursor agent with the Stagehand facade as the only MCP tool; ships.cursor/mcp.jsonso theagentCLI can mount the same facade.STAGEHAND_*/BROWSERBASE_*env vars to the MCP child; never forwardsCURSOR_API_KEY.composer-2.5(override withCURSOR_STAGEHAND_MODEL) and clarifies Browserbase vs. local Chrome selection.SIGINT/SIGTERM, cancels the active run, always cleans up the agent and workspace, surfaces explicit errors for interrupted/failed/empty-text runs, and re-emits the original signal so the CLI exits with the same signal status.v4/integrations/cursor.mdx, overview/nav updates, and a Cursor icon; documents CLI usage and headless approvals.Written for commit 0e9c705. Summary will update on new commits.