nodriver-mcp
nodriver-mcp
一个本地 Codex MCP 服务器,用于使用 nodriver 进行经过身份验证的浏览器研究。它在两次运行之间保留专用的 Chromium/Helium 配置文件,并热重载特定任务的 Python 爬虫。
设置
需要 Python 3.11+、uv 以及基于 Chromium 的浏览器。
uv sync --locked将其添加到 ~/.codex/config.toml,并将每个占位符替换为绝对路径:
[mcp_servers.nodriver]
command = "uv"
args = ["--directory", "<path-to-nodriver-mcp>", "run", "--frozen", "nodriver-mcp"]
startup_timeout_sec = 30
tool_timeout_sec = 600
[mcp_servers.nodriver.env]
NODRIVER_MCP_BROWSER_EXECUTABLE = "<path-to-helium-or-chromium>"
NODRIVER_MCP_USER_DATA_DIR = "<path-to-a-dedicated-browser-profile>"
NODRIVER_MCP_SCRIPTS_DIR = "<path-to-nodriver-mcp>/scrapers"
NODRIVER_MCP_ARTIFACTS_DIR = "<path-to-nodriver-mcp>/artifacts"更改 MCP 配置后重新启动 Codex。浏览器会延迟启动。默认情况下浏览器是可见的,因此您可以登录专用配置文件一次;其 Cookie 会持久保存。当提示明确要求无头浏览时,Codex 会传入 headless=true,否则选择可见模式。切换模式会重新启动受管浏览器,同时保留配置文件。
Related MCP server: chrome-mcp
使用
例如,对 Codex 说:
使用我的浏览器会话在 example.com 上查找匹配的项目。检查页面,创建可重用的爬虫,运行它,并将大量结果保存为工件。以无头模式运行。
Codex 可以使用浏览器工具检查页面,然后保存并运行爬虫。每次 scraper_run 都会重新读取文件,因此无需重启 MCP 服务器即可应用编辑:
async def scrape(ctx, params):
if url := params.get("url"):
await ctx.goto(url)
items = await ctx.evaluate_json("""
Array.from(document.querySelectorAll('article')).map(item => ({
title: (item.querySelector('h2')?.innerText || '').trim(),
href: item.querySelector('a')?.href || null
}))
""")
return {"items": items}入口点必须是 async def scrape(ctx, params) 并返回与 JSON 兼容的数据。建议使用一次批量 ctx.evaluate_json(...) 调用。对于大量结果,请使用 ctx.write_artifact(...)。爬虫必须使用异步操作,并在返回前完成所有任务。
测试
uv run --frozen ruff check src tests
uv run --frozen pytest安全性
仅在 STDIO 上本地运行此服务器。爬虫是未经沙箱化的 Python,拥有 MCP 进程的操作系统访问权限以及对经过身份验证的浏览器的控制权。切勿暴露 Cookie、令牌、密码或 DevTools 端点;将页面内容视为不可信;仅使用您有权访问的数据;并遵守站点条款和速率限制。浏览器配置文件、生成的爬虫和工件可能包含私人数据,不应提交。
Available Tools
9 toolsbrowser_closeClose browser sessionADestructiveIdempotent
Close the managed browser, or close MCP-owned tabs and detach in attach mode.
Inputs: no named parameters. Returns: object
browser_openOpen browser tabADestructive
Open or navigate an MCP tab, reusing the active tab unless new_tab is true.
Inputs: url, new_tab, headless. Returns: object
browser_queryQuery page elementsARead-only
Return text and safe attributes for elements matching a CSS selector.
Inputs: selector (required), limit, tab_id. Returns: object
browser_snapshotRead page contentARead-only
Return bounded visible text or outer HTML, optionally scoped to a CSS selector.
Inputs: format, tab_id, selector, max_chars. Returns: object
browser_statusBrowser statusARead-only
Report browser state and metadata for MCP-accessible tabs.
Inputs: no named parameters. Returns: object
scraper_getRead scraperARead-only
Return a saved scraper's source and metadata.
Inputs: name (required). Returns: object
scraper_listList scrapersARead-only
List metadata for saved scrapers.
Inputs: no named parameters. Returns: object
scraper_runRun scraperADestructive
Hot-load and run a saved scraper. Use either url or tab_id; new_tab requires url.
Inputs: name (required), url, params, tab_id, +3 more. Returns: object
scraper_saveSave scraperADestructive
Validate and atomically save a scraper for the next run.
Inputs: name (required), source (required), expected_revision. Returns: object
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 9 tools
Tools are generally distinct, but browser_open and scraper_run could confuse an agent: both involve navigation, though scraper_run is specifically for executing a saved scraper. Descriptions mitigate this ambiguity largely.
All tools follow a consistent verb_noun pattern with clear prefixes (browser_ and scraper_), making the purpose predictable and easy to navigate.
Nine tools cover both browser interaction and scraper management without excess or deficiency, well-scoped for a focused MCP server.
The set covers core browser operations and CRUD-like scraper management (list, get, save, run), but lacks a delete scraper tool, which is a minor gap for full lifecycle management.
Maintenance
Related MCP Connectors
One MCP server for all web data. Scrape, search, crawl, and AI research in one install.
Programmatic web-scraping MCP server powered by x402 micro-transactions on Base.
MCP server to assist with JxBrowser development.
Hosted Web Crawler MCP server for Claude, ChatGPT and Cursor, with each action switched per account.
Related MCP Servers
- AlicenseNot gradedqualityDmaintenanceMCP server that exposes the Pinchtab browser API for token-efficient web scraping, change detection, and automated testing workflows.15MIT
- AlicenseNot gradedqualityDmaintenanceLocal MCP server for persistent Chrome automation with multi-profile support, enabling tab management, page inspection, element interaction, JavaScript evaluation, and screenshots while preserving login sessions across restarts.3MIT
- AlicenseNot gradedqualityCmaintenanceA hardened local browser MCP server that drives your existing Chrome over the DevTools Protocol, providing token-efficient Markdown extraction and stealth features to avoid trivial automation detection.5 npm1MIT
- FlicenseNot gradedqualityBmaintenanceEnables local-first web scraping and captcha solving via an MCP server written in Rust.-