Skip to main content
Glama

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 を再起動してください。ブラウザは遅延起動します。デフォルトでは可視モードで起動するため、専用プロファイルに一度サインインできます。そのクッキーは永続化されます。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 互換のデータを返す必要があります。1 回の一括 ctx.evaluate_json(...) 呼び出しを推奨します。大きな結果には ctx.write_artifact(...) を使用してください。スクレイパーは非同期操作を使用し、すべてのタスクを完了してから返す必要があります。

テスト

uv run --frozen ruff check src tests
uv run --frozen pytest

セキュリティ

このサーバーは STDIO 経由でのみローカルで実行してください。スクレイパーはサンドボックス化されていない Python で、MCP プロセスの OS アクセス権と認証済みブラウザの制御権を持ちます。クッキー、トークン、パスワード、DevTools エンドポイントを絶対に公開しないでください。ページコンテンツは信頼できないものとして扱い、アクセスが許可されたデータのみを使用し、サイトの利用規約とレート制限を尊重してください。ブラウザプロファイル、生成されたスクレイパー、アーティファクトには個人データが含まれる可能性があるため、コミットしないでください。

Available Tools

9 tools
browser_closeClose browser sessionA
DestructiveIdempotent

Close the managed browser, or close MCP-owned tabs and detach in attach mode.

Inputs: no named parameters. Returns: object

browser_openOpen browser tabA
Destructive

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 elementsA
Read-only

Return text and safe attributes for elements matching a CSS selector.

Inputs: selector (required), limit, tab_id. Returns: object

browser_snapshotRead page contentA
Read-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 statusA
Read-only

Report browser state and metadata for MCP-accessible tabs.

Inputs: no named parameters. Returns: object

scraper_getRead scraperA
Read-only

Return a saved scraper's source and metadata.

Inputs: name (required). Returns: object

scraper_listList scrapersA
Read-only

List metadata for saved scrapers.

Inputs: no named parameters. Returns: object

scraper_runRun scraperA
Destructive

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 scraperA
Destructive

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

    A4/5.0

    Scored across 9 tools

    Disambiguation4/5

    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.

    Naming Consistency5/5

    All tools follow a consistent verb_noun pattern with clear prefixes (browser_ and scraper_), making the purpose predictable and easy to navigate.

    Tool Count5/5

    Nine tools cover both browser interaction and scraper management without excess or deficiency, well-scoped for a focused MCP server.

    Completeness4/5

    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.

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      Not graded
      quality
      D
      maintenance
      Local 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.
      3
      MIT
    • A
      license
      Not graded
      quality
      C
      maintenance
      A 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 npm
      1
      MIT