Skip to content
agentic-browser

MCP Server

The MCP (Model Context Protocol) server exposes agentic-browser as native tools in AI coding assistants. Instead of shelling out to CLI commands, the assistant calls structured tools directly — no JSON parsing, no shell escaping, no subprocess overhead.

Setup

Automatic

npx agentic-browser setup

Detects Claude Code and Cursor, then writes the config for you.

Manual: Claude Code

Add to .mcp.json in your project root:

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

Manual: Cursor

Add to .cursor/mcp.json in your project root:

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

Use your existing Chrome

To control a Chrome you already have open (with all your sessions and cookies), launch Chrome with --remote-debugging-port=9222 --user-data-dir=<dir> (Chrome 136+ ignores the port on the default profile) and add AGENTIC_BROWSER_CDP_URL to your MCP config:

{
  "mcpServers": {
    "agentic-browser": {
      "command": "npx",
      "args": ["agentic-browser", "mcp"],
      "env": {
        "AGENTIC_BROWSER_CDP_URL": "http://127.0.0.1:9222"
      }
    }
  }
}

Alternatively, launch a fresh Chrome with your default profile (Chrome must be closed first):

{
  "mcpServers": {
    "agentic-browser": {
      "command": "npx",
      "args": ["agentic-browser", "mcp"],
      "env": {
        "AGENTIC_BROWSER_USER_PROFILE": "default"
      }
    }
  }
}

Run headless with a custom user-agent:

{
  "mcpServers": {
    "agentic-browser": {
      "command": "npx",
      "args": ["agentic-browser", "mcp"],
      "env": {
        "AGENTIC_BROWSER_HEADLESS": "true",
        "AGENTIC_BROWSER_USER_AGENT": "MyBot/1.0"
      }
    }
  }
}

Other MCP Clients

Any MCP-compatible client can connect via stdio transport:

npx agentic-browser mcp

The server communicates over stdin/stdout using the MCP JSON-RPC protocol.

Tools

browser_start_session

Start a Chrome browser session. Most workflows do not need to call this explicitly because browser tools auto-start a session when needed.

Parameters: None

Returns: Session object with sessionId, status, startedAt. (authTokenRef is omitted from MCP responses.)


browser_navigate

Navigate the browser to a URL. After successful navigation, the server also attempts a best-effort cookie-banner dismissal and includes the result when something was dismissed.

ParameterTypeRequiredDescription
urlstringYesThe URL to navigate to
sessionIdstringNoUses active session if omitted

Returns: resultStatus, resultMessage, currentUrl, and optional cookieBanner. On failure, also includes errorCode.


browser_interact

Interact with a page element or perform browser-level actions.

Element actions: click, type, press, waitFor, scroll, hover, select, toggle

Navigation actions: goBack (browser back), goForward (browser forward), refresh (reload page)

Dialog action: dialog (handle JS alert/confirm/prompt)

ParameterTypeRequiredDescription
actionstringYesOne of the actions listed above
refstringNoElement ref from browser_get_elements (e.g. "e3") — preferred way to target
selectorstringNoCSS selector for the target element (escape hatch when no ref applies)
fallbackSelectorsstring[]NoBackup CSS selectors tried if the primary selector fails
textstringNoText to type (for type), or "dismiss" to dismiss a dialog (for dialog)
keystringNoKey to press (for press action, e.g. "Enter")
valuestringNoOption value (for select), or prompt text (for dialog)
scrollXnumberNoHorizontal scroll delta in pixels (for scroll)
scrollYnumberNoVertical scroll delta in pixels (for scroll, positive = down)
timeoutMsnumberNoTimeout in ms (for waitFor action)
sessionIdstringNoUses active session if omitted

Target an element with ref (from browser_get_elements) — the way you point at something you see rather than describing its markup. selector remains available as an escape hatch; if both are given, selector wins. A ref that no longer resolves (the page changed since it was discovered) fails with SELECTOR_NOT_FOUND and a hint to re-run browser_get_elements.

Navigation actions (goBack, goForward, refresh) and dialog don't require a target.

Returns: resultStatus, resultMessage, and currentUrl. On failure, also includes errorCode.

Page state after acting: after a successful action that can change the page (everything except hover and waitFor), the response also includes pageState — a fresh element snapshot with new refs and a summary. You see the result of your action and can pick the next one without a separate browser_get_elements call. The refs inside pageState supersede any earlier ones.

Error codes: When resultStatus is "failed", the errorCode field contains one of: SELECTOR_NOT_FOUND, ELEMENT_COVERED, ELEMENT_NOT_EDITABLE, NAVIGATION_TIMEOUT, NAVIGATION_FAILED, CDP_DISCONNECTED, SESSION_DEAD, DIALOG_BLOCKING, TIMEOUT, UNKNOWN.


browser_get_content

Get the current page content. MCP responses are compacted for LLMs so the model can understand page structure without parsing a large raw blob first.

