OpenChrome Browser Automation MCP Server

repository·main·Indexed 42 days ago

https://github.com/shaun0927/openchrome

An open-source Model Context Protocol (MCP) server that allows AI agents, such as Claude Code and Codex CLI, to control a real Chrome browser instance via the Chrome DevTools Protocol (CDP). Version 1.13.0 provides capabilities for navigation, interaction, data extraction, and workflow management, including a CLI for managing servers, configuring clients, and handling screenshot exemplars.

Tokens
84.2K
Snippets
225
Records
341
Agent score
53%

What's inside OpenChrome

  1. Overview of OpenChrome Capabilities

    main

    OpenChrome provides a comprehensive suite of 121 tools designed for browser automation, web crawling, and agentic workflows. These tools are categorized into several functional domains:

    • Core: Fundamental browser interaction, DOM manipulation, network interception, and session management.
    • Crawl: Tools for recursive website crawling, sitemap processing, and parallel batch execution.
    • Profile: Management of Chrome profiles.
    • Recording: Session recording and export capabilities.
    • Storage: Management of cookies and web storage (localStorage/sessionStorage).
    • TOTP: Generation of 2FA codes.
    • Workflow: Orchestration of multiple workers for parallel browser operations.
  2. Understand the OpenChrome Project Structure

    main

    The OpenChrome repository follows a strict directory layout to separate production runtime code, CLI entrypoints, tests, and documentation.

    Top-Level Directory Map

    • src/: Shipped TypeScript runtime (production code only).
    • cli/: Thin CLI command adapters that call runtime modules.
    • tests/: Jest, e2e, fixtures, and integration checks. Browser-level scenario tests are located in tests/e2e.
    • docs/: Durable CLI and MCP documentation.
    • scripts/: Maintenance and generation scripts used by CI or package scripts.
    • config/: Shipped runtime policy configuration consumed by the runtime.

    Repository Root Rules

    The root directory is restricted to standard project documents (README.md, LICENSE, SECURITY.md), configuration files (package.json, TypeScript, Jest, ESLint), GitHub automation (.github/), and the primary directories listed above. Ad hoc folders for experiments or local state are prohibited.

  3. Manage tenant API keys via `openchrome admin keys`

    main

    The admin keys command group allows for the lifecycle management of tenant API keys.

    Output Contract:

    • stdout: Contains only the plaintext key (during create or rotate) or a JSON array (during list --json). This allows for clean piping into tools like jq.
    • stderr: Contains all diagnostic information, tables, warnings, and error messages.
    openchrome admin keys create --tenant acme --scope read --scope write
  4. Handle tool cancellation and uncertain writes

    main

    If an operation needs to be interrupted, send the standard MCP notifications/cancelled notification using the original requestId.

    Cancellation Behavior:

    • Pre-dispatch: If interrupted before the command is sent, the execution state is reported as not_started.
    • Post-dispatch: If interrupted after the command is sent to Chrome, the execution state is reported as unknown and retryAllowed is set to false.
    • Limitations: Cancellation stops further admission of commands but cannot roll back actions that have already been sent (like a click, a request, or a script execution). Always inspect the page state or server-side receipts to determine if a retry is safe.
  5. Understand Playbook Exit Codes and Fail-Fast Semantics

    main

    Playbooks execute sequentially. If a step fails:

    1. The step is marked failed in the report.
    2. All subsequent steps are marked skipped (their MCP tools are not called).
    3. The runner disconnects and exits with code 1.

    Exit Codes:

    • 0: All steps and all asserts passed.
    • 1: At least one step or assert failed.
    • 2: Usage, parse, or unknown variable error.
    • 3: I/O, spawn, or transport failure (MCP server unreachable).
  6. Understand Portable Contract Facts and Provenance

    main

    OpenChrome uses contract_facts to provide additive, snapshot-driven data for assertions. These facts are not live browser states but are captured by collectors (like performance_metrics or console_capture) and passed back to the host.

    Every version 1 fact includes a provenance envelope containing schema_version, kind, source_tool, session_id, target_id, and a timezone-qualified ISO-8601 captured_at timestamp.

    Evaluation Rules:

    • Evaluation is closed-world: the current MCP session ID must match the fact's session_id, and the evidence.provenance.target_id must match the fact's target_id.
    • The freshest matching fact is selected deterministically.
    • If facts are missing, malformed, stale, or have unit mismatches, the verdict is inconclusive with a specific machine-stable error code.
    interface ContractFactBase {
      schema_version: 1;
      kind: "performance" | "console";
      source_tool: "performance_metrics" | "console_capture";
      session_id: string;
      target_id: string;
      captured_at: string; // YYYY-MM-DDTHH:mm:ss[.1-9 digits](Z|+/-HH:MM)
    }
  7. Choose the right OpenChrome transport mode

    main

    OpenChrome supports three transport modes to determine how clients interact with the server:

    • stdio (Default): Best for single MCP clients (like Claude Desktop or Cursor) that launch the process and control its lifetime. The process exits when the client exits.
    • http: Best for long-running daemons shared by multiple clients, CI jobs, or callers on different hosts. It allows concurrent connections and uses an idle-timeout to manage its own lifecycle.
    • both: Best when an MCP client launches the process but a sidecar (like a dashboard or monitoring script) also needs to poll /health or /metrics. stdio carries MCP traffic, while HTTP carries the health/metrics side-channel.

    Rule of thumb: Use --transport http if you are running OpenChrome in a Procfile, systemd unit, Docker CMD, or a CI step that outlives a single test run.

  8. How the Shared-profile Broker model works

    main

    The Broker model is the only way to allow multiple MCP clients to share a single Chrome user data directory without using auto-elect.

    Core Concepts:

    • Broker Owner: A single process that holds the exclusive Chrome/CDP ownership for a (port, userDataDir) pair. It runs with the --broker flag.
    • Broker Clients: Additional clients that connect to the owner via --connect-broker. They forward stdio JSON-RPC requests over the broker's HTTP endpoint.
    • Security/Trust: Only use this in a same-trust-zone. All clients must be operated by the same human or automation boundary, as they will share access to authenticated sites, open tabs, and browser state. Do not mix trusted and untrusted agents on a shared profile.
    • Authentication: If the broker has an auth token, clients can share it via the OPENCHROME_AUTH_TOKEN environment variable. The proxy auto-discovers this and uses it for forwarded requests.
  9. Understand Outcome Contracts and the DSL

    main

    Outcome Contracts provide a machine-checkable way to prove that a skill or action (e.g., clicking a button) succeeded. They use a Domain Specific Language (DSL) to define postconditions that the OpenChrome runtime evaluates against a live Chromium page.

    Contracts can be composed using logical operators:

    • and: All children must pass. Short-circuits if a child fails.
    • or: At least one child must pass. Short-circuits if a child succeeds.
    • not: The single child must fail to satisfy the assertion.

    If an assertion fails, the runtime escalates based on the contract's on_fail policy and emits an evidence bundle.

    {
      "kind": "and",
      "children": [
        { "kind": "url", "pattern": "/orders/[A-Z0-9]{8}/confirmation" },
        { "kind": "dom_text", "selector": "h1", "contains": "Thank you" },
        { "kind": "no_dialog" }
      ]
    }
  10. Understand the Profile Fingerprint v1 concept

    main

    A profile fingerprint is a deterministic, secret-free hash computed from a captured EnvelopeCapture. It allows two parties to verify if they are looking at the same authenticated session without exchanging sensitive data like actual cookie values or storage contents.

    Key characteristics:

    • Deterministic: The same input always produces the same hash.
    • Value-Agnostic: It hashes the shape of the data (e.g., field names, value lengths) rather than the values themselves. Changing a cookie's value without changing its length will not change the fingerprint.
    • Length-Sensitive: Changing the length of a value will change the fingerprint.
    • Non-Cryptographic: It is intended for session comparison and diagnostic purposes, not for authentication or tamper detection.
  11. Lifecycle behavior of attached Chrome instances

    main
    When using --auto-connect, openchrome operates in attach mode. A key guarantee of this mode is that openchrome will not kill the Chrome instance it attached to during shutdown. Your existing browser windows and sessions will survive oc_stop, SIGTERM, and process-exit handlers.
  12. Core Browser Interaction and Automation Tools

    main

    The core category contains tools for direct browser control and state inspection. Key capabilities include:

    • Action Execution: act (natural language instructions), computer (mouse/keyboard/screenshot), drag_drop, fill_form, and interact (natural language element finding).
    • Navigation & Tabs: navigate, tabs_create, tabs_activate, tabs_close, and page_reload.
    • Data Extraction: extract_data (JSON-LD, OpenGraph, etc.), page_content (HTML), read_page (Markdown/AX), and inspect.
    • Network & Console: network_capture_full, network_capture_lite, request_intercept, and console_capture.
    • State & Context: oc_context_export (auth-relevant state) and oc_context_import (restoring state).