此MCP服务器通过Playwright提供了Firefox浏览器的自动化功能,允许您在MCP启用的应用程序中控制Firefox。该服务器支持基本自动化和高级多标签调试功能。
npm install
npx playwright install firefox
将此服务器添加到您的MCP配置文件中(通常为~/.config/mcp/cline.json或类似文件):
{
"mcpServers": {
"firefox-control": {
"command": "node",
"args": ["index.js"],
"cwd": "/home/luke/workbench/drabardi/firefox-mcp-server"
}
}
}
为了实现完整的调试功能,请使用增强型服务器:
{
"mcpServers": {
"firefox-control": {
"type": "stdio",
"command": "node",
"args": ["/path/to/firefox-mcp-server/index-multi-debug.js"],
"env": {"DISPLAY": ":1"}
}
}
}
注意:更新配置后,请重启Claude Code以激活新的调试工具。
启动支持多标签和调试的Firefox浏览器
headless (布尔值):运行在无头模式下(默认:false)enableDebugLogging (布尔值):启用调试日志记录(默认:true)创建一个新的具有独立会话和调试功能的标签
tabId (字符串,必需):标签的唯一标识符url (字符串):初始导航的URL(默认:"about:blank")enableMonitoring (布尔值):启用实时监控(默认:true)contextId (字符串):用于隔离的浏览器上下文ID列出所有活动标签及其URL和状态
关闭特定标签
tabId (字符串,必需):要关闭的标签ID设置后续操作的活动标签
tabId (字符串,必需):要设为活动的标签ID导航到一个URL
url (字符串,必需):要导航到的URLtabId (字符串):特定的标签(如果未指定,则使用活动标签)点击一个元素
selector (字符串):要点击的CSS选择器coordinates (对象):替代方案——点击特定的x,y坐标tabId (字符串):目标标签ID在输入字段中键入文本
selector (字符串,必需):输入字段的CSS选择器text (字符串,必需):要键入的文本tabId (字符串):目标标签ID发送键盘事件
key (字符串,必需):要发送的键modifiers (数组):修饰键(ctrl, shift, alt, meta)repeat (数字):重复次数(默认:1)selector (字符串):目标元素选择器tabId (字符串):目标标签ID执行拖动操作
selector (字符串):要拖动的元素fromCoordinates (对象):起始坐标 {x, y}toCoordinates (对象):结束坐标 {x, y}offsetX (数字):拖动的X偏移量offsetY (数字):拖动的Y偏移量duration (数字):拖动持续时间(毫秒,默认:0)steps (数字):中间步骤的数量(默认:1)tabId (字符串):目标标签ID获取页面的HTML内容
selector (字符串):可选的CSS选择器,用于特定元素tabId (字符串):目标标签ID获取页面的可见文本内容
selector (字符串):可选的CSS选择器,用于特定元素tabId (字符串):目标标签ID截取屏幕
path (字符串):保存截图的文件路径(默认:"screenshot.png")fullPage (布尔值):捕获整个页面(默认:false)tabId (字符串):目标标签ID等待元素出现
selector (字符串,必需):要等待的CSS选择器timeout (数字):超时时间(毫秒,默认:30000)tabId (字符串):目标标签ID在浏览器中执行JavaScript
script (字符串,必需):要执行的JavaScript代码tabId (字符串):目标标签ID获取当前页面的URL
tabId (字符串):目标标签ID在浏览器历史中后退
tabId (字符串):目标标签ID在浏览器历史中前进
tabId (字符串):目标标签ID重新加载当前页面
tabId (字符串):目标标签ID关闭Firefox浏览器及所有标签
获取从浏览器捕获的控制台日志
tabId (字符串):目标标签IDlimit (数字):返回的日志最大数量(默认:50)since (数字):过滤日志的时间戳types (数组):按日志类型过滤 ["log", "error", "warn", "info", "debug"]获取捕获的JavaScript错误
tabId (字符串):目标标签IDlimit (数字):返回的错误最大数量(默认:20)since (数字):过滤错误的时间戳获取捕获的网络请求和响应
tabId (字符串):目标标签IDlimit (数字):返回的请求最大数量(默认:30)since (数字):过滤请求的时间戳filter (字符串):按请求类型过滤 ["all", "xhr", "websocket", "fetch"](默认:"all")获取捕获的WebSocket消息(适用于LiveView调试)
tabId (字符串):目标标签IDlimit (数字):返回的消息最大数量(默认:50)since (数字):过滤消息的时间戳获取性能指标(计时、内存使用情况)
tabId (字符串):目标标签ID获取所有调试事件的综合流
tabId (字符串):目标标签IDlimit (数字):返回的事件最大数量(默认:100)since (数字):过滤事件的时间戳向页面注入调试辅助函数
tabId (字符串):目标标签IDincludeWebSocketMonitoring (布尔值):包含WebSocket监控(默认:true)开始/重新开始对标签的监控
tabId (字符串):目标标签IDtypes (数组):要监控的类型 ["console", "errors", "network", "websocket", "performance"](默认:全部)清除标签的调试事件缓冲区
tabId (字符串):目标标签IDtypes (数组):要清除的缓冲区类型 ["console", "errors", "network", "websocket"]// 启动浏览器并启用调试
mcp__firefox-control__launch_firefox_multi({headless: false, enableDebugLogging: true})
// 创建标签并导航
mcp__firefox-control__create_tab({tabId: "main", url: "https://example.com", enableMonitoring: true})
// 与页面交互
mcp__firefox-control__click({selector: "button#submit", tabId: "main"})
mcp__firefox-control__type_text({selector: "input[name='search']", text: "hello world", tabId: "main"})
// 截取屏幕
mcp__firefox-control__screenshot({path: "page.png", fullPage: true, tabId: "main"})
// 关闭
mcp__firefox-control__close_browser()
// 启动浏览器并创建多个玩家标签
mcp__firefox-control__launch_firefox_multi({headless: false, enableDebugLogging: true})
mcp__firefox-control__create_tab({tabId: "player1", url: "http://localhost:4000/squid-ball", enableMonitoring: true})
mcp__firefox-control__create_tab({tabId: "player2", url: "http://localhost:4000/squid-ball", enableMonitoring: true})
// 玩家1创建游戏
mcp__firefox-control__set_active_tab({tabId: "player1"})
mcp__firefox-control__click({selector: 'button[phx-click="create_game"]', tabId: "player1"})
// 玩家2加入游戏(假设游戏ID可用)
mcp__firefox-control__set_active_tab({tabId: "player2"})
mcp__firefox-control__type_text({selector: 'input[name="game_id"]', text: "GameID123", tabId: "player2"})
mcp__firefox-control__click({selector: 'button[type="submit"]', tabId: "player2"})
// 分别监控两个玩家
mcp__firefox-control__get_all_debug_activity({tabId: "player1", limit: 10})
mcp__firefox-control__get_all_debug_activity({tabId: "player2", limit: 10})
// 监控LiveView的WebSocket流量
mcp__firefox-control__get_websocket_messages({tabId: "player1", limit: 5})
// 过滤获取控制台日志
mcp__firefox-control__get_console_logs({tabId: "player1", types: ["error", "warn"], limit: 10})
// 监控网络活动
mcp__firefox-control__get_network_activity({tabId: "player1", filter: "xhr", limit: 20})
// 获取性能指标
mcp__firefox-control__get_performance_metrics({tabId: "player1"})
// 综合调试流以进行全面监控
mcp__firefox-control__get_all_debug_activity({tabId: "player1", limit: 50})
// 捕获实时游戏节拍和状态变化
mcp__firefox-control__get_websocket_messages({tabId: "player1", limit: 3})
// 返回:球的位置、挡板移动、节拍数、玩家状态
// 监控LiveView更新的控制台
mcp__firefox-control__get_console_logs({tabId: "player1", types: ["log"], limit: 5})
// 返回:Phoenix LiveView更新日志中的游戏状态变化
// 清除缓冲区并重新开始监控
mcp__firefox-control__clear_debug_buffers({tabId: "player1", types: ["console", "websocket"]})
mcp__firefox-control__start_monitoring({tabId: "player1", types: ["console", "websocket"]})
index-multi-debug.js)此服务器提供了广泛的浏览器自动化和调试访问能力。请谨慎使用,并确保信任将控制Firefox的MCP客户端。该服务器可以: