npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

console-logger-mcp

v1.0.13

Published

Capture browser console logs and expose them to AI via MCP — bridges Chrome extension console output to any MCP-compatible IDE

Readme

console-logger-mcp

捕获浏览器控制台日志,并通过 MCP(Model Context Protocol)暴露给 AI。

弥合浏览器开发者工具与 AI 编程助手之间的鸿沟:Chrome 扩展捕获 console.log/warn/error/info/debug 及未处理的异常,将其推送到 MCP 服务器,IDE 中的 AI 可以直接查询这些日志 —— 不再需要手动复制粘贴错误信息。

注意:该 MCP 需要配合 console-logger-extension 浏览器插件使用 插件目录:plugin/console-logger-extension

工作原理

Chrome/Edge 扩展 ──HTTP POST /logs──▶ MCP 服务器 ──MCP (stdio/SSE)──▶ IDE 中的 AI
                                        ├─ get_logs      (查询日志)
                                        ├─ get_tabs      (列出标签页)
                                        ├─ clear_logs    (清除日志)
                                        └─ get_log_stats  (统计摘要)

特性

  • 零依赖 — 纯 Node.js 内置 http 模块
  • 双传输模式 — 同时支持 stdioSSE MCP 传输
  • 多标签页感知 — 按浏览器标签页跟踪日志,支持自动清理
  • 替换模式 — 推送新批次时清除旧缓存,防止数据过期
  • 健康检查端点 — 通过 GET /health 轻松监控

前置条件

  • Node.js >= 18.0.0
  • Chrome 浏览器(用于配套扩展)

快速开始

方式 A:npx(推荐 — 无需安装)

npx console-logger-mcp

这将以 stdio 模式 启动服务器(由 IDE 管理进程生命周期),同时在随机端口开放 HTTP 监听供浏览器扩展使用,并通过固定端口 3456 提供 /discover 发现端点。

方式 B:本地克隆

git clone <repo-url>
cd console-logger-mcp
node server.js          # SSE 模式(手动启动)
# 或
node bin/cli.js          # stdio 模式(IDE 管理)

方式 C:Windows 开机自启(静默,无控制台窗口)

双击 install.bat 注册 Windows 计划任务,登录时自动启动服务器。详见开机自启设置

SSE(手动启动 + 持久连接)

注意:现在主服务器使用随机端口,扩展通过 http://127.0.0.1:3456/discover 自动发现真实端口。 如果你使用 SSE 模式,需要将客户端指向实际端口(启动日志中会显示)。

{
  "mcpServers": {
    "console-logger-mcp": {
      "type": "sse",
      "url": "http://127.0.0.1:<实际端口>/sse"
    }
  }
}

MCP

{
  "mcpServers": {
    "console-logger-mcp": {
      "command": "npx",
      "args": ["console-logger-mcp"]
    }
  }
}

如何选择?

  • stdio:IDE 自动启动/停止服务器,配置更简单,无需手动启动。
  • SSE:手动启动服务器(或通过开机自启),服务器在 IDE 重启后仍保持运行。

IDE 配置示例

Qoder IDE

  1. 打开 Settings → MCP
  2. 粘贴上面的 STDIO 或 SSE 配置
  3. 保存 — IDE 会自动连接

Cursor / Continue / 其他 MCP 客户端

使用相同的 STDIO 配置格式。SSE 模式下将客户端指向 http://127.0.0.1:3456/sse

工具

| 工具 | 描述 | 参数 | |------|------|------| | get_logs | 查询捕获的控制台日志 | tabId?, level?, search?, limit?, offset? | | get_tabs | 列出所有有日志的标签页 | — | | clear_logs | 清除指定或所有标签页的日志 | tabId? | | get_log_stats | 获取全局统计信息(按级别计数) | — |

工具使用示例

# AI 提示词:"检查浏览器控制台中的错误"
→ 调用 get_logs(level="error")
→ 返回带堆栈跟踪的格式化错误日志

# AI 提示词:"哪些标签页有控制台输出?"
→ 调用 get_tabs()
→ 返回包含 URL、标题、日志数量的标签页列表

# AI 提示词:"清除所有日志,重新开始"
→ 调用 clear_logs()
→ 返回确认信息

