Skip to main content
The Stagehand MCP server provides 9 tools for AI-powered browser automation. These tools enable session management, navigation, natural language actions, data extraction, and cookie manipulation. Server name: stagehand Version: 1.0.0 Script: scripts/stagehand-mcp-server.mjs

Environment Variables


Architecture

Stagehand wraps a browser automation server (port 3002) and exposes it as MCP tools. Each browser session:
  • Uses Chromium with stealth mode (--disable-blink-features=AutomationControlled)
  • Runs at 1920x1080 resolution
  • Can run headless or with visible UI
  • Maintains independent cookie stores and state
  • Consumes ~300MB RAM per active session
Resource limits: ~33 concurrent sessions on 10GB available RAM.

Workflow Pattern

  1. Start session → get session_id
  2. Navigate to target URL
  3. Act / Extract / Observe as needed
  4. Screenshot for debugging (optional)
  5. Close session when done
Cookie-based authentication:
  1. Start session → get session_id
  2. Set cookies from browser extension capture
  3. Navigate to authenticated page (bypasses login)
  4. Act / Extract data
  5. Close session

start-session

Start a new Stagehand browser session. Returns a session ID used by all other tools. Parameters:
  • headless (boolean, optional): Run headless (default: true)
Returns: Session object with session_id and metadata. Example 1: Headless session (default)
Response:
Example 2: Visible browser (for debugging)
Use cases:
  • Platform scraping (OnlyFans, Fansly, etc.)
  • Social media posting automation
  • Content extraction from authenticated pages
  • HITL (human-in-the-loop) login workflows

Navigate the browser to a URL in an existing session. Parameters:
  • session_id (string, required): Session ID from start-session
  • url (string, required): URL to navigate to
Returns: Navigation result with status. Example:
Response:
Tips:
  • Always call navigate before interacting with page elements
  • Wait for page load to complete before calling act or extract
  • Use with set-cookies for authenticated navigation

act

Perform a browser action using natural language (click, type, scroll, etc.). This is Stagehand’s core AI-powered feature — it understands natural language instructions and translates them to browser actions. Parameters:
  • session_id (string, required): Session ID from start-session
  • action (string, required): Natural language action description
Returns: Action result with status. Example 1: Click action
Response:
Example 2: Type action
Example 3: Complex multi-step
Example 4: Conditional action
Supported actions:
  • Click elements (buttons, links, etc.)
  • Type text into inputs/textareas
  • Scroll (up, down, to element)
  • Select dropdown options
  • Upload files
  • Press keyboard keys
  • Hover over elements
  • Drag and drop
Best practices:
  • Use clear, specific descriptions (“Click the blue ‘Submit’ button” vs “click button”)
  • Reference visual landmarks when multiple similar elements exist
  • Break complex workflows into multiple act calls
  • Check results with screenshot if action fails

extract

Extract structured data from the current page using a schema description. This is Stagehand’s AI-powered data scraping — it understands what data you want and extracts it intelligently. Parameters:
  • session_id (string, required): Session ID from start-session
  • instruction (string, required): What to extract (natural language)
  • schema (object, optional): Optional JSON schema describing the output structure
Returns: Extracted data matching the schema. Example 1: Simple extraction
Response:
Example 2: With schema
Response:
Example 3: Profile stats
Response:
Use cases:
  • Platform statistics scraping
  • Content feed extraction
  • Fan engagement metrics
  • Earnings data collection
  • Post metadata gathering

observe

Observe interactive elements on the current page. Parameters:
  • session_id (string, required): Session ID from start-session
  • instruction (string, optional): What to look for (e.g. “Find all clickable buttons”)
Returns: List of observed elements with selectors and descriptions. Example 1: Find all buttons
Response:
Example 2: Find input fields
Use cases:
  • Debug why act isn’t finding an element
  • Discover available interactions on a page
  • Validate page structure before automation

screenshot

Take a screenshot of the current browser page. Parameters:
  • session_id (string, required): Session ID from start-session
Returns: Screenshot data (typically base64-encoded image). Example:
Response:
Use cases:
  • Debug failed automation steps
  • Verify page state before/after actions
  • Capture visual confirmation of task completion
  • Generate proof-of-posting for scheduling

get-cookies

Get all cookies from the current browser session. Parameters:
  • session_id (string, required): Session ID from start-session
Returns: Array of cookie objects. Example:
Response:
Use cases:
  • Save cookies after manual login (HITL flow)
  • Store session tokens for future automation
  • Transfer authentication between sessions

set-cookies

Inject cookies into the browser session (for bypassing login). This is the core of Genie Helper’s cookie-based authentication flow. Parameters:
  • session_id (string, required): Session ID from start-session
  • cookies (array, required): Array of cookie objects [{name, value, domain, path, ...}]
Returns: Success confirmation. Example:
Response:
Cookie sources:
  1. Browser extension capture (primary) — user exports cookies from authenticated session
  2. HITL login flow — user logs in manually, Stagehand captures cookies via get-cookies
  3. Stored credentials — cookies retrieved from Directus platform_sessions collection
Authentication workflow:
Important:
  • Set cookies BEFORE navigating to the target site
  • Ensure domain includes the leading dot (.onlyfans.com not onlyfans.com)
  • Include all authentication cookies (not just the main token)
  • Check cookie expiry before use

close-session

End and clean up a browser session. Always call this when done to free up system resources (300MB RAM per session). Parameters:
  • session_id (string, required): Session ID to close
Returns: Confirmation of closure. Example:
Response:
Best practices:
  • Always close sessions in a finally block (if using programmatically)
  • Don’t leave sessions idle — they consume RAM
  • Close immediately after task completion
  • Monitor active sessions with resource tracking

Complete Scraping Example

Here’s a full OnlyFans profile scraping workflow: 1. Start session
→ Get session_id 2. Set cookies (from browser extension)
3. Navigate to profile
4. Extract profile stats
5. Navigate to posts feed
6. Extract post data
7. Close session

Error Handling

All Stagehand tools surface HTTP errors to the agent: Session not found:
Solution: Verify session_id or start a new session Element not found:
Solution: Use observe to find available elements, or rephrase action description Navigation failed:
Solution: Check URL validity, network connectivity, or increase timeout Server unavailable:
Solution: Check if Stagehand server (port 3002) is running

Performance & Limits

Session limits:
  • Max concurrent sessions: ~33 (on 10GB available RAM)
  • RAM per session: ~300MB
  • Session timeout: Auto-closes after 30 minutes idle
Operation timing:
  • start-session: ~2-3s
  • navigate: ~1-3s (depending on page load)
  • act: ~2-5s (AI inference + action execution)
  • extract: ~3-8s (AI inference + data scraping)
  • screenshot: ~0.5-1s
  • set-cookies / get-cookies: ~0.1s
  • close-session: ~0.5s
Recommendations:
  • Reuse sessions for multiple operations on the same site
  • Close sessions immediately when done
  • Use headless mode for production (faster, less RAM)
  • Batch extractions when possible (one extract with complex schema vs multiple calls)

Stealth Mode

All Stagehand sessions use anti-detection measures:
Platform detection resistance:
  • No navigator.webdriver flag
  • Standard user agent strings
  • Real browser fingerprint
  • Human-like interaction timing (built into Stagehand AI)
Best practices for stealth:
  • Use cookies from real browser sessions (not manual login automation)
  • Add delays between actions (Stagehand does this automatically)
  • Don’t scrape too aggressively (rate limit your requests)
  • Rotate sessions periodically