Safari's built-in MCP server for AI coding agents

By

Tagged: AI

Safari 27 ships with a native MCP server inside safaridriver. Here's how to enable it, connect Claude Code, Codex, or Cursor, inspect its 17 tools, and see how it compares to Playwright MCP.

I saw a post on X by Florian Beer pointing out something that flew completely under my radar: Safari now ships with its own built-in Model Context Protocol server.

No npm package, no Node.js runtime, no separate Chromium download. Apple baked it straight into macOS starting with Safari 27 (and Safari Technology Preview 247), inside /usr/bin/safaridriver.

I tested the binary directly on my Mac (macOS 27.2.1, Safari 27.2), probed its JSON-RPC handshake, and ran a live session against flaviocopes.com to see what works well and what still has rough edges.

What’s already sitting in /usr/bin

If you’re on macOS 27, the server is already on disk. Listing /usr/bin/safari* on my Mac shows 2 symlinks pointing to the same 167 KB binary inside /System/Cryptexes/App/usr/bin/safaridriver:

ls -l /usr/bin/safari*
lrwxr-xr-x  1 root  wheel  42 Nov  6 06:22 /usr/bin/safaridriver -> /System/Cryptexes/App/usr/bin/safaridriver
lrwxr-xr-x  1 root  wheel  42 Nov  6 06:22 /usr/bin/safarimcp -> /System/Cryptexes/App/usr/bin/safaridriver

Running --version and --help shows the exact Safari build and the new --mcp flag (along with -b, --bidi for WebDriver BiDi):

/usr/bin/safaridriver --version
/usr/bin/safaridriver --help
Included with Safari 27.2 (22625.2.8.11.9)
Usage: safaridriver [options]
	-h, --help                Prints out this usage information.
	--version                 Prints out version information and exits.
	-p, --port                Port number the driver should use...
	-b, --bidi                Port number the driver should use to listen for incoming
	                          WebSocket connections...
	--enable                  Applies configuration changes so that subsequent WebDriver
	                          sessions will run without further authentication.
	--diagnose                Causes safaridriver to log diagnostic information...
	--mcp                     Run as an MCP (Model Context Protocol) server using stdio
	                          transport. Reads JSON-RPC from stdin, writes to stdout.

Terminal output showing /usr/bin/safaridriver, /usr/bin/safarimcp, the Safari 27.2 version, and the --mcp flag

There’s a nice detail the official docs don’t mention.

You can run /usr/bin/safarimcp directly without passing --mcp.

Both commands invoke the same binary, and calling it as safarimcp drops you directly into JSON-RPC over stdin and stdout.

How to turn it on and connect an agent

Before any agent can open a page, Safari requires an explicit opt-in inside its settings:

  1. Open Safari > Settings > Advanced and check Show features for web developers.
  2. Open Safari > Settings > Developer and check Allow remote automation and external agents (or run safaridriver --enable in Terminal).

Safari Developer settings with Allow remote automation and external agents checked

Be careful with that second checkbox. If you leave it unchecked, /usr/bin/safaridriver --mcp still boots up, performs the MCP handshake, and lists all 17 tools to your agent.

Everything seems to work, until the first navigate_to_url call fails with this error:

Error Domain=WebDriverErrorDomain Code=6 "Could not create a session: You must enable 'Allow remote automation' in the Developer section of Safari Settings to control Safari via WebDriver."

Once the toggle is on, register the server with your agent.

For Claude Code (which I explain in the Claude Code Handbook):

claude mcp add safari-mcp -- "/usr/bin/safaridriver" --mcp

For OpenAI Codex (covered in the OpenAI Codex Handbook):

codex mcp add safari-mcp -- "/usr/bin/safaridriver" --mcp

For Cursor or any other client that reads mcp.json:

{
  "mcpServers": {
    "safari-mcp": {
      "command": "/usr/bin/safaridriver",
      "args": ["--mcp"]
    }
  }
}

If you’re testing with Safari Technology Preview (version 247 or later), point command at "/Applications/Safari Technology Preview.app/Contents/MacOS/safaridriver" with the same --mcp argument.

When your agent runs its first navigation prompt, Safari opens a window with a banner right below the toolbar saying "This window is controlled by <clientName>." (using the clientInfo.name sent during initialize) and a Stop button on the right:

Live Safari window controlled through the Safari MCP server showing the top banner and Stop button

As per Apple’s Connecting an AI agent to Safari guide, start your first prompt by asking to navigate to a URL instead of asking to list the tabs, because calling tab tools before a controlled window exists can return an error.

Here’s how the pieces talk to each other:

How Safari's built-in MCP server worksAn AI coding agent sends JSON-RPC messages over stdio to safaridriver with the --mcp flag, which drives an isolated Safari window with WebKit text extraction, Web Inspector console and network logs, and optional manual Touch ID login.JSON-RPC over stdioControls windowWebKit textTree + UIDsConsole, network, PNGpathTool result or diffManual passkey sign-inCoding agent/usr/bin/safaridriver--mcpIsolated SafariwindowYou + Touch ID

Probing the live server over stdio

Since the server speaks plain JSON-RPC over stdio, we can talk to it directly from a short Python script, without opening Safari or configuring an agent first.

I sent an initialize request, a notifications/initialized notification, and tools/list, resources/list and prompts/list to /usr/bin/safarimcp:

import json, select, subprocess, time

p = subprocess.Popen(
  ['/usr/bin/safarimcp'],
  stdin=subprocess.PIPE,
  stdout=subprocess.PIPE,
  text=True,
  bufsize=1
)

def rpc(msg, wait_id=None):
  p.stdin.write(json.dumps(msg) + '\n')
  p.stdin.flush()
  if wait_id is None:
    return None
  end = time.time() + 5
  while time.time() < end:
    if select.select([p.stdout], [], [], 0.2)[0]:
      obj = json.loads(p.stdout.readline())
      if obj.get('id') == wait_id:
        return obj

init = rpc({
  'jsonrpc': '2.0',
  'id': 1,
  'method': 'initialize',
  'params': {
    'protocolVersion': '2025-03-26',
    'capabilities': {},
    'clientInfo': {'name': 'probe', 'version': '1.0'}
  }
}, wait_id=1)['result']

rpc({'jsonrpc': '2.0', 'method': 'notifications/initialized'})
tools = rpc({'jsonrpc': '2.0', 'id': 2, 'method': 'tools/list', 'params': {}}, wait_id=2)['result']['tools']
p.stdin.close()
p.wait(timeout=3)

print(f"server:   {init['serverInfo']['name']} {init['serverInfo']['version']}")
print(f"protocol: {init['protocolVersion']}")
print(f"tools ({len(tools)}):")
for t in tools:
  print(f"  - {t['name']}")

Here’s the exact handshake response it returned:

{
  "id": 1,
  "jsonrpc": "2.0",
  "result": {
    "capabilities": {
      "tools": {}
    },
    "protocolVersion": "2024-11-05",
    "serverInfo": {
      "name": "Safari",
      "version": "1.0.0"
    }
  }
}

It exposes tools only.

Asking for resources/list or prompts/list returns JSON-RPC error -32601 (Method not found).

Terminal output of the live JSON-RPC handshake against /usr/bin/safarimcp listing serverInfo Safari 1.0.0 and all 17 tools

In total, Safari 27.2 registers 17 tools:

GroupToolsWhat they cover
Navigation and tabsnavigate_to_url, create_tab, list_tabs, switch_tab, close_tab, page_info, wait_for_navigationOpen pages, move across tabs, wait for loads, read title and URL
Reading and visualsget_page_content, screenshotWebKit text extraction with node UIDs, viewport or full-page PNGs
Interactionpage_interactions, browser_dialogs, evaluate_javascriptBatched clicks/typing/scrolling, alert/prompt handling, JS execution
Debugging and emulationbrowser_console_messages, list_network_requests, get_network_request, set_viewport_size, set_emulated_mediaConsole buffers, Inspector network details, viewport sizing, screen/print media

What stands out in the tool schemas

Reading the live tool schemas I noticed a few design choices that seem to target the biggest pain points of browser MCP servers: context bloat and slow round-trips.

Token-conscious text extraction (get_page_content)

