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 setupDetects 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 mcpThe 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.
| Parameter | Type | Required | Description |
|---|---|---|---|
url | string | Yes | The URL to navigate to |
sessionId | string | No | Uses 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)
| Parameter | Type | Required | Description |
|---|---|---|---|
action | string | Yes | One of the actions listed above |
ref | string | No | Element ref from browser_get_elements (e.g. "e3") — preferred way to target |
selector | string | No | CSS selector for the target element (escape hatch when no ref applies) |
fallbackSelectors | string[] | No | Backup CSS selectors tried if the primary selector fails |
text | string | No | Text to type (for type), or "dismiss" to dismiss a dialog (for dialog) |
key | string | No | Key to press (for press action, e.g. "Enter") |
value | string | No | Option value (for select), or prompt text (for dialog) |
scrollX | number | No | Horizontal scroll delta in pixels (for scroll) |
scrollY | number | No | Vertical scroll delta in pixels (for scroll, positive = down) |
timeoutMs | number | No | Timeout in ms (for waitFor action) |
sessionId | string | No | Uses 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.
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
mode | "title" | "text" | "html" | "a11y" | "summary" | No | "summary" | Extraction mode |
selector | string | No | CSS selector to scope content | |
maxChars | number | No | Max characters to return (default: 8000 for text, 10000 for a11y, 4000 for html, ignored for summary/title) | |
sessionId | string | No | Uses 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.
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
roles | string[] | No | all | Filter: "link", "button", "input", "select", "textarea", "checkbox", "radio", "contenteditable", "custom" |
visibleOnly | boolean | No | true | Only visible elements |
limit | number | No | 50 | Max elements to return |
selector | string | No | Scope to a subtree | |
sessionId | string | No | Uses 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).
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
taskIntent | string | Yes | What you want to do, e.g. "login:github.com" | |
siteDomain | string | No | Domain to scope search | |
limit | number | No | 5 | Max 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.
| Parameter | Type | Required | Description |
|---|---|---|---|
sessionId | string | No | Uses active session if omitted |
browser_screenshot
Take a screenshot of the current page and return the image as a base64-encoded string.
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
format | string | No | "jpeg" | Image format: "jpeg" or "png" |
quality | number | No | JPEG quality (0-100, ignored for PNG) | |
fullPage | boolean | No | false | Capture the full scrollable page |
sessionId | string | No | Uses active session if omitted |
Returns: Base64-encoded image data.
browser_stop_session
Stop the browser session and terminate Chrome.
| Parameter | Type | Required | Description |
|---|---|---|---|
sessionId | string | No | Uses 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:
browser_start_session— optional, launch Chrome explicitlybrowser_navigatewithurl: "https://github.com/login"— cookie dismissal runs automatically after successful navigationbrowser_get_contentwithmode: "summary"— get the low-token overview firstbrowser_get_elements— get labeled elements with refs (e1,e2, …) and summarized primary actionsbrowser_interactwithaction: "type",ref: "e1"(the login field),text: "username"— the response'spageStateshows the updated pagebrowser_interactwithaction: "type",ref: "e2"(the password field),text: "***"browser_interactwithaction: "click",ref: "e3"(the submit button) —pageStatereflects where you landedbrowser_get_contentwithmode: "text"ormode: "a11y"only when the summary is not enoughbrowser_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.