mcp-chromium-cdp

mcp-chromium-cdp

MCP server for controlling Chromium/Chrome via Chrome DevTools Protocol. Supports cross-platform automation, auto-launch, and automatic reconnection.

Category
访问服务器

README

mcp-chromium-cdp

Model Context Protocol (MCP) server for controlling Chromium/Chrome via Chrome DevTools Protocol. Cross-platform with automatic reconnection support.

✨ Key Features

  • Cross-platform: Works on macOS, Linux, and Windows
  • Chromium-first: Detects and launches Chromium, falls back to Chrome
  • Auto-reconnection: Automatically reconnects if browser crashes or restarts (up to 5 retries)
  • Auto-launch: Launches browser automatically if not running
  • Custom profiles: Support for custom browser profiles via environment variables
  • Stdio transport: Native integration with Claude Desktop and Claude Code

Installation

Global Installation

npm install -g mcp-chromium-cdp

Local Installation

npm install mcp-chromium-cdp

From Source

git clone https://github.com/duquesnay/mcp-chromium-cdp.git
cd mcp-chromium-cdp
npm install
npm run build

Configuration

Claude Desktop (macOS)

Add to ~/Library/Application Support/Claude/claude_desktop_config.json:

{
  "mcpServers": {
    "chromium": {
      "command": "npx",
      "args": ["-y", "mcp-chromium-cdp"]
    }
  }
}

Claude Code

claude mcp add chromium -- npx -y mcp-chromium-cdp

Or with local build:

claude mcp add chromium -- node /path/to/mcp-chromium-cdp/build/index.js

Environment Variables

CHROMIUM_PATH

Override Chromium binary path:

CHROMIUM_PATH=/usr/bin/chromium-browser mcp-chromium-cdp

CHROMIUM_USER_DATA_DIR

Use custom browser profile:

CHROMIUM_USER_DATA_DIR=~/.config/chromium-mcp mcp-chromium-cdp

Available Tools

Tool Description
chrome_navigate Navigate to a specific URL
chrome_get_current_url Get the current page URL
chrome_get_title Get the page title
chrome_get_content Get the page HTML content
chrome_get_visible_text Get visible text from the page
chrome_execute_script Execute JavaScript in the page
chrome_click Click an element by CSS selector
chrome_type Type text into an input field
chrome_screenshot Take a screenshot (base64)
chrome_open_new_tab Open a new tab
chrome_close_tab Close the current tab
chrome_list_tabs List all open tabs
chrome_reload Reload the current page
chrome_go_back Navigate back in history
chrome_go_forward Navigate forward in history

Usage Examples

With Claude

Using chromium tools, navigate to https://example.com and get the page title

Programmatic Usage

import { Client } from '@modelcontextprotocol/sdk/client/index.js';
import { StdioClientTransport } from '@modelcontextprotocol/sdk/client/stdio.js';

const transport = new StdioClientTransport({
  command: 'npx',
  args: ['-y', 'mcp-chromium-cdp']
});

const client = new Client({
  name: 'my-client',
  version: '1.0.0'
}, {
  capabilities: {}
});

await client.connect(transport);

// Navigate to URL
await client.callTool({
  name: 'chrome_navigate',
  arguments: { url: 'https://example.com' }
});

// Get page title
const result = await client.callTool({
  name: 'chrome_get_title',
  arguments: {}
});

console.log(result.content[0].text);

Auto-Reconnection

If Chromium crashes or is restarted, the server will automatically attempt to reconnect:

  • Max retries: 5 attempts
  • Retry delay: 2 seconds between attempts
  • Logs: Reconnection attempts logged to stderr

Example log output:

[Connection] Chromium disconnected
[Reconnect] Attempting to reconnect to Chromium...
[Reconnect] Successfully reconnected to Chromium

Chromium Detection

The server automatically detects Chromium in standard locations:

macOS:

  • /Applications/Chromium.app/Contents/MacOS/Chromium
  • ~/Applications/Chromium.app/Contents/MacOS/Chromium

Linux:

  • /usr/bin/chromium
  • /usr/bin/chromium-browser
  • /snap/bin/chromium

Windows:

  • %LOCALAPPDATA%\Chromium\Application\chrome.exe
  • %PROGRAMFILES%\Chromium\Application\chrome.exe
  • %PROGRAMFILES(X86)%\Chromium\Application\chrome.exe

If Chromium is not found, the server falls back to Chrome via chrome-launcher.

Development

# Install dependencies
npm install

# Build
npm run build

# Watch mode
npm run watch

Architecture

This project consists of two main components:

  1. ChromeController (src/chrome-controller.ts):

    • Manages Chrome DevTools Protocol (CDP) connections
    • Implements browser automation methods
    • Handles auto-launch and reconnection logic
    • Cross-platform Chromium detection
  2. MCP Server (src/index.ts):

    • Implements the Model Context Protocol server
    • Exposes Chrome control methods as MCP tools
    • Handles communication via stdio

Troubleshooting

Chromium/Chrome Not Found

If the server can't find Chromium:

  1. Install Chromium from chromium.org
  2. Or specify path manually:
    CHROMIUM_PATH=/path/to/chromium mcp-chromium-cdp
    

Connection Issues

If the server can't connect:

  1. Check if another process is using port 9222:

    lsof -i :9222
    
  2. The server will auto-launch Chromium if not running

  3. Check logs for reconnection attempts

MCP Server Not Showing in Claude

  1. Verify configuration in Claude Desktop/Code
  2. Check that build/index.js exists
  3. Look at Claude logs for errors

Differences from chrome-mcp

This project is based on the original chrome-mcp package by @moe03 with the following enhancements:

  • Chromium-first detection (instead of Chrome-only)
  • Automatic reconnection on disconnection
  • Cross-platform Chromium path detection
  • Environment variable configuration
  • TypeScript source code included
  • Improved error handling and logging

Credits

Original code by @moe03 (chrome-mcp package).

Enhanced with auto-reconnection and cross-platform support by @duquesnay.

Built using:

License

MIT

Contributing

Contributions welcome! Please open an issue or PR on GitHub.

Support

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选