ParameterTypeRequiredDefaultDescription
mode"title" | "text" | "html" | "a11y" | "summary"No"summary"Extraction mode
selectorstringNoCSS selector to scope content
maxCharsnumberNoMax characters to return (default: 8000 for text, 10000 for a11y, 4000 for html, ignored for summary/title)
sessionIdstringNoUses active session if omitted

summary is the recommended first read because it returns a low-token overview with title, headings, landmarks, primaryActions, inputs, alerts, iframe metadata, contentExcerpt (up to 1500 chars of visible text), and forms (grouped form fields with labels, types, required status, and current values), including whether frames are same-origin or cross-origin.

Text, HTML, and accessibility content are automatically truncated at the default maxChars limit. When truncated, the response includes a truncated: true flag and a notice. Use a CSS selector to scope content instead of raising the limit.

Response shape by mode:

  • summary: { mode, url, title, headings, landmarks, primaryActions, inputs, alerts, frames, totalInteractiveElements, truncatedInteractiveElements, contentExcerpt, forms }
  • title: { mode, content, truncated }
  • text: { mode, content, truncated, summaryLines, previewLines }
  • a11y: { mode, content, truncated, headings, landmarks, actions, inputs, previewLines }
  • html: { mode, content, truncated }

browser_get_elements

Discover interactive elements on the page. Each element gets a short ref ("e1", "e2", …) that you pass to browser_interact — you point at what you see instead of authoring a CSS selector. Refs stay valid while the page URL is unchanged; after a navigation, call browser_get_elements again. A fresh look supersedes the old refs, and the CLI (agent elements) shares the same refs. The underlying selectors (including >>> crossings for open shadow roots and same-origin iframes) are resolved server-side, so they never need to appear in your calls.

ParameterTypeRequiredDefaultDescription
rolesstring[]NoallFilter: "link", "button", "input", "select", "textarea", "checkbox", "radio", "contenteditable", "custom"
visibleOnlybooleanNotrueOnly visible elements
limitnumberNo50Max elements to return
selectorstringNoScope to a subtree
sessionIdstringNoUses active session if omitted

Returns:

{
  "elements": [
    {
      "ref": "e1",
      "role": "button",
      "text": "Login"
    }
  ],
  "totalFound": 42,
  "truncated": true,
  "summary": {
    "countsByRole": {
      "button": 12,
      "link": 18
    },
    "primaryActions": [{ "ref": "e1", "role": "button", "text": "Login" }]
  }
}

MCP responses replace raw selectors with the ref handle, and omit visible (always true when visibleOnly is true), actions (derivable from role), tagName (redundant with role), and enabled when it is true. The full selector-based view (including selector/fallbackSelectors) is still available via the programmatic API.


browser_search_memory

Search task memory for previously learned selectors, selector aliases, and interaction patterns. Results include selectorHints (proven selectors) and selectorAliases (human-readable names mapped to selectors with fallbacks).

ParameterTypeRequiredDefaultDescription
taskIntentstringYesWhat you want to do, e.g. "login:github.com"
siteDomainstringNoDomain to scope search
limitnumberNo5Max results

browser_dismiss_cookies

Dismiss a cookie or consent banner on the current page. The tool tries fast DOM heuristics first, then falls back to the accessibility tree for banners that are harder to target.

ParameterTypeRequiredDescription
sessionIdstringNoUses active session if omitted

browser_screenshot

Take a screenshot of the current page and return the image as a base64-encoded string.

ParameterTypeRequiredDefaultDescription
formatstringNo"jpeg"Image format: "jpeg" or "png"
qualitynumberNoJPEG quality (0-100, ignored for PNG)
fullPagebooleanNofalseCapture the full scrollable page
sessionIdstringNoUses active session if omitted

Returns: Base64-encoded image data.


browser_stop_session

Stop the browser session and terminate Chrome.

ParameterTypeRequiredDescription
sessionIdstringNoUses active session if omitted

Session Management

The MCP server tracks a single active session. When you call browser_start_session, the returned sessionId becomes the active session. All subsequent tool calls use it automatically unless you pass a specific sessionId.

When the MCP client disconnects, the server automatically cleans up any active session.

Example Workflow

A typical sequence an AI assistant would use:

  1. browser_start_session — optional, launch Chrome explicitly
  2. browser_navigate with url: "https://github.com/login" — cookie dismissal runs automatically after successful navigation
  3. browser_get_content with mode: "summary" — get the low-token overview first
  4. browser_get_elements — get labeled elements with refs (e1, e2, …) and summarized primary actions
  5. browser_interact with action: "type", ref: "e1" (the login field), text: "username" — the response's pageState shows the updated page
  6. browser_interact with action: "type", ref: "e2" (the password field), text: "***"
  7. browser_interact with action: "click", ref: "e3" (the submit button) — pageState reflects where you landed
  8. browser_get_content with mode: "text" or mode: "a11y" only when the summary is not enough
  9. browser_stop_session — done

Because each browser_interact returns a fresh pageState, you often only need step 4 once — subsequent refs come back with every action.