sentry-investigator

sentry-investigator

Automatically reads Sentry issues, investigates them by analyzing your Ruby codebase, explains why issues happened, and provides fix suggestions.

Category
访问服务器

README

Sentry Investigator MCP (Ruby-Focused)

A Model Context Protocol (MCP) server that automatically reads Sentry issues, investigates them by analyzing your Ruby codebase, explains why issues happened, and provides fix suggestions tailored for Ruby applications.

🚀 Features

  • 🔍 Sentry Integration: Fetch and analyze issues directly from your Sentry projects
  • 💎 Ruby-Focused Analysis: Specialized support for Ruby, Rails, and ERB files
  • 📊 Codebase Analysis: Automatically analyze your Ruby code to understand issue context
  • 🧠 Smart Investigation: Combine Sentry data with Ruby code analysis for comprehensive insights
  • 🔧 Ruby Fix Suggestions: Get specific, actionable fix recommendations for Ruby errors
  • 📈 Impact Analysis: Understand user impact and frequency patterns
  • ⚡ Stack Trace Analysis: Deep dive into Ruby stack traces with code context

📋 Prerequisites

  • Node.js 18 or higher
  • A Sentry account with API access
  • Ruby/Rails project (primary focus)
  • Cursor editor (or any MCP-compatible client)

⚙️ Installation

  1. Clone or download this MCP server:
git clone https://github.com/doraemon0905/sentry-mcp
cd sentry-mcp
  1. Install dependencies:
npm install
  1. Build the project:
npm run build

🔧 Setup

1. Get Sentry API Token

  1. Go to Sentry (https://your_domain.sentry.io) → Settings → Personal Tokens
  2. Create a new token with the following scopes:
    • org:read
    • project:read
    • event:read
    • alerts:read
    • team:read

2. Configure Cursor

Add the MCP server to your Cursor configuration. Edit your MCP settings file:

On macOS/Linux: ~/.cursor/mcp.json
On Windows: %APPDATA%\Cursor\mcp.json

{
  "mcpServers": {
    "sentry-investigator": {
      "command": "node",
      "args": ["/path/to/sentry-mcp/dist/index.js"],
      "env": {
        "SENTRY_AUTH_TOKEN": "your-sentry-auth-token-here",
        "SENTRY_ORGANIZATION": "your-sentry-org-slug",
        "SENTRY_PROJECT": "your-default-project-slug"
      }
    }
  }
}

Required Environment Variables:

  • SENTRY_AUTH_TOKEN: Your Sentry API token
  • SENTRY_ORGANIZATION: Your Sentry organization slug
  • SENTRY_PROJECT: (Optional) Your default project slug

Replace /path/to/sentry-mcp with the actual path to this project.

3. Restart Cursor

Restart Cursor to load the new MCP server.

🎯 Usage

1. List Recent Issues

Use the get_sentry_issues tool to fetch recent issues:
- project: (optional) Specific project slug
- limit: Number of issues (default: 10, max: 100)
- status: unresolved, resolved, or ignored (default: unresolved)

2. Investigate an Issue

Use the investigate_issue tool with:
- issue_id: The Sentry issue ID
- codebase_path: Path to your Ruby codebase (default: current directory)
- include_fix: Whether to include fix suggestions (default: true)

3. Analyze Stack Traces

Use the analyze_stack_trace tool to analyze any Ruby stack trace:
- stack_trace: The stack trace text
- codebase_path: Path to your Ruby codebase (default: current directory)

🔧 Available Tools

Tool Description
get_sentry_issues Fetch recent issues from Sentry
investigate_issue Full investigation of a specific issue (supports short IDs like "ATS-3YJ")
analyze_stack_trace Analyze any stack trace with Ruby code context

📝 Example Investigation Report

When you investigate a Ruby issue, you'll get a comprehensive report including:

# 🐛 Issue Investigation Report

**Issue:** NoMethodError: undefined method `name' for nil:NilClass
**ID:** 12345 (PROJ-1AB)
**Status:** unresolved
**Level:** error
**Occurrences:** 45 (12 users affected)
**First Seen:** 2024-01-15 10:30:00
**Last Seen:** 2024-01-20 15:45:00

## 🔍 Stack Trace Analysis

**Parsed Stack Trace:**
1. `get_user_data`
   📁 app/services/user_service.rb:25

### 📄 `app/services/user_service.rb` (Line 25)

```ruby
  23: def get_user_data(user_id)
  24:   user = User.find_by(id: user_id)
→ 25:   user.name # Error occurs here
  26: end

🔧 Function: get_user_data

💡 Issue Analysis

Error Type: NoMethodError Ruby error caused by trying to call a method on a nil object.

Frequency Analysis: Medium frequency (9 occurrences/day) Impact Level: 🟡 Medium (12 users affected)

🔧 Suggested Fixes

NoMethodError Fix

# Add method existence checks
if user.respond_to?(:name)
  user.name
else
  # Handle missing method case
end

# Or use safe navigation
user&.name

🛠️ Development

Project Structure

src/
├── index.ts              # Main MCP server entry point
├── services/
│   ├── SentryService.ts      # Sentry API integration
│   ├── CodebaseAnalyzer.ts   # Ruby-focused code analysis utilities  
│   └── IssueInvestigator.ts  # Main investigation logic

Ruby Language Support

The MCP is optimized for Ruby applications and includes:

  • File Types: .rb, .erb, .rake files
  • Stack Trace Parsing: Ruby-specific error format recognition
  • Method Detection: Ruby method definitions (def, self., lambdas, procs)
  • Import Analysis: require, require_relative, include, extend, gem statements
  • Error Types: NoMethodError, NameError, ArgumentError, TypeError, etc.
  • Fix Suggestions: Ruby-specific error handling patterns

Scripts

  • npm run build - Build the TypeScript project
  • npm run dev - Build in watch mode for development
  • npm start - Run the built server

Building from Source

npm install
npm run build

🤝 Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests if applicable
  5. Submit a pull request

📄 License

MIT License - see LICENSE file for details.

🆘 Troubleshooting

Common Issues

"Sentry service not configured"

  • Ensure SENTRY_AUTH_TOKEN and SENTRY_ORGANIZATION environment variables are set in your MCP configuration
  • Verify your API token has the correct permissions

"No project specified and no default project configured"

  • Either specify a project in the tool call or set SENTRY_PROJECT environment variable

"Failed to connect to Sentry"

  • Check your API token and organization slug
  • Ensure your network allows HTTPS requests to sentry.io

"File not found in codebase"

  • Verify the codebase_path parameter points to your Ruby project root
  • Some files in stack traces may be from gems or external libraries

Ruby-Specific Notes

  • The analyzer prioritizes Ruby files (.rb, .erb, .rake) over other file types
  • Stack trace parsing is optimized for Ruby error formats
  • Method suggestions focus on Ruby patterns and best practices
  • Excludes common Ruby directories (vendor/, tmp/) from analysis

🔗 Links

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选