Instead of returning raw HTML or a huge accessibility tree, get_page_content uses WebKit’s text extraction and defaults to a compact textTree format (it also supports markdown, text, json, html, plainText).

By default it only reads the visible viewport, truncates paragraphs to maxWordsPerParagraph: 15, removes URL query noise (shortenURLs: true) and only assigns node UIDs to interactive elements (nodeIds: "interactive").

If an output is still 32 kB or more, the server writes it to a temporary file and returns the file path, instead of blowing up your agent’s context window.

Node UIDs for interactions

When get_page_content or navigate_to_url returns elements like input uid=116, you pass that UID directly to page_interactions instead of guessing fragile CSS selectors.

The evaluate_javascript schema also mentions a $uid(N) macro (return $uid(42).href) and a frameId parameter for iframes. In my live test on Safari 27.2, plain JavaScript worked as expected, while calling return $uid(104).tagName threw Can't find variable: $uid. So for now, stick to standard DOM selectors inside evaluate_javascript.

Batched interactions that return diffs (page_interactions)

Most browser MCP servers make the model send one tool call to focus an input, one to type, one to click Submit, and so on, and every time it gets back a full page snapshot.

Safari’s page_interactions instead takes an array of actions (click, type, keyPress, scroll, selectText, selectMenuItem, hover, highlightText), runs them in order, with a 400 ms settle between steps, and returns a diff of what changed on the page (unless more than 50% of the page changed, in which case it returns the full text). If a click triggers navigation, it waits until the page is loaded before returning.

Screenshots stay on disk (screenshot)

screenshot saves a PNG to a temporary file (or savePath if passed) and returns the path, never inline base64.

This is because for an agent running locally in a terminal, passing a file path is much faster than shoving megabytes of base64 into stdout, and it keeps the JSON-RPC stream fast.

Driving flaviocopes.com in a live session

After checking Allow remote automation and external agents, I ran a real session against https://flaviocopes.com/ over /usr/bin/safarimcp.

Calling navigate_to_url opened the controlled Safari window above and returned WebKit’s textTree right away, with uid handles already attached to links and inputs:

root scrollPosition=(0,0) contentSize=[1180×3492]
  navigation label='Main navigation'
    link uid=112 url=/blog 'GUIDES'
    link uid=113 url=/courses
    link uid=114 url=/apps
    link uid=115 url=/newsletter
  form role=search label='Search this site' autocomplete=on
    input uid=116 title='Search 2,000+ posts' placeholder='Search 2,000+ posts'

Next I sent a single batched page_interactions call with 2 actions on uid=116: click the search box, then type mcp.

Safari ran both steps in one round-trip, reported "requested": 2, "successful": 2, and automatically switched to [full update — 77% changed] because live search results replaced most of the viewport:

{
  "url": "https://flaviocopes.com/",
  "format": "textTree",
  "requested": 2,
  "successful": 2,
  "steps": [
    "Clicked on input titled “Search 2,000+ posts” of type text with placeholder “Search 2,000+ posts” with class “svelte-e9gkc3”",
    "Inserted text into input titled “Search 2,000+ posts” of type text with placeholder “Search 2,000+ posts” with class “svelte-e9gkc3”"
  ]
}

A few other calls from the same session showed both the polish and 2 early quirks on Safari 27.2:

  • evaluate_javascript with return { title: document.title, links: document.querySelectorAll("a").length } returned {"title":"Flavio Copes","links":74}.
  • screenshot with savePath: "/tmp/safari-mcp-inpage.png" replied Saved screenshot to '/tmp/safari-mcp-inpage.png' (277.7 kB).
  • evaluate_javascript using the schema’s $uid(104) macro returned Can't find variable: $uid, and list_network_requests returned {"count":0,"requests":[]} after navigating to two pages.

Safari MCP vs Playwright MCP vs Chrome DevTools MCP

In my macOS browsers for AI agents guide, Safari only had WebDriver and Selenium, so Chrome with Playwright MCP and Chrome DevTools MCP were the obvious defaults.

Here’s how Safari’s native server stacks up next to them now:

