灯塔 MCP 服务器
一个模型背景协议(MCP)服务器,利用Google灯塔提供全面的网络性能审计和分析能力. 该服务器使LLMs和AI代理能够进行详细的网站性能评估,访问审核,SEO分析,安全检查和Core Web Virtuals监测.
关键特性
- 绩效分析: 完成灯塔审计,包括核心网络生命、业绩分数和优化建议
- QQ 无障碍审计: WCAG 合规检查和无障碍分数分析
- SEO分析:搜索引擎优化审计和最佳做法建议
- 安全评估:HTTPS、CSP和安全脆弱性扫描
- 资源分析: JavaScript, CSS, 图像和字体优化机会
- 移动对桌面: 使用节流选项对设备进行比较分析
- 核心网络维度: LCP、INP、CLS监测并进行阈值检查
- 绩效预算: 自定义性能阈值和预算监测
- 代理浏览:灯塔13,一个页面如何为AI代理服务的审计(WebMCP工具,代理访问树,llms.txt)
- * 结构化产出: 每个工具声明一个
outputSchema并验证返回structuredContent,因此客户端可以得到输入的数据,而不是 JSON 字符串来解析 - 参考资源:为网络性能、无障碍性、标准环境和安全制定准则和最佳做法
所需经费
- 节点.js 22.0.0或更新
- Chrome/铬浏览器(由灯塔自动管理)
- VS 代码、 光标、 Windsurf、 Claude 桌面或任何其他 MCP 客户端
开始
使用下列配置之一,与您首选的客户端安装灯塔 MCP 服务器:
{
"mcpServers": {
"lighthouse": {
"command": "npx",
"args": ["@danielsogl/lighthouse-mcp@latest"]
}
}
}
持久性色谱配置文件( Login会话)
需要验证的会话时,以持续Chrome剖面进行发射并运行标题:
{
"mcpServers": {
"lighthouse": {
"command": "npx",
"args": [
"@danielsogl/lighthouse-mcp@latest",
"--profile-path",
"<profile-path>",
"--no-headless"
]
}
}
}
您可以通过额外的克罗姆旗 --chrome-flag,例如 --chrome-flag=--disable-gpu。 。 。 .
如果旗帜值开始于 -- 并匹配已知选项名, 首选 --chrome-flag=... 以避免将其解析为顶级选项.
Profile模式禁用灯塔的存储重置,因此饼干和本地存储在运行之间持续存在.
若为 --user-data-dir 指向缺失目录,它将被创建并作为新配置处理.
设定 --profile-path 路径 chrome://version (例如:. .../Default) (中文(简体) ).
注意:Chrome远程调试需要非默认用户数据目录,因此重用专用配置目录而不是系统默认.
也可以通过 --user-data-dir + 键 --profile-directory 如果你愿意的话 分开来.
附随 --chrome-port 单靠它不会保存存储; 包含一个保存会话的配置标记 .
CLI 选项
支持 MCP 服务器运行时旗 :
--profile-path <path>: 使用来自chrome://version(自动识别用户数据 dir + profile name)--user-data-dir <path>: 为持久性会话重新使用 Chrome 配置目录--profile-directory <name>: 在用户数据目录中选择配置--chrome-path <path>: 通往Chrome/Chrome可执行文件的明确路径(覆盖自动检测;也尊重CHROME_PATH环境变量)--chrome-flag <flag>或者说--chrome-flag=<flag>:通过外克罗梅旗(可重复)--chrome-port <port>或者说--remote-debugging-port <port>: 附加到已启用远程调试的 Chrome 实例--headless: 强制无头模式--no-headless: 向导模式
日志
灯塔木来作斯德. 服务器保持这个 error 所以它不会淹没你的MCP
客户端日志; 设置 LIGHTHOUSE_LOG_LEVEL 改为 silent, (中文(简体) ), info 或者说 verbose 调试时
(例如Chrome未能发射).
LIGHTHOUSE_LOG_LEVEL=verbose npx @danielsogl/lighthouse-mcp@latest
WSL2 / 自定义色调路径
如果错误的Chrome 二进制被取出(例如Windows Chrome代替了WSL2上的Linux 二进制),则明确设置路径:
# Via CLI flag
npx @danielsogl/lighthouse-mcp@latest --chrome-path /usr/bin/google-chrome
# Via environment variable
CHROME_PATH=/usr/bin/google-chrome npx @danielsogl/lighthouse-mcp@latest
在您的 MCP 配置中 :
{
"mcpServers": {
"lighthouse": {
"command": "npx",
"args": ["@danielsogl/lighthouse-mcp@latest", "--chrome-path", "/usr/bin/google-chrome"]
}
}
}
E2E 烟雾试验(文件)
使用持续配置文件进行真正的审计( 必要时使用现有配置文件目录并登录一次):
npm run smoke:profile -- --url https://example.com \
--profile-path "<profile-path>" \
--no-headless
E2E 烟雾试验(从现有染色体开始)
启用远程调试启动 Chrome :
/path/to/GoogleChromeExecutable \
--remote-debugging-port=9222 \
--user-data-dir /path/to/chrome-profile
替换 /path/to/GoogleChromeExecutable 与您的平台的 Chrome / Chromium 二进制路径 .
然后把灯塔放在这个例子上:
npm run smoke:profile -- --url https://example.com --chrome-port 9222
为了保存附加时的存储, 通过配置路径, 灯塔保持 cookie/ 本地存储 :
npm run smoke:profile -- --url https://example.com \
--chrome-port 9222 \
--profile-path "<profile-path>"
在 VS 代码中安装
手动 VS 代码安装
您也可以使用 VS 代码 CLI 安装灯塔 MCP 服务器 :
# For VS Code
code --add-mcp '{"name":"lighthouse","command":"npx","args":["-y","@danielsogl/lighthouse-mcp@latest"]}'
# For VS Code Insiders
code-insiders --add-mcp '{"name":"lighthouse","command":"npx","args":["-y","@danielsogl/lighthouse-mcp@latest"]}'
在安装后,灯塔MCP服务器将可用于您在VS代码中的GitHub Copilot代理.
在光标中安装
手动光标安装
转到 Cursor Settings → MCP → Add new MCP Server名称为“灯塔”,使用 command 带有命令的类型 npx @danielsogl/lighthouse-mcp@latest数字 :
{
"mcpServers": {
"lighthouse": {
"command": "npx",
"args": ["@danielsogl/lighthouse-mcp@latest"]
}
}
}
在 Windsurf 安装
人工 Windsurf 安装
跟着风起云起的MCP 文档。使用以下配置:
{
"mcpServers": {
"lighthouse": {
"command": "npx",
"args": ["@danielsogl/lighthouse-mcp@latest"]
}
}
}
在 Claude 桌面中安装
克劳德桌面安装
跟随 MCP 安装 指南,使用以下配置:
{
"mcpServers": {
"lighthouse": {
"command": "npx",
"args": ["@danielsogl/lighthouse-mcp@latest"]
}
}
}
可用的工具
灯塔MCP服务器提供了下列网络综合分析工具:
审计工具
| 工具 | 说明 | 参数 |
|---|---|---|
run_audit | 全面审计灯塔 | url, (中文(简体) ), categories?, (中文(简体) ), device?, (中文(简体) ), throttling? |
get_accessibility_score | 获得无障碍分数和建议 | url, (中文(简体) ), device?, (中文(简体) ), includeDetails? |
get_seo_analysis | 获得高级管理办公室的分析和建议 | url, (中文(简体) ), device?, (中文(简体) ), includeDetails? |
性能工具
| 工具 | 说明 | 参数 |
|---|---|---|
get_performance_score | 获得总体业绩分数 | url, (中文(简体) ), device? |
get_core_web_vitals | 获取核心网络维度度度度测量 | url, (中文(简体) ), device?, (中文(简体) ), includeDetails?, (中文(简体) ), threshold? |
compare_mobile_desktop | 设备之间的性能比较 | url, (中文(简体) ), categories?, (中文(简体) ), throttling?, (中文(简体) ), includeDetails? |
check_performance_budget | 对照执行情况预算进行核对 | url, (中文(简体) ), device?, (中文(简体) ), budget |
get_lcp_opportunities | 找到 LCP 优化机会 | url, (中文(简体) ), device?, (中文(简体) ), includeDetails?, (中文(简体) ), threshold? |
分析工具
| 工具 | 说明 | 参数 |
|---|---|---|
find_unused_javascript | 查找未使用的 JavaScript 代码 | url, (中文(简体) ), device?, (中文(简体) ), minBytes?, (中文(简体) ), includeSourceMaps? |
analyze_resources | 分析所有网站资源 | url, (中文(简体) ), device?, (中文(简体) ), resourceTypes?, (中文(简体) ), minSize? |
QQ 安全工具
| 工具 | 说明 | 参数 |
|---|---|---|
get_security_audit | 进行全面的安全审计 | url, (中文(简体) ), device?, (中文(简体) ), checks? |
可用的提示
灯塔MCP服务器包含可重复使用的提示,帮助LLMS提供结构化的分析和建议:
分析提示
| 提示 | 说明 | 参数 |
|---|---|---|
analyze-audit-results | 灯塔审计结果分析 | auditResults, (中文(简体) ), focusArea? |
compare-audits | 审计结果前后的比较 | beforeAudit, (中文(简体) ), afterAudit, (中文(简体) ), changesImplemented? |
optimize-core-web-vitals | 获取核心网络维度优化建议 | coreWebVitals, (中文(简体) ), framework?, (中文(简体) ), constraints? |
optimize-resources | 获取资源优化建议 | resourceAnalysis, (中文(简体) ), loadingStrategy?, (中文(简体) ), criticalUserJourneys? |
* 可用资源
灯塔MCP服务器为内置参考资源提供了基本准则和最佳做法:
| 资源 | 说明 | URI 资源 |
|---|---|---|
core-web-vitals-thresholds | 核心网络生命力性能阈值 | lighthouse://performance/core-web-vitals-thresholds |
optimization-techniques | 业绩优化技术和影响 | lighthouse://performance/optimization-techniques |
wcag-guidelines | WCAG 2.1 无障碍准则和问题 | lighthouse://accessibility/wcag-guidelines |
seo-best-practices | SEO最佳做法和优化机会 | lighthouse://seo/best-practices |
security-best-practices | 网络安全最佳做法和脆弱性 | lighthouse://security/best-practices |
budget-guidelines | 按地点类型分列的执行情况报告建议 | lighthouse://performance/budget-guidelines |
categories-scoring | 灯塔审计类别和评分方法 | lighthouse://audits/categories-scoring |
framework-guides | 特定框架优化指南 | lighthouse://frameworks/optimization-guides |
战略提示
| 提示 | 说明 | 参数 |
|---|---|---|
create-performance-plan | 制定全面的绩效改进计划 | currentMetrics, (中文(简体) ), targetGoals?, (中文(简体) ), timeframe? |
create-performance-budget | 创建自定义的绩效预算建议 | currentMetrics, (中文(简体) ), businessGoals?, (中文(简体) ), userBase? |
seo-recommendations | 提出改善机会均等的建议 | seoAudit, (中文(简体) ), websiteType?, (中文(简体) ), targetAudience? |
accessibility-guide | 创建无障碍改进指南 | accessibilityAudit, (中文(简体) ), complianceLevel?, (中文(简体) ), userGroups? |
快速参数细节
auditResults: JSON 来自灯塔工具的审计结果focusArea: 重点(b)的具体类别"performance", (中文(简体) ),"accessibility", (中文(简体) ),"seo", (中文(简体) ),"best-practices", (中文(简体) ),"agentic-browsing"(中文(简体) )beforeAudit编号 :afterAudit: 灯塔在变更前后的审计结果changesImplemented: 说明在审计之间所作的变动currentMetrics: 审计的现有业绩计量targetGoals:具体业绩指标或业务目标timeframe: 实施改进的时间表framework: 前端框架或技术堆栈constraints技术或商业制约因素websiteType:网站类型(如:电子商务,博客,公司)targetAudience目标受众或市场信息complianceLevel: 遵守《公约》的情况"AA"或者说"AAA"(中文(简体) )userGroups: 考虑无障碍的具体用户群体
参数细节
共同参数
url(必须): 用于分析的网站 URLdevice: 目标设备("desktop"或者说"mobile",默认值 :"desktop"(中文(简体) )includeDetails: 包含详细的审计信息(默认:false(中文(简体) )throttling: 启用网络/CPU节奏( 默认 ):false(中文(简体) )
具体参数
categories- 灯塔类别供审计["performance", "accessibility", "best-practices", "seo", "agentic-browsing"](中文(简体) )threshold: 度量衡的自定义阈值(例如,{"lcp": 2.5, "inp": 200, "cls": 0.1}(中文(简体) )budget: 执行预算限制(例如,{"performanceScore": 90, "largestContentfulPaint": 2500}(中文(简体) )resourceTypes: 分析的资源类型(["images", "javascript", "css", "fonts", "other"](中文(简体) )minBytes: 用于分析的最小文件大小阈值( 默认 :2048(中文(简体) )checks: 进行安全检查(["https", "csp", "hsts", "origin-isolation", "clickjacking", "trusted-types", "third-party-cookies", "deprecations"](中文(简体) )
使用实例
基本业绩审计
// Get overall performance score
{
"tool": "get_performance_score",
"arguments": {
"url": "https://example.com",
"device": "mobile"
}
}
核心网络活性分析
// Check Core Web Vitals with custom thresholds
{
"tool": "get_core_web_vitals",
"arguments": {
"url": "https://example.com",
"device": "mobile",
"includeDetails": true,
"threshold": {
"lcp": 2.5,
"inp": 200,
"cls": 0.1
}
}
}
安全评估
// Comprehensive security audit
{
"tool": "get_security_audit",
"arguments": {
"url": "https://example.com",
"checks": ["https", "csp", "hsts"]
}
}
资源优化
// Find optimization opportunities
{
"tool": "analyze_resources",
"arguments": {
"url": "https://example.com",
"resourceTypes": ["images", "javascript"],
"minSize": 1024
}
}
使用参考资源
获取内在准则和最佳做法:
// Get Core Web Vitals thresholds
{
"resource": {
"uri": "lighthouse://performance/core-web-vitals-thresholds"
}
}
// Access WCAG accessibility guidelines
{
"resource": {
"uri": "lighthouse://accessibility/wcag-guidelines"
}
}
// Get framework-specific optimization guides
{
"resource": {
"uri": "lighthouse://frameworks/optimization-guides"
}
}
使用分析提示
// Analyze audit results with focused recommendations
{
"prompt": "analyze-audit-results",
"arguments": {
"auditResults": "{...lighthouse audit json...}",
"focusArea": "performance"
}
}
// Create a performance improvement plan
{
"prompt": "create-performance-plan",
"arguments": {
"currentMetrics": "{...current performance metrics...}",
"targetGoals": "Achieve 90+ performance score and sub-2s LCP",
"timeframe": "3 months"
}
}
// Compare before/after audit results
{
"prompt": "compare-audits",
"arguments": {
"beforeAudit": "{...before audit results...}",
"afterAudit": "{...after audit results...}",
"changesImplemented": "Implemented lazy loading and image optimization"
}
}
使用大小写
- 业绩监测: 自动性能跟踪和核心网络生命监测
- 无障碍遵守: WCAG 2.1 合规检查和补救指导
- SEO 优化: 技术审计和搜索引擎优化建议
- 安全评估:脆弱性扫描和安全最佳做法验证
- 资源优化: 组合分析和优化机会识别
- 预算:自动执行情况预算监测和警报
- CI/CD 一体化: 自动质量门和性能回归检测
建筑
服务器使用 :
- 示范背景协议SDK:用于 MCP 服务器执行
- 谷歌灯塔:用于网络绩效审计
- Chrome 发射器: 用于浏览器自动化
- 类型脚本: 类型安全及更好的开发者经验
- 佐德语Name:用于运行时间计划验证
测试
npm run test:run # unit tests
npm run test:coverage # unit tests with coverage
npm run test:e2e # end-to-end tests
端到端套件会建起服务器,用真实的MCP客户端在stdio上发射
运行实际的灯塔审计 相对于一个固定的页面 循环。 这需要克罗梅
待安装; 设置 CHROME_PATH 如果它住的地方不标准.
捐款
欢迎捐款! 请读我们的 贡献指南 详细情况如下:
- 代码样式和标准
- 测试要求
- 请求程序
- 开发设置
许可证
这个项目根据麻省理工学院许可证颁发——见 自由主义 详细文件.
• 警卫
关于安全问题,请参见我们 安全政策。 。 。 .
++ 辅助
- 🐛 错误报告数字 : GitHub 问题
- 💬 讨论情况数字 : GitHub 讨论
- 📧 电子邮件数字 : 安全@ 编码规则.ai
承认
- Google灯塔团队的优秀审计引擎
- 示范上下文协议规格
- 持续激励和贡献的开源社区
由 QQ 创建 丹尼尔·索格