Skip to main content
Glama

Browser MCP

Browser MCP is an Electron-based Model Context Protocol server that gives MCP clients control over a real local browser window. It exposes tools for starting browser sessions and for running page actions: accessibility snapshots with element refs, real mouse and keyboard input, forms, frames and shadow DOM, uploads and downloads, cookies and storage, console and uncaught errors, and network inspection, mocking, and blocking.

The package is published on NPM as @cypherpotato/browser-mcp.

Contents

Related MCP server: chrome-mcp

How it works

Browser MCP has two runtime layers:

  1. A Node entrypoint named browser-mcp-electron.

  2. An Electron browser host that opens and controls real browser windows.

By default, MCP clients should start the package with --mcp. That command starts or reuses a local HTTP sentinel, then proxies MCP messages over stdin/stdout for the client.

flowchart LR
  Client["MCP client"] --> Stdio["browser-mcp-electron --mcp"]
  Stdio --> Sentinel["Local HTTP sentinel"]
  Sentinel --> Electron["Electron browser host"]
  Electron --> Page["Live browser session"]

The sentinel stores its current local endpoint in the operating system temp directory under browser-mcp-electron-sessions/sentinel.json. The server only listens on 127.0.0.1.

Requirements

  • Node.js 18 or newer.

  • npm or another Node package manager.

  • A desktop session capable of running Electron.

  • Linux only: the usual Electron runtime libraries for your distribution.

Installation

Install globally if your MCP client will call the binary directly:

npm install -g @cypherpotato/browser-mcp

Or run it without a global install:

npx @cypherpotato/browser-mcp --help

To verify the binary:

browser-mcp-electron --help

MCP client configuration

Use the stdio bridge mode for normal MCP client integration:

{
  "mcpServers": {
    "browser": {
      "command": "browser-mcp-electron",
      "args": ["--mcp"]
    }
  }
}

With npx:

{
  "mcpServers": {
    "browser": {
      "command": "npx",
      "args": ["-y", "@cypherpotato/browser-mcp", "--mcp"]
    }
  }
}

Optional startup URL and profile directory:

{
  "mcpServers": {
    "browser": {
      "command": "browser-mcp-electron",
      "args": [
        "--mcp",
        "--url",
        "https://example.com",
        "--data-dir",
        "~/.browser-mcp"
      ]
    }
  }
}

Running the HTTP sentinel

For normal MCP client usage, configure the client to run browser-mcp-electron --mcp. That command starts the HTTP sentinel automatically when needed and reuses a healthy sentinel when one already exists.

Run the HTTP sentinel manually only when you want to manage the browser host separately from an MCP stdio client.

Start it in the foreground:

browser-mcp-electron --mcp-http --url https://example.com --data-dir ~/.browser-mcp

Start it in the background and return after it is healthy:

browser-mcp-electron --mcp-http-background --url https://example.com --data-dir ~/.browser-mcp

The local sentinel uses port 55332 by default so the Session Copy browser extension can discover it. Override the port when needed:

browser-mcp-electron --mcp-http-background --sentinel-port 55333

When --mcp runs later, it reuses a healthy sentinel when one exists on the requested port. If no healthy sentinel exists, it starts one automatically.

CLI reference

browser-mcp-electron [--mcp] [--url <url>] [--data-dir <path>]
browser-mcp-electron --mcp-http [--url <url>] [--data-dir <path>]
browser-mcp-electron --mcp-http-background [--url <url>] [--data-dir <path>]
browser-mcp-electron --mcp-stdio [--url <url>] [--data-dir <path>]

Option

Description

--mcp

Starts or reuses the local HTTP sentinel and proxies MCP over stdin/stdout. Recommended for MCP clients.

--mcp-http

Starts or reuses only the local HTTP MCP sentinel and keeps the process alive.

--mcp-http-background

Starts or reuses the local HTTP MCP sentinel, then returns after it is healthy.

--mcp-stdio

Starts the legacy MCP server directly over stdin/stdout.

--url, -u

Initial browser URL. Defaults to https://www.google.com.

--data-dir

Browser profile/session directory. Defaults to ~/.browser-mcp.

--sentinel-port