FeatureSafari MCP (safaridriver --mcp)Playwright MCP (@playwright/mcp)Chrome DevTools MCP (chrome-devtools-mcp)
Install and runtimeBuilt into macOS 27 / Safari 27 (167 KB binary)npx @playwright/mcp@latest (Node.js)npx chrome-devtools-mcp@latest (Node.js)
Browser engineReal shipping Safari (WebKit)Chromium, Chrome, or patched WebKit/FirefoxChrome or Chrome for Testing
Tool surface17 tools24 toolsCDP inspection, traces, and automation tools
Default page readWebKit textTree with UIDs + 32 kB file spilloverAccessibility snapshotAccessibility snapshot + DevTools inspection
Interaction modelBatched page_interactions returning diffsSingle action per tool callSingle action per tool call
Session modelIsolated window (no personal cookies, history, or AutoFill)Isolated by default, or persistent --user-data-dir / extension attachIsolated or attach to Chrome remote debugging
Passkeys and Touch IDReal Safari window supports manual macOS Touch ID sign-inNo native iCloud Keychain Touch ID passkeys in Playwright ChromiumDepends on attaching to a regular signed-in Chrome profile
OS supportmacOS onlymacOS, Linux, WindowsmacOS, Linux, Windows

Notice the tool count too. In the MCP servers I actually use, one of my main complaints about browser and API servers is how quickly tool definitions pile up in every conversation. Keeping Safari’s surface at 17 focused tools with batched interactions is a much cleaner fit.

Privacy, isolation, and why Touch ID passkeys matter

Apple’s WebKit announcement post is very clear about the privacy boundary: the server runs locally, does not make any network calls on its own, and the window it controls is isolated from your personal browsing history, cookies, and AutoFill.

This is good news if you don’t want a coding agent to quietly read your personal Gmail tab or grab your saved form data.

But the flip side of using real Safari instead of a bundled Chromium or an Electron in-app browser is what Florian points out with Touch ID. When I wrote about how AI agents can log in without seeing your passwords, passkeys were one of the hardest walls for browser automation, because headless and bundled browsers do not participate in the macOS native iCloud Keychain Touch ID flow.

With Safari’s MCP server, the window is a real visible Safari window on your Mac. The agent can navigate to a site protected by a passkey, pause while you tap Touch ID yourself to sign into that isolated window, and then continue inspecting the authenticated dashboard, without ever touching your password manager or your personal tabs.

Keep in mind the other half of the privacy boundary: Apple doesn’t get anything from the MCP server, but every screenshot, console log, network response body, and extracted DOM node is sent to the AI agent and model you connect.

Once you’re done, click the Stop button in the Safari top banner, and only connect this to agents you trust.

How I would use it (and where it doesn’t fit)

I would use Safari MCP first for catching Safari-specific layout and CSS bugs on flaviocopes.com and my Astro apps. Playwright’s WebKit build is great for CI coverage, but it’s a patched WebKit binary, not the shipping Safari app. Letting Claude Code or Codex open http://localhost:4321 in real Safari, resize the viewport, and check browser_console_messages removes that last manual Safari pass.

I would also reach for it with admin panels behind Touch ID passkeys, where I don’t want to mint a separate API token or maintain a second Chrome profile. Letting the agent open the login page in Safari, while I tap Touch ID once, is much simpler than fighting an in-app browser.

And because /usr/bin/safaridriver --mcp ships with macOS, any Mac on macOS 27 has a real browser MCP server ready in one command, with no Node version mismatches or gigabyte browser downloads.

Where I would skip it and stay with Playwright or Chrome DevTools MCP:

  • Automated test suites and CI. Safari MCP is macOS-only and opens a visible window rather than a headless Linux container, so Playwright is still the right fit for repeatable end-to-end tests.
  • Deep performance profiling. list_network_requests and get_network_request cover headers, bodies, and timing, and you can read Navigation Timing via evaluate_javascript, yet Chrome DevTools MCP gives you full traces when hunting down slow renders.
  • Persistent logged-in agent profiles. Because Safari isolates every automation session, it won’t keep you signed in across restarts the way a dedicated Chrome --user-data-dir profile does.

If you already run macOS 27 with Claude Code, Codex or Cursor, just flip that Developer checkbox in Safari and add /usr/bin/safaridriver --mcp to your config.

Want me to talk about your product? You can sponsor this site.

Related posts about ai: