Browserbase MCP Server

repository·main·Indexed 25 days ago

https://github.com/browserbase/mcp-server-browserbase

An MCP server for AI web browser automation using Browserbase and Stagehand. It enables LLMs to interact with web pages, navigate, perform actions, and extract data via the Model Context Protocol. Supports hosted SHTTP, self-hosted NPM, and Docker deployments. Version 3.0.0.

Tokens
7.5K
Snippets
14
Records
40
Agent score
82%

What's inside @browserbasehq/mcp

  1. Set up the Browserbase MCP Server locally via Docker

    main

    To run the server locally using Docker, first build the image from the repository, then configure your MCP client to run the container. Ensure you pass the required environment variables through the docker run command.

    # Build the image
    git clone https://github.com/browserbase/mcp-server-browserbase.git
    cd mcp-server-browserbase
    docker build -t mcp-browserbase .
    // MCP Config for Docker
    {
      "mcpServers": {
        "browserbase": {
          "command": "docker",
          "args": [
            "run",
            "--rm",
            "-i",
            "-e",
            "BROWSERBASE_API_KEY",
            "-e",
            "BROWSERBASE_PROJECT_ID",
            "-e",
            "GEMINI_API_KEY",
            "mcp-browserbase"
          ],
          "env": {
            "BROWSERBASE_API_KEY": "",
            "BROWSERBASE_PROJECT_ID": "",
            "GEMINI_API_KEY": ""
          }
        }
      }
    }
  2. Set up the Browserbase MCP Server via NPM (Self-Hosted)

    main

    To run the self-hosted version using NPM, add the @browserbasehq/mcp package to your MCP configuration. You must provide your BROWSERBASE_API_KEY, BROWSERBASE_PROJECT_ID, and GEMINI_API_KEY in the environment variables.

    {
      "mcpServers": {
        "browserbase": {
          "command": "npx",
          "args": ["@browserbasehq/mcp"],
          "env": {
            "BROWSERBASE_API_KEY": "",
            "BROWSERBASE_PROJECT_ID": "",
            "GEMINI_API_KEY": ""
          }
        }
      }
    }
  3. Set up the Browserbase Hosted MCP Server (SHTTP)

    main

    The easiest way to use Browserbase MCP is via the hosted SHTTP server at https://mcp.browserbase.com/mcp. This version includes hosted LLM costs for Gemini.

    If your MCP client supports SHTTP, use the http type configuration. If it only supports STDIO, use npx mcp-remote to connect to the hosted URL.

    // For clients supporting SHTTP
    {
      "mcpServers": {
        "browserbase": {
          "type": "http",
          "url": "https://mcp.browserbase.com/mcp"
        }
      }
    }
    
    // For clients only supporting STDIO
    {
      "mcpServers": {
        "browserbase": {
          "command": "npx",
          "args": ["mcp-remote", "https://mcp.browserbase.com/mcp"]
        }
      }
    }
  4. Understand Sampling capability in Browserbase MCP

    main

    The Browserbase MCP server implements the MCP sampling capability. This allows the server to initiate requests TO the client to ask for LLM completions. This is primarily used for intelligent browser automation, enabling the server to request AI assistance for analyzing web pages and making decisions during a session.

    Note: Sampling support is dependent on the MCP client implementation. Not all clients (e.g., Claude Desktop) currently support this capability.

  5. Configure custom LLM models for the self-hosted server

    main

    The self-hosted server defaults to google/gemini-2.5-flash-lite. To use a different model (e.g., Claude or GPT-4o), pass the --modelName flag and provide the corresponding API key using the --modelApiKey flag. The model must be supported by Stagehand.

    {
      "mcpServers": {
        "browserbase": {
          "command": "npx",
          "args": [
            "@browserbasehq/mcp",
            "--modelName",
            "anthropic/claude-sonnet-4.5",
            "--modelApiKey",
            "your-anthropic-api-key"
          ],
          "env": {
            "BROWSERBASE_API_KEY": "",
            "BROWSERBASE_PROJECT_ID": ""
          }
        }
      }
    }
  6. Configure MCP evaluation settings

    main

    The mcp-eval-basic.config.json file defines the configuration for running evaluations against the Browserbase MCP server. It specifies the server connection details, environment variables, success thresholds, and the specific workflows to be tested.

    Top-level Configuration Keys

    • passThreshold: A float representing the minimum success rate required for an evaluation to pass (e.g., 0.7).
    • timeout: The maximum time in milliseconds allowed for the evaluation (e.g., 180000).
    • llmJudge: A boolean indicating whether an LLM should be used to judge the results.
    • server: An object defining how to connect to the MCP server.
    • workflows: An array of workflow objects defining specific test cases.
  7. Configure MCP evaluation settings in mcp-eval.config.json

    main

    The mcp-eval.config.json file defines the configuration for running evaluations against the Browserbase MCP server. It specifies the server connection details, evaluation thresholds, and a suite of test workflows.

    Top-level Configuration Keys

    • passThreshold (number): The minimum score required for an evaluation to be considered successful (e.g., 0.7).
    • timeout (number): The maximum execution time in milliseconds for the evaluation process.
    • llmJudge (boolean): Enables or disables using an LLM to judge the success of the evaluation steps.
    • server (object): Defines how to connect to the MCP server.
    • workflows (array): A list of test scenarios to execute.
    {
      "passThreshold": 0.7,
      "timeout": 180000,
      "llmJudge": false,
      "server": {
        "transport": "stdio",
        "command": "node",
        "args": ["./cli.js"],
        "env": {
          "BROWSERBASE_API_KEY": "${BROWSERBASE_API_KEY}",
          "BROWSERBASE_PROJECT_ID": "${BROWSERBASE_PROJECT_ID}",
          "GEMINI_API_KEY": "${GEMINI_API_KEY}"
        }
      },
      "workflows": []
    }
  8. Configure the MCP server connection

    main

    The server object in the evaluation configuration defines the transport mechanism and execution environment for the MCP server.

    Server Configuration Keys

    • transport: The communication method (e.g., stdio).
    • command: The executable used to run the server (e.g., node).
    • args: An array of command-line arguments passed to the command (e.g., ["./cli.js"]).
    • env: An object containing the environment variables required by the server. Required variables include:
      • BROWSERBASE_API_KEY
      • BROWSERBASE_PROJECT_ID
      • GEMINI_API_KEY
    "server": {
      "transport": "stdio",
      "command": "node",
      "args": ["./cli.js"],
      "env": {
        "BROWSERBASE_API_KEY": "${BROWSERBASE_API_KEY}",
        "BROWSERBASE_PROJECT_ID": "${BROWSERBASE_PROJECT_ID}",
        "GEMINI_API_KEY": "${GEMINI_API_KEY}"
      }
    }
  9. Configure the Browserbase MCP Server

    main

    The Browserbase MCP Server is configured using a schema that defines connection details for Browserbase, session management, viewport settings, and model configurations for Stagehand.

    Required Fields:

    • browserbaseApiKey: The Browserbase API Key.
    • browserbaseProjectId: The Browserbase Project ID.

    Key Configuration Options:

    • proxies: Boolean to enable/disable Browserbase proxies.
    • verified: Enables Browserbase Verified Identity (Scale Plan users only). Note: advancedStealth is a deprecated alias for this.
    • keepAlive: Whether to keep the Browserbase session alive.
    • context: Object to manage session persistence via contextId and persist (boolean).
    • viewPort: Defines browserWidth and browserHeight.
    • modelName: The model used for Stagehand (defaults to google/gemini-2.5-flash-lite).
    • modelApiKey: Required if modelName is set to anything other than the default.
    • server: Configuration for the transport layer, including port and host (defaults to localhost).
  10. Set Browserbase and Model Environment Variables

    main

    The server uses specific environment variables to resolve configuration if they are not provided via CLI.

    Browserbase Configuration

    • BROWSERBASE_API_KEY: Your Browserbase API key.
    • BROWSERBASE_PROJECT_ID: Your Browserbase Project ID.

    Model Configuration

    If modelApiKey is not provided via CLI, the server looks for:

    • GEMINI_API_KEY
    • GOOGLE_API_KEY (as a fallback)

    Note: If these are not set, the server will log a warning and use dummy values, which will cause API calls to fail.

  11. Configure MCP evaluation via mcp-eval-minimal.config.json

    main

    The mcp-eval-minimal.config.json file defines the configuration for running evaluations on the Browserbase MCP server. It specifies the pass threshold, server transport settings, environment variables, timeouts, and the specific workflows to be tested.

    Top-level Configuration Keys

    • passThreshold: A float representing the minimum success rate required for an evaluation to pass (e.g., 0.7).
    • server: An object defining how to launch the MCP server.
    • timeout: The execution timeout in milliseconds (e.g., 60000).
    • llmJudge: A boolean indicating whether an LLM should be used to judge the results.
    • workflows: An array of workflow objects defining the test scenarios.
    {
      "passThreshold": 0.7,
      "server": {
        "transport": "stdio",
        "command": "node",
        "args": ["./cli.js"],
        "env": {
          "BROWSERBASE_API_KEY": "${BROWSERBASE_API_KEY}",
          "BROWSERBASE_PROJECT_ID": "${BROWSERBASE_PROJECT_ID}",
          "GEMINI_API_KEY": "${GEMINI_API_KEY}"
        }
      },
      "timeout": 60000,
      "llmJudge": false,
      "workflows": [
        {
          "name": "smoke-test-navigation",
          "description": "Quick test to verify basic navigation works",
          "steps": [
            {
              "user": "Open a browser and go to example.org",
              "expectedState": "success"
            },
            {
              "user": "Close the browser",
              "expectedState": "success"
            }
          ],
          "expectTools": ["start", "navigate", "end"]
        }
      ]
    }