Port for the HTTP sentinel. Defaults to 55332; use 0 for a random available port.

--confirm-actions

Comma-separated helpers that must be confirmed before they run. See Action confirmation.

--help, -h

Prints the CLI help.

Tools

browser_toggle_session

Starts or stops a real Electron browser session.

Start a session:

{
  "action": "start",
  "start_url": "https://example.com"
}

Stop a session:

{
  "action": "stop",
  "session_id": 1
}

browser_import_session

Opens a new agent browser window and imports a Session Copy extension payload, including its URL, cookies, localStorage, and sessionStorage. The page is loaded, its storage is written, and it is reloaded. A JavaScript dialog the page opens during the first load is dismissed; the one it opens after the reload is reported as pendingDialog by the next browser_run_actions call. A page that opens a dialog again every time it is dismissed cannot be imported by this tool: after 20 dialogs the call fails and the window is closed. browser.state("load") and the Import button of the window follow the same steps in the current window, where such a page keeps its dialog pending and the import finishes once that dialog is answered.

{
  "session": {
    "version": 1,
    "url": "https://example.com",
    "localStorage": {},
    "sessionStorage": {},
    "cookies": []
  }
}

browser_get_context

Lists active Browser MCP sessions with process ID, session ID, title, sanitized URL, and state. The sanitized URL has no query, except when a password typed by browser.auth("login") contains the ? of that URL: the password is replaced by [redacted] and the rest of the query stays.

Session states:

State

Meaning

idle

Ready for actions.

waiting

Loading or running an action.

user_input

A JavaScript dialog is pending. Resolve it with browser.setDialog(...) or browser.dismissDialog().

browser_run_actions

Runs an async JavaScript function body in the live page. The function receives a browser helper object.

Inspect the current page:

return browser.snapshot();

The snapshot lists the accessibility tree. Elements you can act on carry a ref:

URL: https://example.com/login
Title: Sign in
Viewport: 1264x813
Pending dialog: none
Console: recent=0 errors=0 warnings=0

- heading "Sign in" [level=1, ref=e1]
- textbox "Email" [ref=e2]
- textbox "Password" [ref=e3]
- button "Continue" [ref=e4]

Fill a form by ref or selector and wait for the result:

await browser.fill("@e2", "user@example.com");
await browser.fill("input[type=password]", "secret");
await browser.click("@e4");
await browser.wait({ text: "Welcome" });
return await browser.get("text", "h1");

Navigate:

return browser.navigate("https://example.com");

Mock an API response:

await browser.network("route", "*/api/user", { body: { name: "Ada" }, status: 200 });
return await (await fetch("/api/user")).json();

Capture a screenshot:

return await browser.screenshot();

Review network activity:

const logs = await browser.networkLogs({ filterMethod: "POST", filterPath: "/api/" });
return await browser.inspectNetworkRequest(logs.requests[0].id);

Targets

Helpers that act on an element accept any of these as target:

Target

Example

Snapshot ref

"@e4", "ref=e4", or "e4"

CSS selector

"button[type=submit]"

XPath

"xpath=//button[text()='Save']"

DOM element

document.querySelector("#save")

Pointer helpers (click, leftClick, rightClick, dblclick, hover, scroll, drag) also accept viewport CSS pixels in place of a target, for example browser.leftClick(120, 240). A point with no element under it, such as one outside the viewport, is an error, except as the destination of drag.

  • Every helper returns a promise, including the ones that only read (consoleLogs, snapshot). Always await the call.

  • Refs are reassigned by every snapshot and dropped when the page navigates. A ref whose element is gone fails with an error instead of acting on another element, even when a similar element took its place.

  • Selectors and refs reach open shadow DOM and iframes, including iframes from another origin. A selector must match inside a single root: "#host #inner" does not cross a shadow boundary, so use "#inner" or a ref.

  • Closed shadow roots are reachable by ref only.

  • Input is real browser input sent through the DevTools protocol. It triggers CSS :hover, focus, native drag and drop, and trusted events. A click fails when another element covers the click point.

Navigation inside a script

