设备日志流式查询服务

一个用于从Android和iOS设备流式传输和查询设备日志的服务器。

  • by narodejesus
  • TypeScript
  • 本地部署
  • 1 星标
  • 更新于
在 GitHub 查看 narodejesus/logcat-mcp

使用说明

logcat mcp

MCP服务器,用于流式传输和查询设备日志 安卓 (adb logcat)以及 iOS (模拟器 log stream +物理设备 idevicesyslog).

先决条件

  • Node.js >= 18
  • 安卓: adb 在PATH(安卓SDK平台工具)中
  • iOS模拟器:Xcode xcrun simctl
  • iOS物理设备 (可选): brew install libimobiledevice

设置

npm install
npm run build

MCP客户端配置

克劳德桌面/OpenCode

添加到MCP配置中:

{
  "mcpServers": {
    "logcat": {
      "command": "node",
      "args": ["/absolute/path/to/logcatmcp/build/index.js"]
    }
  }
}

工具

工具 说明
list_devices 列出已连接的Android/iOS设备
start_streaming 开始从设备捕获日志
stop_streaming 停止捕获日志(或全部停止 deviceId: "all")
get_logs 使用过滤器(优先级、标签、平台、设备、分页)查询捕获的日志
search_logs 在日志消息和标签中进行全文搜索
get_log_stats 汇总统计(按优先级、平台、设备计数)
clear_logs 清除内存中的日志缓冲区
clear_device_logs 清除设备日志缓冲区(仅限Android)

资源

URI 描述
logcat://status 活动流和缓冲区统计数据(JSON)
logcat://logs/latest 最近100个日志条目
logcat://logs/errors 最近的错误/致命条目
logcat://logs/{platform} 日志筛选方式 android 或 ios
logcat://device/{deviceId} 来自特定设备的日志

用法示例

1. list_devices                              → see what's connected
2. start_streaming(platform: "android",
                   deviceId: "emulator-5554") → begin capture
3. get_logs(limit: 20, minPriority: "warn")  → view recent warnings+
4. search_logs(query: "crash")               → find crash-related entries
5. stop_streaming(deviceId: "all")           → stop when done

建筑

src/
  types.ts             Shared types, constants, regex patterns
  android-provider.ts  Android adb logcat streaming + parsing
  ios-provider.ts      iOS simulator/physical device log streaming
  log-store.ts         In-memory ring buffer with query/search/stats
  index.ts             MCP server entry point (tools + resources + stdio transport)

许可证

麻省理工学院