An MCP server for AI-assisted frontend development using Chrome DevTools. Requires Google Chrome.
{{ message }}
XRealSys / chrome-devtool-mcp Public
AI frontend develop utils
MIT license
0 stars0 forksBranches Tags Activity
Star
Notifications
develop
BranchesTags
Go to file
Code
Name | Name | Last commit message | Last commit date |
---|---|---|---|
7 Commits | |||
.claude | .claude | ||
src | src | ||
tests | tests | ||
.gitignore | .gitignore | ||
AI_DEBUGGING_GUIDE.md | AI_DEBUGGING_GUIDE.md | ||
LICENSE | LICENSE | ||
PROJECT_STRUCTURE.md | PROJECT_STRUCTURE.md | ||
README.md | README.md | ||
package.json | package.json | ||
pyproject.toml | pyproject.toml | ||
requirements.txt | requirements.txt | ||
run_tests.sh | run_tests.sh | ||
start.sh | start.sh | ||
test_domains_via_tools.py | test_domains_via_tools.py | ||
test_partial_domains.py | test_partial_domains.py | ||
test_partial_simple.py | test_partial_simple.py | ||
test_simulate_partial.py | test_simulate_partial.py | ||
verify_partial_domains.py | verify_partial_domains.py | ||
View all files |
一个基于 Model Context Protocol (MCP) 的 Chrome DevTools 控制服务器,为 AI 辅助前端开发提供强大的浏览器调试能力。
本项目提供了一套完整的 Chrome 浏览器控制工具,让 AI 能够:
git clone https://github.com/yourusername/chrome-devtool-mcp.git cd chrome-devtool-mcp
python -m venv venv source venv/bin/activate # macOS/Linux
venv\Scripts\activate # Windows
pip install -r requirements.txt
使用以下命令启动服务器:
python src/chrome_devtools_mcp.py
或使用启动脚本:
./start.sh
服务器将在 http://localhost:12524
启动。
如果需要使用其他端口,修改脚本中的端口号或设置环境变量:
MCP_PORT=8080 python src/chrome_devtools_mcp.py
macOS/Linux:
mkdir -p ~/.config/claude/mcp nano ~/.config/claude/mcp/chrome-devtools.json
Windows:
mkdir -p $env:APPDATA\claude\mcp notepad $env:APPDATA\claude\mcp\chrome-devtools.json
{ "mcpServers": { "chrome-devtools": { "command": "python", "args": ["/path/to/chrome-devtool-mcp/mcp_server.py"], "env": {} } } }
如果你已经有其他 MCP 服务器在运行,可以通过以下方式添加 Chrome DevTools 服务器:
{ "mcpServers": { "existing-server": { // ... 现有配置 }, "chrome-devtools": { "command": "python", "args": ["/path/to/chrome-devtool-mcp/mcp_server.py"], "env": {} } } }
export CLAUDE_MCP_CHROME_DEVTOOLS="python /path/to/chrome-devtool-mcp/mcp_server.py" claude-code
在 Claude Code 中,你可以通过以下方式验证工具是否成功接入:
请列出所有可用的 MCP 工具
你应该能看到以下工具:
Cmd+,
或 Ctrl+,
)如果需要自定义端口或主机:
连接成功后,你可以在 Cursor 中:
@
符号查看可用的 MCP 工具你应该能看到以下工具:
如果无法连接:
http://localhost:12524/docs
查看 API 文档使用 launch_chrome 工具启动一个 Chrome 浏览器实例
使用 navigate_to 工具访问 http://localhost:3000
使用 get_dom_tree 工具获取页面的 DOM 结构
使用 query_elements 工具查找所有 class 为 "button" 的元素
使用 get_network_logs 工具查看所有 API 请求
使用 execute_javascript 工具在页面上执行 console.log('Hello from AI!')
1. 启动 Chrome 并导航到 React 应用
2. 使用 execute_javascript 执行:
window.__REACT_DEVTOOLS_GLOBAL_HOOK__.renderers.values().next().value.findFiberByHostInstance(document.querySelector('#root'))._debugOwner.stateNode.state
3. 分析返回的状态数据
1. 清空网络日志
2. 触发应用中的某个操作
3. 使用 get_network_logs 筛选特定 API 端点
4. 分析请求和响应数据
1. 使用 execute_javascript 执行 performance.mark('start')
2. 执行一系列操作
3. 使用 execute_javascript 执行 performance.mark('end') 和 performance.measure('operation', 'start', 'end')
4. 获取性能数据
1. 使用 connect_remote_chrome 连接到已运行的应用
2. 使用 query_elements 找到登录按钮选择器(如 '#login-btn')
3. 使用 set_breakpoint('dom', '#login-btn') 在登录按钮上设置断点
4. 点击登录按钮,调试器会暂停
5. 使用 get_console_logs 查看控制台输出
6. 使用 get_paused_info 查看暂停位置和调用栈
7. 使用 resume_execution 继续执行
1. 启动 Electron 应用时添加 --remote-debugging-port=9222 参数
2. 使用 connect_remote_chrome('localhost', 9222) 连接
3. 使用各种调试工具进行分析
4. 设置断点并调试特定功能
1. 使用 list_available_targets() 列出所有可用的标签页
2. 选择目标标签页的 webSocketDebuggerUrl
3. 使用 connect_websocket_url(ws_url) 切换到该标签页
4. 现在所有操作都会在新的标签页上执行
示例代码:
# 列出所有标签页
targets = list_available_targets()
# 选择第二个标签页
ws_url = targets['data']['targets'][1]['webSocketDebuggerUrl']
# 切换到该标签页
connect_websocket_url(ws_url)
启动 Chrome 浏览器实例,支持 headless 模式。
参数:
headless
(bool): 是否无头模式运行,默认 falseport
(int): 远程调试端口,默认 9222连接到远程 Chrome/Chromium 实例(如 Electron 应用)。
参数:
host
(str): 远程主机地址,默认 localhostport
(int): 远程调试端口,默认 9222直接使用 WebSocket URL 连接到特定的调试会话。
参数:
ws_url
(str): WebSocket 调试器 URL,如 'ws://localhost:9222/devtools/page/ABC123'使用场景:
列出所有可用的 Chrome 标签页/页面及其 WebSocket URL。
参数:
host
(str): Chrome 主机地址,默认 localhostport
(int): Chrome 调试端口,默认 9222导航到指定 URL。
参数:
url
(str): 目标 URL获取当前页面的 DOM 树结构。
参数:
depth
(int): DOM 树的最大深度,默认 3使用 CSS 选择器查询 DOM 元素。
参数:
selector
(str): CSS 选择器获取网络请求日志。
参数:
filter_url
(str, optional): URL 过滤模式获取控制台日志。
参数:
level
(str, optional): 日志级别过滤(error, warning, log, info)在页面上下文中执行 JavaScript 代码。
参数:
code
(str): 要执行的 JavaScript 代码截取当前页面的屏幕截图。
参数:
full_page
(bool): 是否截取整个页面,默认 false获取当前页面的基本信息。
无参数。
关闭 Chrome 浏览器实例。
无参数。
设置 JavaScript 断点。支持传统断点和日志断点(logpoint)。
参数:
breakpoint_type
(str): 断点类型 - 'dom', 'event', 'function', 'xhr', 'line', 'logpoint'target
(str): 断点目标(如 DOM 选择器、函数名、URL:行号)options
(dict, optional): 额外选项
condition
: 条件表达式,只在条件为真时触发logMessage
: 日志消息(用于日志断点)pause
: 是否暂停执行(默认:logpoint 为 False,其他为 True)示例:
set_breakpoint('dom', '#login-button')
set_breakpoint('function', 'handleLogin')
set_breakpoint('line', 'app.js:42')
set_breakpoint('xhr', '/api/login')
set_breakpoint('function', 'processData', {'logMessage': 'Processing data...', 'pause': False})
set_breakpoint('function', 'validate', {'condition': 'value < 0', 'logMessage': 'Invalid value', 'pause': False})
列出所有活动断点。
无参数。
移除指定断点。
参数:
breakpoint_id
(str): 断点 ID获取调试器暂停时的信息。
无参数。
从断点恢复执行。
无参数。
单步跳过当前行。
无参数。
获取当前页面加载的所有 JavaScript 源代码列表。
无参数。
返回:
获取特定脚本的源代码。
参数:
script_id
(str): 脚本 ID(从 get_script_sources 获取)在所有加载的脚本中搜索函数、类或文本。
参数:
pattern
(str): 搜索模式(如函数名、类名、文本)search_type
(str): 搜索类型 - 'function'、'class'、'variable'、'text'获取页面中定义的所有函数。
无参数。
欢迎提交 Issue 和 Pull Request!
本项目采用 MIT 许可证 开源。
MIT License - 详细信息请查看 LICENSE 文件。
该许可证允许您:
只要您:
Readme
MIT license
Activity
0 stars
0 watching
0 forks
Report repository
No releases published
No packages published
Generate images using Bytedance's SeedDream 3.0 model via the Replicate platform.
MCP Server for PGYER platform, supports uploading, querying apps, etc.
Work on dataset metadata with MLCommons Croissant validation and creation.
An MCP server and client implementation for the Swagger Petstore API.
Search dashboards, investigate incidents and query datasources in your Grafana instance
A comprehensive MCP server for managing OPNsense firewalls, offering over 300 tools for configuration and monitoring.
Connects to the React Native application debugger to retrieve console logs from Metro.
Provides multi-cluster Kubernetes management and operations using MCP, featuring a management interface, logging, and nearly 50 built-in tools covering common DevOps and development scenarios. Supports both standard and CRD resources.
Gru-sandbox(gbox) is an open source project that provides a self-hostable sandbox for MCP integration or other AI agent usecases.
Integrates Ollama's local LLM models with MCP-compatible applications. Requires a local Ollama installation.