HTTP API

服务器还提供 REST 端点(供浏览器扩展使用):

| 方法 | 路径 | 描述 | |------|------|------| | GET | /health | 健康检查 — 返回状态、日志数量、运行时间 | | GET | /logs | 查询所有缓存日志(可选 ?tabId=xxx) | | POST | /logs | 从扩展推送日志。请求体:{ "logs": [...], "replace": false } | | GET | /discover | 端口发现 — 返回主服务器的真实端口(固定端口 3456) | | POST | /shutdown | 优雅关闭服务器 | | GET | /sse | SSE 连接(仅 SSE 模式) | | POST | /message | JSON-RPC 请求(仅 SSE 模式) |

POST /logs

{
  "logs": [
    {
      "level": "error",
      "args": ["Uncaught TypeError: Cannot read property 'foo' of undefined"],
      "stack": "at example.js:12:5\nat helper.js:3:1",
      "url": "https://example.com/page",
      "tabId": "tab-123",
      "tabTitle": "Example Page",
      "timestamp": 1719800000000,
      "seq": 1
    }
  ],
  "replace": false
}
  • replace: true — 写入本批次前清除所有缓存日志(用于手动"发送到 MCP"按钮)
  • replace: false(默认) — 追加到现有缓存

配置

服务器配置在 config.js 中:

| 配置项 | 默认值 | 描述 | |--------|--------|------| | host | 127.0.0.1 | 监听地址 | | port | 3456 | 发现服务器端口(主服务器使用随机端口) | | maxLogsPerTab | 5000 | 每个浏览器标签页的最大日志数 | | maxLogsTotal | 50000 | 全局日志上限 | | maxTabAgeMs | 1800000(30 分钟) | 不活跃标签页的自动清理时间 |

开机自启设置(Windows)

SSE 模式下,可以设置服务器在 Windows 登录时自动启动:

  1. 双击 install.bat — 创建计划任务
  2. 每次登录时服务器静默启动(无控制台窗口)
  3. 如果崩溃,60 秒内自动重启

管理脚本:

| 脚本 | 操作 | |------|------| | install.bat | 安装开机自启任务 | | uninstall.bat | 移除开机自启任务 + 停止服务器 | | status.bat | 查看运行状态 | | start.bat | 手动启动(带控制台窗口,用于调试) | | start-silent.vbs | 静默启动器(计划任务使用) |

配套扩展

本 MCP 服务器配合 Console Log Capture Chrome 扩展(Manifest V3)使用。

扩展功能:

  • 钩取 console.log/warn/error/info/debug
  • 捕获未处理的异常
  • 按标签页开关捕获功能
  • 按级别/关键词过滤
  • 下载日志为文件
  • 推送日志到 MCP 服务器(手动或自动)
  • 预览缓存日志

安装扩展:

  1. 打开 chrome://extensions/
  2. 启用 开发者模式
  3. 点击 加载已解压的扩展程序 → 选择 console-logger-extension 目录
  4. 固定扩展以便快速访问

日志格式

每条捕获的日志条目:

{
  "level": "error",
  "args": ["Error message", { "detail": "object" }],
  "stack": "Error\n    at func (file.js:10:5)",
  "url": "https://example.com/page",
  "tabId": "chrome-tab-123",
  "tabTitle": "Page Title",
  "tabUrl": "https://example.com/page",
  "timestamp": 1719800000000,
  "seq": 42
}

常见问题

| 问题 | 解决方案 | |------|----------| | IDE 显示"未连接" | 验证服务器是否运行:curl http://127.0.0.1:3456/discover 查看是否返回端口信息 | | 扩展无法推送日志 | 检查扩展选项 → MCP 设置 → 服务器 URL 是否为 http://127.0.0.1:3456(发现服务器) | | 端口 3456 已被占用 | 发现服务器无法启动,但主服务器仍可正常工作(使用随机端口)。停掉占用 3456 端口的旧进程即可恢复自动发现 | | stdio 模式无输出 | stdio 使用 stdin/stdout 进行 JSON-RPC 通信;查看 stderr 获取日志:npx console-logger-mcp 2>debug.log | | 找不到 npx | 从 nodejs.org 安装 Node.js 18+ |

许可证

MIT