browser-use-mcp-server

repository·main·Indexed 21 days ago

https://github.com/kontext-security/browser-use-mcp-server

An MCP (Model Context Protocol) server that enables AI agents to interact with and control web browsers using the browser-use library. It supports SSE and stdio transport modes, includes VNC streaming for real-time visual monitoring, and can be deployed via Docker. The server provides a public API for managing server lifecycles, task execution, and browser context configuration.

Tokens
2K
Snippets
10
Records
11
Agent score
74%

What's inside browser-use-mcp-server

  1. Install browser-use-mcp-server dependencies

    main

    Use uv to synchronize dependencies and install the necessary Playwright browser binaries:

    # Install dependencies
    uv sync
    uv pip install playwright
    uv run playwright install --with-deps --no-shell chromium
    uv sync
    uv pip install playwright
    uv run playwright install --with-deps --no-shell chromium
  2. Run browser-use-mcp-server via Docker

    main

    Docker provides an isolated environment. You can run the container with default settings or provide a custom VNC password via a mounted file.

    Default run (VNC password: browser-use):

    docker build -t browser-use-mcp-server .
    docker run --rm -p8000:8000 -p5900:5900 browser-use-mcp-server

    Run with custom VNC password:

    echo "your-secure-password" > vnc_password.txt
    docker run --rm -p8000:8000 -p5900:5900 \
      -v $(pwd)/vnc_password.txt:/run/secrets/vnc_password:ro \
      browser-use-mcp-server
    docker run --rm -p8000:8000 -p5900:5900 browser-use-mcp-server
  3. View browser automation via VNC

    main

    The server supports VNC streaming to watch browser automation in real-time. If running via Docker, the VNC port is 5900.

    You can use a browser-based viewer like noVNC to connect:

    git clone https://github.com/novnc/noVNC
    cd noVNC
    ./utils/novnc_proxy --vnc localhost:5900

    Default VNC password: browser-use (unless overridden via Docker secrets).

    ./utils/novnc_proxy --vnc localhost:5900
  4. Run the server in stdio Mode

    main

    To run the server using stdio transport, you must first build and install it as a global tool, then run it using the browser-use-mcp-server command. This mode requires mcp-proxy.

    1. Build and install globally:

    uv build
    uv tool uninstall browser-use-mcp-server 2>/dev/null || true
    uv tool install dist/browser_use_mcp_server-*.whl

    2. Run with stdio transport:

    browser-use-mcp-server run server --port 8000 --stdio --proxy-port 9000

    Client Configuration (JSON):

    {
      "mcpServers": {
        "browser-server": {
          "command": "browser-use-mcp-server",
          "args": [
            "run",
            "server",
            "--port",
            "8000",
            "--stdio",
            "--proxy-port",
            "9000"
          ],
          "env": {
            "OPENAI_API_KEY": "your-api-key"
          }
        }
      }
    }
    uv build
    uv tool uninstall browser-use-mcp-server 2>/dev/null || true
    uv tool install dist/browser_use_mcp_server-*.whl
    browser-use-mcp-server run server --port 8000 --stdio --proxy-port 9000
  5. Install prerequisites for browser-use-mcp-server

    main

    Before installing the server, ensure you have uv, Playwright, and mcp-proxy (required for stdio mode) installed. Use the following commands to set up the environment:

    # Install uv
    curl -LsSf https://astral.sh/uv/install.sh | sh
    
    # Install mcp-proxy and update shell
    uv tool install mcp-proxy
    uv tool update-shell
    # Install prerequisites
    curl -LsSf https://astral.sh/uv/install.sh | sh
    uv tool install mcp-proxy
    uv tool update-shell
  6. Run the server in SSE Mode

    main

    To run the server using Server-Sent Events (SSE) transport, execute the following command from the source directory:

    uv run server --port 8000

    To use this in a client (like Cursor or Claude), configure the client with the SSE URL:

    {
      "mcpServers": {
        "browser-use-mcp-server": {
          "url": "http://localhost:8000/sse"
        }
      }
    }
    uv run server --port 8000
  7. Configure environment variables

    main

    Create a .env file in your project root to configure the server. The following keys are supported:

    • OPENAI_API_KEY: Your OpenAI API key (required).
    • CHROME_PATH: (Optional) Path to a specific Chrome installation.
    • PATIENT: Set to true if you want API calls to wait for task completion; otherwise, defaults to false.
    OPENAI_API_KEY=your-api-key
    CHROME_PATH=optional/path/to/chrome
    PATIENT=false
  8. Locate MCP client configuration files

    main

    Depending on which AI client you are using, the configuration file is located at:

    ClientConfiguration Path
    Cursor./.cursor/mcp.json
    Windsurf~/.codeium/windsurf/mcp_config.json
    Claude (Mac)~/Library/Application Support/Claude/claude_desktop_config.json
    Claude (Windows)%APPDATA%\Claude\claude_desktop_config.json
  9. Use the browser-use-mcp-server public API

    main

    The browser_use_mcp_server module provides a high-level interface for managing browser-based tasks via the Model Context Protocol (MCP). The primary entry points for managing the server lifecycle, task execution, and configuration are re-exported from the core server module.

    Key components include:

    • Server: The main server class.
    • main: The primary entry point for running the server.
    • create_mcp_server: Utility to initialize the MCP server instance.
    • run_browser_task_async: Executes a browser task asynchronously.
    • create_browser_context_for_task: Sets up the browser environment for a specific task.
    • init_configuration: Initializes the server configuration.
    • CONFIG: Access to the global configuration object.
    • task_store: A registry for managing active or completed tasks.
    • cleanup_old_tasks: Utility to prune the task store.
    from browser_use_mcp_server import (
        Server,
        main,
        create_browser_context_for_task,
        run_browser_task_async,
        cleanup_old_tasks,
        create_mcp_server,
        init_configuration,
        CONFIG,
        task_store,
    )
    
    # Example usage pattern (conceptual):
    # config = init_configuration()
    # server = create_mcp_server(config)
    # main(server)
  10. Configure CLI logging behavior

    main

    The CLI uses JSON-formatted logging sent to stderr. This is designed for machine-readable logs. The log format includes time, level, name, and message. Errors encountered during server startup are also logged as JSON objects to stderr containing error and traceback fields.

    {
      "time": "2025-07-10T12:00:00.000Z",
      "level": "ERROR",
      "name": "browser_use_mcp_server",
      "message": "Error starting server",
      "error": "Some error message",
      "traceback": "Traceback details..."
    }
  11. Run the browser-use MCP server via CLI

    main

    Use the run command to start the browser-use MCP server. The server requires the server subcommand to be passed as the first argument. You can configure browser settings, networking, and transport modes using various flags.

    Subcommands

    • server: The only supported subcommand for the run command.

    Options

    OptionDefaultDescription
    --port8000Port to listen on for SSE (Server-Sent Events)
    --proxy-portNonePort for the proxy to listen on (required when using --stdio mode)
    --chrome-pathNonePath to the Chrome executable
    --window-width1280Browser window width
    --window-height1100Browser window height
    --localeen-USBrowser locale
    --task-expiry-minutes60Minutes after which tasks are considered expired
    --stdioFalseEnable stdio mode with mcp-proxy (flag)
    # Example: Running the server in stdio mode with a specific proxy port
    python -m browser_use_mcp_server.cli run server --stdio --proxy-port 8080
    
    # Example: Running the server in SSE mode with custom browser dimensions
    python -m browser_use_mcp_server.cli run server --port 9000 --window-width 1920 --window-height 1080