错误监控服务

一个基于Node.js和TypeScript实现的MCP Sentry服务器,用于通过Sentry API集成进行错误跟踪和监控,支持标准MCP协议和SSE传输。

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

使用说明

MCP哨兵服务器(Node.js)

这是模型上下文协议(MCP)哨兵服务器的Node.js+TypeScript实现。它与Sentry集成,通过MCP检索错误报告和堆栈跟踪。

中文文档

特性

  • 与Sentry API集成,用于错误跟踪和监控
  • 支持标准MCP over stdin/stdout和SSE(服务器发送事件)传输
  • SSE服务器的可配置端口(默认值:3579)

先决条件

  • Node.js>=20.0.0
  • pnpm>=10.5.2

安装

克隆存储库并安装依赖项:

pnpm install

配置

创建一个 .env 使用Sentry身份验证令牌在根目录中创建文件:

SENTRY_TOKEN=your_sentry_auth_token_here

您可以从Sentry帐户设置中获取Sentry身份验证令牌。

用法

构建项目

pnpm build

运行服务器

pnpm start

或者,您可以将Sentry身份验证令牌和API基指定为命令行参数:

pnpm start --auth-token your_sentry_auth_token_here --api-base your_sentry_api_base_here

在SSE支持下运行

pnpm start:sse

这将在端口3579(默认)上启动支持SSE的Express服务器。您可以在以下位置访问SSE端点:

http://localhost:3579/sse

您还可以使用 .env.local 文件。

发展模式

pnpm dev

MCP配置

{
  "mcpServers": {
    "sentry-server": {
      "command": "npx",
      "args": ["-y","@weekit/mcp-sentry@1.0.9"],
      "env": {
        "SENTRY_TOKEN": "your_sentry_auth_token_here",
        "SENTRY_API_BASE": "https://your_sentry_api_base_here"
      }
    }
  }
}

使用本地构建:

{
  "mcpServers": {
    "my-sentry": {
      "command": "node",
      "args": ["path/to/dist/index.js"],
      "env": {
        "SENTRY_TOKEN": "your_sentry_auth_token_here",
        "SENTRY_API_BASE": "https://your_sentry_api_base_here"
      }
    }
  }
}

通信协议

MCP Sentry服务器支持两种通信协议:

  1. 标准MCP协议:通过标准输入/输出流进行通信
  2. SSE 运输:服务器通过HTTP发送基于web的通信事件(端口3579)

MCP功能

MCP Sentry服务器通过MCP协议提供以下功能:

鼓励

  • sentry-issue:通过ID或URL检索哨兵问题
  • most-triggered-issue:从Sentry问题列表URL中查找影响最多用户的问题

工具

  • get_sentry_issue:通过ID或URL检索和分析哨兵问题
  • get_sentry_issues_list:从URL检索并分析哨兵问题列表

API

服务器通过标准输入/输出流使用模型上下文协议进行通信,并提供以下功能:

  1. 列出可用的提示和工具
  2. 检索哨兵问题信息,包括:
    • 发行标题和ID
    • 状态和严重程度
    • 首次和最后一次看到的时间戳
    • 事件计数
    • 详细的堆栈跟踪

MCP工作流程

以下是MCP Sentry服务器的工作流程图:

flowchart TD
    A[Client/LLM] -->|1. Send MCP Request| B[MCP Sentry Server]
    B -->|2. Parse Request Type| C{Determine Request Type}

    C -->|Prompt Request| D[Handle Prompt\nsentry-issue]
    C -->|Tool Request| E[Handle Tool\nget_sentry_issue]

    D -->|3. Extract Issue ID| F[Call Sentry API]
    E -->|3. Extract Issue ID| F

    F -->|4. Get Issue Data| G[Sentry API]
    G -->|5. Return Issue Data| F
    F -->|6. Get Event Data| G
    G -->|7. Return Event Data| F

    F -->|8. Parse Data| H[Create SentryIssueData Object]
    H -->|9. Format Data| I{Response Type}

    I -->|Prompt Response| J[Convert to PromptResult Format]
    I -->|Tool Response| K[Convert to ToolResult Format]

    J -->|10. Return Response| B
    K -->|10. Return Response| B

    B -->|11. Send MCP Response| A

测试

运行所有测试:

pnpm test

运行单元测试:

pnpm test test/unit.test.ts

运行集成测试:

pnpm test test/integration.test.ts

查看测试覆盖率:

pnpm test -- --coverage