Skip to main content
Glama
README.md
# palmifer-mcp

Zero-dependency **Model Context Protocol (MCP)** server wrapping [palmifer](https://github.com/kjx-talesofai/claude-skill-palmifer) to drive **your real, logged-in Chrome** (or a throwaway headless Chrome) over CDP — built for sandboxed desktop AI apps (Gemini App, Claude Desktop, Cursor, Antigravity) where agent shell commands cannot read Chrome's `DevToolsActivePort` or bind `127.0.0.1`.

<details>
<summary><b>中文说明(点开)</b> —— 零依赖本地 Chrome MCP 服务:直连已登录 Chrome,支持无头隔离、只读结构化提取与自检管理</summary>

**它是什么**:把 `palmifer` 封装为宿主机侧的 **stdio MCP Server**(纯 Node.js ≥ 22,**228 KB 零第三方 npm 依赖**)。像 Gemini App 这类沙箱较严的桌面客户端,Agent 自己跑 shell 会遇到 `EPERM` / 无法连本地端口 / 无法启动子进程,通过 `palmifer-mcp` 就能直接把 25 个强类型浏览器工具暴露给 Agent。

**核心优势(v0.4.1 实测)**:
- **直连你已登录的真实 Chrome**:在 `chrome://inspect/#remote-debugging` 勾一次开关、弹窗点一次 **Allow**,后台 daemon 持久复用连接;支持 `new_window: true` 独立窗口隔离,不弄乱你的主窗口标签页,也不会因为你切 tab 变成 `hidden`。
- **毫秒级直连快路径**:MCP Server 对已运行的本地 daemon 直接走 `127.0.0.1` loopback HTTP,跳过每次拉起 Node 子进程的 ~150 ms 开销(实测 `browser_tabs` p50 **0.97 ms** vs 子进程模式 **156.3 ms**);`private_start` 冷启动 **823 ms**,首次整套启动→打开公网页面 **1,874 ms**(快于 `@playwright/mcp` 3,389 ms 与 `chrome-devtools-mcp` 2,808 ms)。
- **省 Token 15x–24x 的免弹窗只读读取**:`browser_dom(fields=...)` 用纯 DOM 选择器一次抽取出干净 JSON 数组(穿透 Shadow DOM、自动把相对链接解析为绝对 `https://...`、跳过空骨架行、支持 `dedupe_by` 去重),无需触发高风险的 `browser_eval` 弹窗;`browser_text(main_only=true)` 自动剔除 `nav/header/footer/aside` 噪音。7 个真实公网站点只读总计 **5,291 tokens**(对比 `chrome-devtools-mcp` **79,690 tokens**、`@playwright/mcp` **125,847 tokens**;即使使用有界 AX 树 `browser_snapshot(limit=220)` 也仅 **10,289 tokens**)。
- **权限分级与防越权**:`readOnlyHint`(7 个)、`destructiveHint: false`(10 个)、`destructiveHint: true`(8 个);`browser_batch` 严格禁止内部夹带破坏性工具(`browser_eval` / `browser_click` 等),并直接内嵌原生 JSON `data` 减少回传体积;`--` 参数分隔符与沙箱路径校验防止命令行/路径注入。
- **自带排障与托管 CLI**:`palmifer-mcp doctor` 一眼看清当前 MCP 入口、daemon PID、运行中脚本路径和代码是否过期(`mcpStale` / `daemon.stale`);`palmifer-mcp daemon install` 可把 daemon 装为 macOS LaunchAgent 跑在宿主桌面会话中,彻底解决 Gemini App 沙箱内无法启动无头 Chrome(Mach IPC `bootstrap_check_in` 被拒)的问题。

</details>

## Architecture

```
MCP Host (Gemini App / Claude Desktop / Cursor / Antigravity)
  │  stdio JSON-RPC 2.0
  ▼
palmifer-mcp (0.4.1, Node >= 22, 228 KB, zero deps)
  ├── fast-path: direct 127.0.0.1:8798 HTTP /run (~0.97 ms p50)
  └── fallback:  spawn vendor/palmifer/palmifer.mjs (starts daemon on first call)
        │
        ▼
  palmifer daemon (127.0.0.1:8798, token-auth)
        ├── real mode    ──CDP──▶ Your Chrome (existing logins, 1x Allow)
        ├── anon context ──CDP──▶ Cookie-less window inside current Chrome
        └── private mode ──CDP──▶ Throwaway headless Chrome (~823 ms cold start)
```

## Measured Benchmark (`v0.4.1` vs Competitors)

Head-to-head benchmark across **9 real websites** (Authenticated: `X.com`, `Bilibili.com`; Public: `simonwillison.net`, `lobste.rs`, `ithome.com`, `sspai.com`, `bbc.com/news`, `en.wikipedia.org`, `github.com/trending`) plus Shadow DOM / iframe fixtures. Full methodology and per-site tables live in [bench/RESULTS.md](bench/RESULTS.md).

| KPI | `palmifer-mcp 0.4.1` | `@playwright/mcp 0.0.86` | `chrome-devtools-mcp 1.14.0` |
|---|---:|---:|---:|
| **Install size / deps** | **228 KB (0 deps)** | 19,176 KB | 12,508 KB |
| **Schema prompt tax (`tools/list`)** | **4,516 tokens** | 5,300 tokens | 8,303 tokens |
| **Cold start → first page ready** | **1,874 ms** | 3,389 ms | 2,808 ms |
| **7-site read-only `text(main_only)` tokens** | **5,291 tokens** *(AX snap: 10,289)* | 125,847 tokens (23.8x) | 79,690 tokens (15.1x) |
| **Structured Top-5 extract** | **2.9–5.3 ms** (`readOnlyHint: true`) | 506–1,823 ms (`destructiveHint: true`) | 101–106 ms (`evaluate_script`) |
| **Multi-step browse (`github.com/trending`)** | **2 rounds / 466.4 ms / 441 tok** | 4 rounds / 2,053.0 ms / 779 tok | 4 rounds / 799.3 ms / 533 tok |
| **Shadow DOM + Iframe read-only** | 6.32 ms / **44 tokens** | **3.37 ms** / 84 tokens | 3.63 ms / 78 tokens |
| **Authenticated `X.com` & `Bilibili.com`** | **Real logged-in feed (both)** | Hit X login wall / guest view | Hit X login wall / guest view |

## Requirements

- **Node.js >= 22** (zero `npm install` needed)
- **Google Chrome / Chromium / Edge / Brave**

To drive your own signed-in Chrome:
1. Open `chrome://inspect/#remote-debugging` in Chrome
2. Tick **"Allow remote debugging for this browser instance"**
3. Click **Allow** once when Chrome prompts on first connection

## Install & Configure

Keep a stable local path under `~/.mcp/servers/` so MCP clients never point at temporary folders:

```bash
mkdir -p ~/.mcp/servers
git clone https://github.com/kjx-talesofai/palmifer-mcp.git ~/.mcp/servers/palmifer-mcp
node ~/.mcp/servers/palmifer-mcp/bin/palmifer-mcp.mjs config --stable
```

Add to your MCP host (Gemini App, Claude Desktop, Cursor, Antigravity):

```json
{
  "mcpServers": {
    "palmifer": {
      "command": "/opt/homebrew/bin/node",
      "args": [
        "/Users/<you>/.mcp/servers/palmifer-mcp/bin/palmifer-mcp.mjs"
      ],
      "env": {
        "PALMIFER_MCP_KEEP_DAEMON": "1"
      }
    }
  }
}
```

> **Tip:** Replace `/opt/homebrew/bin/node` with the output of `which node` so GUI apps (which don't inherit shell `PATH`) can always launch Node >= 22. Setting `PALMIFER_MCP_KEEP_DAEMON=1` keeps your Chrome **Allow** approval alive across MCP reconnects; set `"0"` if you want the daemon stopped on MCP exit.

### Optional LaunchAgent (Recommended for Sandboxed Hosts like Gemini App)

Sandboxed macOS desktop apps (such as Gemini App's Seatbelt sandbox) block child processes from using Chrome's Mach IPC (`bootstrap_check_in: Permission denied`), which makes headless `private_start` fail inside the sandbox. Running the `palmifer` daemon in your normal user LaunchAgent session solves both **headless `private_start`** and **persistent Chrome Allow** across app restarts:

```bash
node ~/.mcp/servers/palmifer-mcp/bin/palmifer-mcp.mjs daemon install
```

Manage or inspect anytime:

```bash
node ~/.mcp/servers/palmifer-mcp/bin/palmifer-mcp.mjs doctor          # inspect PID, script paths, stale code
node ~/.mcp/servers/palmifer-mcp/bin/palmifer-mcp.mjs restart         # stop running daemon so new disk code loads
node ~/.mcp/servers/palmifer-mcp/bin/palmifer-mcp.mjs daemon status   # check LaunchAgent status
node ~/.mcp/servers/palmifer-mcp/bin/palmifer-mcp.mjs daemon uninstall
```

### Environment Variables

| Variable | Description | Default |
|---|---|---|
| `PALMIFER_BIN` | Override path to `palmifer.mjs` | `vendor/palmifer/palmifer.mjs` |
| `PALMIFER_STATE_DIR` | Daemon state directory (for multi-client isolation) | `~/.cache/palmifer` (falls back to `$TMPDIR/palmifer-<uid>`) |
| `PALMIFER_DAEMON_PORT` | Daemon loopback HTTP port | `8798` |
| `PALMIFER_MCP_KEEP_DAEMON` | Keep daemon alive on MCP exit (`"1"` or `"0"`) | `"0"` |
| `PALMIFER_MCP_DIRECT_HTTP` | Set `"0"` to disable direct HTTP fast-path and always spawn | `"1"` |
| `PALMIFER_MCP_TIMEOUT_MS` | Per-tool execution timeout (ms) | `180000` |
| `PALMIFER_FAST` | Set `"1"` to skip human-paced delays globally | `"0"` |
| `PALMIFER_CHROME_FLAGS` | Extra Chrome flags for `private_start` | Inherits `HTTPS_PROXY`/`HTTP_PROXY`/`ALL_PROXY` automatically |

## Tools (25)

Tools carry MCP `ToolAnnotations` so hosts can auto-approve read-only & low-risk calls while prompting on destructive actions:

### Read-Only (`readOnlyHint: true, destructiveHint: false`)
- `browser_status` — Daemon, CDP mode/tabs, plus `mcp` diagnostics (`version`, `pid`, `entry`, `mcpStale`, `daemon.stale`)
- `browser_tabs` — List open tabs with index, `targetId`, `mine`, `anon`, title, URL
- `browser_frames` — List `#fN` iframes in a tab
- `browser_snapshot` — Accessibility tree with `@eN` refs (`actionable_only`, `filter`, `limit`)
- `browser_text` — Visible `innerText`, with `main_only=true` (strips `nav`/`header`/`footer`/`aside` clutter) or `selector`
- `browser_dom` — Shadow-DOM-piercing query & **read-only structured JSON extractor** via `fields` (`"."`, `"@attr"`, `"<css>"`, `"<css>@<attr>"`, trailing `"[]"`), with automatic `resolve_urls`, `skip_empty`, and `dedupe_by`
- `browser_wait` — Wait for CSS selector or visible text

### Non-Destructive Navigation & Capture (`readOnlyHint: false, destructiveHint: false`, `openWorldHint` where noted)
- `browser_mode` — `private_start` (`http(s)|about:blank` URL only, `openWorldHint: true`), `private_status`, `use_private`, `use_real`, `anon_on`, `anon_status`
- `browser_open` — Open URL in new tab or isolated window (`new_window=true`, `background=true`)
- `browser_goto` — Navigate current/specified tab (reuses isolated window)
- `browser_use_tab` — Select active tab by index string, `targetId`, or substring
- `browser_front` — Bring hidden tab to front (prefer `front=true` directly on actions)
- `browser_scroll` — Real `mouseWheel` scrolling (`down` / `up` / `bottom` / `top`)
- `browser_screenshot` — PNG/JPEG/WebP capture (`full`, `scale`, `max_width`, `annotate`, `include_image`)
- `browser_pdf` — Render tab to PDF on disk
- `browser_network` — Capture & inspect XHR/fetch traffic (`start`, `list`, `detail`, `stop`)
- `browser_batch` — Run multiple read-only / non-destructive steps in one call with native JSON `data` (rejects `destructiveHint=true` tools)

### Destructive / State-Changing (`destructiveHint: true`)
- `browser_click` — Trusted click by `@eN`, CSS, text, or `(x, y)` (`front`, `fast`, `verify`)
- `browser_fill` — Trusted focus + clear + type into input (`front`, `fast`, `verify`)
- `browser_press` — Trusted key press (`Enter`, `Tab`, `Escape`, `Meta+A`, etc.)
- `browser_upload` — Attach local files to `<input type="file">`
- `browser_eval` — Evaluate arbitrary JS in page/iframe
- `browser_close_tab` — Close specific tab, `mine=true`, or `all=true`
- `browser_session` — Teardown & lifecycle: `browser_close`, `anon_off`, `cancel`, `stop`, `restart_daemon`
- `browser_cdp` — Raw CDP `Domain.method` escape hatch

## Tests & Benchmark

```bash
npm run check      # syntax check all .mjs files
npm test           # 14 unit, schema, security-hardening, batch-guard, stale-detection, and Mach sandbox fast-fail tests
npm run test:e2e   # full headless Chrome E2E suite (private_start, dom fields, text main_only, trusted events, upload, iframe, pdf, network, batch, anon, public web, HTTP vs spawn benchmark)
```

## Author

<p>
  <a href="https://hypersampling.com">
    <img src="https://assets.hypersampling.com/hyper-sampling-2.jpg" alt="hypersampling" height="38"/>
  </a>
</p>

Built by [Jiaxin Kou](https://hypersampling.com) · [GitHub](https://github.com/kjx-talesofai)

## License

MIT — see [LICENSE](LICENSE).

TDQS

B3.3/5.0

Scored across 25 tools

Disambiguation4/5

Most tools have clearly distinct purposes, and descriptions actively steer between overlapping extraction modes (text vs dom vs snapshot) and lifecycle controls (mode vs session). Minor ambiguity remains around status variants, tab closing vs browser closing, and front vs use_tab.

Naming Consistency4/5

All tools consistently use the browser_ prefix with snake_case suffixes, making the namespace predictable. However, many names are noun-oriented (browser_tabs, browser_status, browser_pdf) rather than strict verb_noun action names.

Tool Count3/5

25 tools sits at the heavy end for a single MCP server. Browser automation justifies many primitives, but the inclusion of advanced/control tools like cdp, batch, network, and session makes the surface feel broad and borderline bloated.

Completeness4/5

The set covers navigation, tab lifecycle, extraction, interaction, waits, screenshots, PDF/upload, network inspection, CDP, and batching. Minor gaps such as dedicated hover/drag/select or cookie/storage management exist, though most are workaroundable via eval or raw CDP.