A script runs inside the page, so it ends when the page loads another document. Make the navigating call (navigate, back, forward, reload, or a click that follows a link) the last statement and continue in a follow-up tool call. Statements after it may not run; when the document is replaced mid-script the tool returns the result of the last helper call, or { navigated: true } when there was none.

A helper that is still loading a document when timeout_ms runs out is left to finish (up to 15 seconds) instead of being interrupted by a reload. Any other script that times out is stopped by reloading the page; a page stuck in a synchronous loop has that script terminated first. Recovery can add a few seconds to timeout_ms. A page that stops responding again as soon as it loads makes every call time out, with a postActionSnapshot that reports it; leave it with browser.navigate.

Helpers

Inspect:

Helper

Description

browser.snapshot(options?)

Page header and accessibility tree with refs. Options: interactive, compact, depth, selector, urls, maxLength.

browser.get(what, target?, extra?)

Reads text, html, value, attr (extra is the name), styles (extra is a property list), box, count (target is a selector), url, or title.

browser.is(state, target)

Checks visible, enabled, or checked.

browser.read(url?, options?)

Returns the page as Markdown. Options: filter, outline, raw, maxLength. With a URL it navigates first.

browser.shadowelements(target?)

Lists the refs of elements inside shadow roots, with the root mode (open or closed).

browser.screenshot()

Returns an MCP image.

browser.highlight(target)

Outlines an element for 3 seconds.

browser.inspect()

Opens DevTools for the session.

browser.consoleLogs()

Recent console entries, uncaught exceptions, and browser messages such as failed resources.

browser.errors({ clear? })

Uncaught exceptions and unhandled promise rejections, with stack, line, and column.

Act:

Helper

Description

browser.click(target, { button?, count?, duration? })

Clicks an element.

browser.dblclick(target)

Double clicks.

browser.leftClick(target, duration?), browser.rightClick(target, duration?)

Left or right click, optionally holding the button.

browser.hover(target)

Moves the pointer over an element.

browser.fill(target, text)

Replaces the value of an input, textarea, or contenteditable element.

browser.type(text)

Types into the focused element.

browser.focus(target)

Focuses an element.

browser.press(key)

Presses a key or chord: Enter, Tab, Escape, ArrowDown, Control+a, Shift+Tab.

browser.keyboard(action, value)

type, inserttext, down, or up.

browser.mouse(action, ...)

move (x, y), down (button?), up (button?), or wheel (deltaY, deltaX?).

browser.select(target, ...values)

Selects options by value or label. Also drives ARIA comboboxes.

browser.check(target), browser.uncheck(target)

Sets a checkbox, radio, or switch. Fails when the click does not change the state.

browser.drag(from, to, duration?, isLeftClick?)

Drags between two targets or coordinates.

browser.scroll(target, deltaY, deltaX?)

Scrolls with the mouse wheel over a target.

browser.find(strategy, value, action?, text?, options?)

Locates by role, text, label, placeholder, alt, title, testid, first, last, or nth and runs click, dblclick, fill, focus, hover, check, uncheck, or text. Options: name, exact.

browser.frame(target)

Scopes selectors and snapshots to an iframe. Use browser.frame("main") to go back.

browser.upload(target, ...files)

Sets files on a file input, or on the chooser opened by the target. More than one file requires an input with multiple.

browser.download(target, file?)

Clicks the target and waits for the download, optionally copying it to file. An existing file is not overwritten.

Wait and navigate:

Helper

Description

browser.wait(ms)

Waits a fixed time.

browser.wait(target, { state?, timeout? })

Waits until the target is visible (default), hidden, attached, or detached.

browser.wait({ text | url | load | fn | download, timeout? })

Waits for page text, a URL glob, a load state (load, domcontentloaded, networkidle), a JavaScript expression, or a finished download.

browser.sleep(ms)

Waits inside the page action.

browser.navigate(url)

Loads a URL and waits for it.

browser.back(), browser.forward(), browser.reload()

History navigation.

browser.pushstate(url)

Client-side navigation through history.pushState, within the current origin.

Waits never outlast the action: the default and maximum timeout is the time left in timeout_ms.

Network:

Helper

Description

browser.network("route", url, options)

Intercepts requests whose URL contains url (or matches it as a * glob). body and status mock the response, abort blocks the request, resourceType limits the match. headers are response headers for a mock and extra request headers otherwise.

browser.network("unroute", url?)

Removes one route, or all of them.

browser.network("requests", { filter?, method?, type?, status?, clear? })

Lists recorded requests. clear removes the listed requests from the record.

browser.network("request", id)

Request and response details, including bodies.

browser.network("har", "start"), browser.network("har", "stop", file?)

Records a HAR 1.2 file. An existing file is not overwritten.

browser.networkLogs(options?), browser.inspectNetworkRequest(id)

Compact request list and request details.

A mocked body is served as JSON when it parses as JSON and as plain text otherwise. Pass headers: { "Content-Type": "text/html" } to mock a document. Routing a URL again replaces its previous route, and when several routes match a request the newest one wins. A route with an invalid header name or value is rejected. A mock the browser still refuses is reported in browser.consoleLogs() and the request fails; it never reaches the server.

Environment:

Helper

Description

browser.set("viewport", width, height)

Resizes the emulated viewport, enabling mobile emulation first when needed.

browser.set("device", name)

mobile, tablet, or desktop.

browser.set("geo", latitude, longitude)

Overrides geolocation. Without arguments, clears the override.

browser.set("offline", boolean)

Turns the network off or on.

browser.set("headers", object)

Extra HTTP headers for every request.

browser.set("credentials", username, password)

HTTP Basic credentials for every request, to every origin the page loads.

browser.set("media", { colorScheme?, reducedMotion? })

Emulates prefers-color-scheme and prefers-reduced-motion.

browser.setEmulation(mode), browser.setViewport(width, height), browser.setColorScheme(scheme)

Shortcuts for the settings above.

Viewport emulation uses mobile metrics, so a page without <meta name="viewport"> is laid out 980 px wide, as on a phone.

State:

Helper

Description

browser.cookies("get", { all?, urls? }), browser.cookies("set", name, value, options?), browser.cookies("clear", { all? })

Reads, writes, and clears cookies.

browser.storage(kind, action, key?, value?)

kind is local or session; action is get, set, or clear.

browser.clipboard(action, text?)

read, write, copy, or paste. Uses the system clipboard.

browser.state(action, ...)

save, load, show, clear (name), list, rename (from, to), clean (days). Stores cookies and storage encrypted in the data directory.

browser.auth(action, name?, options?)

save ({ url, username, password, usernameSelector?, passwordSelector?, submitSelector? }), login, show, delete, list. After login, a password of 6 to 384 characters is replaced by [redacted] in every tool result, recorded request, and HAR file of every session: as plain text, URL-encoded or form-encoded (as UTF-8, Latin-1, or Windows-1252, also when encoded more than once), as HTML entities (also when escaped more than once), JSON-escaped, with its outer whitespace trimmed or its inner whitespace collapsed, and inside a Basic Authorization value of up to 384 characters built with the profile username and the password as typed or trimmed. A shorter or longer password, or a longer Basic value, is not redacted and login returns a warning. It also returns one when the password has fewer than 6 characters once trimmed or collapsed, which leaves it redacted only as typed, and when a very long password leaves no room for all of its forms. A password that mixes regular and non-breaking spaces, has several whitespace runs of which the page collapses only some, or has a tab and is placed in a URL, which drops the tab, is not recognized in those forms. The host keeps the passwords of the most recent logins only, without a notice when an older one is dropped: about 25 for passwords of 18 ASCII characters, fewer for longer ones or ones with whitespace, and about half for ones with accented characters. A password stays registered until the host exits, also after delete, so one that is a common word is replaced in the URLs, snapshots, and network filters of every session. A backslash right before the password is removed with it, and the target.text of pointer helpers is cut at 160 characters before it is redacted. Object keys and response bodies the browser reports as base64 are not redacted, a page in a legacy encoding other than Windows-1252 can send the password in a form that is not recognized, and a script can still read the password from the page field and transform it before returning it.

browser.session(action?)

current or list.

Saved states and login profiles are encrypted with the operating system keychain through Electron safeStorage.

Dialogs and confirmation:

Helper

Description

browser.setDialog(value)

Accepts a pending alert/confirm/prompt. Pass the text for a prompt.

browser.dismissDialog()

Dismisses a pending alert/confirm/prompt.

browser.confirm(id), browser.deny(id)

Runs or discards an action held by action confirmation.

Action confirmation

Start the host with --confirm-actions (or BROWSER_MCP_CONFIRM_ACTIONS) to hold selected helpers until they are confirmed:

browser-mcp-electron --mcp --confirm-actions navigate,upload,state

The list accepts helper names (click, fill, upload, ...) and these categories. The host does not start with a name it does not know:

Category

Helpers

navigate

navigate, back, forward, reload, pushstate

click

click, dblclick, leftClick, rightClick, check, uncheck, select, drag

fill

fill, type, press, keyboard

upload

upload

download

download

network

network, networkLogs, inspectNetworkRequest, set, setViewport, setEmulation, setColorScheme

state

state, auth, cookies, storage, clipboard

A held helper is not executed. The tool returns { confirmationRequired: true, confirmationId, action, message }. Run browser.confirm("confirm-1") to execute it with the original arguments, or browser.deny("confirm-1") to discard it. Each session keeps one pending confirmation; a newer held helper replaces it. browser.confirm must run in a later browser_run_actions call than the one that was held, and a held helper whose target was a DOM element cannot be confirmed: use a ref or a selector.

Helpers that perform another helper's action are held with it: browser.find(..., action) follows its action, browser.mouse("down" | "up"), browser.download and browser.upload count as click, browser.read(url) and browser.state("load") as navigate, browser.auth("login") as navigate, fill and click, and browser.wait({ download }) as download.

A sentinel that is already running keeps the list it was started with; starting a client with a different list fails instead of running without it.

Confirmation applies to browser helpers only. The script runs inside the page, so it can still call DOM APIs such as element.click() or set location.href directly.

Notes and limitations

  • The browser host runs with site isolation disabled so one DevTools session can reach iframes from every origin. Do not use it as a hardened browsing profile.

  • JavaScript dialogs (alert, confirm, prompt) are captured in every frame and reported as pendingDialog. An iframe sandboxed without allow-modals also reports them, although a regular browser would block the call.

  • A page cannot veto navigation with beforeunload: the host always leaves the page, and no dialog is reported.

  • While a dialog is pending, browser_run_actions only runs browser.setDialog and browser.dismissDialog; any other script returns pendingDialog without running. Navigating, going back or forward, or reloading from the window toolbar dismisses the dialog.

  • A dialog opened while a page is loading is reported like any other, by browser.navigate and by browser_toggle_session; the page finishes loading after the dialog is resolved. A dialog opened after the script returned, for example by a timer, is reported as pendingDialog next to result.

  • A page that closes itself with window.close() ends its session.

  • browser.navigate rejects javascript: URLs.

  • The target returned by pointer and focus helpers describes the element without the value of text fields. Read a value with browser.get("value", target).

  • The console counters in the snapshot header cover the current document only; browser.consoleLogs() keeps the entries of earlier pages.

  • The console buffer holds 200 entries. When it is full, the oldest entry that is not an uncaught exception is dropped first, so browser.errors() survives a noisy console. Once exceptions fill more than half of it, the oldest entry of any kind is dropped instead.

  • A middle click moves the pointer 40 pixels to the right and back while the button is down, because Chromium's autoscroll would otherwise swallow the next click. The page sees those two moves.

  • Keys and mouse buttons left down by browser.keyboard("down") or browser.mouse("down") are released when the script ends.

  • Request interception starts with the first browser.network("route", ...) call and stays on until the session closes. After unroute, requests still pass through the host and continue unchanged, which adds a small delay per request.

  • browser.clipboard reads and writes the clipboard of the logged-in user.

  • The HTTP sentinel listens on 127.0.0.1 without authentication. Any local process can call it, including the cookie, storage, and saved-state helpers.

Environment variables

Variable

Description

Default

BROWSER_MCP_DATA_DIR

Browser profile/session directory.

~/.browser-mcp

BROWSER_MCP_URL

Initial browser URL.

https://www.google.com

BROWSER_MCP_SENTINEL_PORT

HTTP sentinel port. Use 0 for a random available port.

55332

BROWSER_MCP_CONFIRM_ACTIONS

Comma-separated helpers or categories that require confirmation.

unset

BROWSER_MCP_DEBUG_LOG

Debug log path used by the launcher and Electron host.

OS temp file

BROWSER_MCP_RPC_PORT

Internal RPC port for detached Electron host mode.

unset

BROWSER_MCP_RPC_TOKEN

Internal RPC token for detached Electron host mode.

unset

Development

Install dependencies:

npm install

Run the app:

npm start

Run the recommended MCP mode from the local checkout:

npm run mcp

Check JavaScript syntax:

npm run check

Run tests:

npm test

The test suite starts local HTTP test pages and Browser MCP HTTP sentinels, then validates the public MCP tools (tests/mcp-browser-actions.test.js) and every browser helper (tests/mcp-agent-commands.test.js). It uses ports 55331, 55332, and 55351 to 55353; override them with BROWSER_MCP_TEST_PORT, BROWSER_MCP_AGENT_TEST_PORT, BROWSER_MCP_SENTINEL_PORT, and BROWSER_MCP_CONFIRM_SENTINEL_PORT.

The clipboard test is skipped by default because it writes to the system clipboard. It restores the previous text afterwards, and skips itself when the clipboard holds an image or files. Run it with:

BROWSER_MCP_TEST_CLIPBOARD=1 npm test

Session Copy browser extension

Load extensions/session_copy/chrome as an unpacked Chromium extension. Its Open in agent browser action exports the active HTTP(S) tab and calls the Browser MCP sentinel at http://127.0.0.1:55332/mcp. Keep the default sentinel port when using this action.

The imported session opens in a new agent browser window using the Browser MCP profile. The extension transfers the page URL, cookies, localStorage, and sessionStorage.

Troubleshooting

The MCP client cannot find browser-mcp-electron

Use the npx configuration or provide the absolute path to the binary.

Windows:

where.exe browser-mcp-electron

Linux/macOS:

command -v browser-mcp-electron

The sentinel starts, but the MCP client opens a new one

Make sure both commands use the same user account and, if you pinned a port, the same --sentinel-port value. The sentinel registry is stored in the OS temp directory and is scoped to the current machine/user environment.

Electron does not start on Linux

Install the Electron runtime libraries required by your distribution and start the sentinel from a graphical user session. For systemd, prefer a user service instead of a system service because Browser MCP needs access to the user's desktop session.

A page action times out

Pass a larger timeout_ms to browser_run_actions:

{
  "code": "await browser.sleep(15000); return browser.snapshot();",
  "timeout_ms": 20000
}

Action timeouts are clamped between 100 ms and 5 minutes.

A helper returns confirmationRequired

The host was started with --confirm-actions or BROWSER_MCP_CONFIRM_ACTIONS. Run browser.confirm(id) with the returned confirmationId to execute the action, or browser.deny(id) to discard it.

A ref no longer works

Refs belong to the latest snapshot of the current document. Run browser.snapshot() again after a navigation or a large re-render and use the new ref.

Multiple sessions are active

Pass the session_id returned by browser_toggle_session to browser_run_actions. When more than one session exists, Browser MCP requires explicit session selection.

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      Not graded
      quality
      D
      maintenance
      Enables MCP clients to drive a real, logged-in Chrome browser for web automation tasks like navigation, clicking, typing, and screenshotting.
      MIT
    • F
      license
      Not graded
      quality
      D
      maintenance
      Drive your real, signed-in Chrome browser from any MCP client, enabling browser automation such as navigation, clicking, typing, and screenshots through standard MCP tools.
      1
      -
    • A
      license
      B
      quality
      C
      maintenance
      Enables MCP clients to drive a real Chromium browser for automation, including navigation, JavaScript execution, CDP commands, network capture, and multi-tab control.
      7
      22 PyPI
      GPL 3.0
    • F
      license
      Not graded
      quality
      A
      maintenance
      Enables remote agents to control a local Chrome/Edge browser via MCP, supporting navigation, snapshots, clicks, typing, screenshots, and script execution.
      -