|
1 | | -# CLAUDE.md |
| 1 | +# AGENTS.md |
2 | 2 |
|
3 | | -## 🔴 CRITICAL Requirements |
| 3 | +Sentry MCP is a Model Context Protocol server that exposes Sentry's error tracking and performance monitoring to AI assistants through 19 tools. |
4 | 4 |
|
5 | | -**MANDATORY before ANY code:** |
6 | | -1. TypeScript: NEVER use `any`. Use `unknown` or proper types |
7 | | -2. Security: NO API keys in logs. NO vulnerabilities |
8 | | -3. Validation: `pnpm run tsc && pnpm run lint && pnpm run test` |
9 | | -4. Tools limit: ≤20 (hard limit: 25) |
| 5 | +## Principles |
10 | 6 |
|
11 | | -**MANDATORY reads:** |
12 | | -- Start here: CLAUDE.md — Contributor doc map |
13 | | -- Tools → @docs/adding-tools.mdc |
14 | | -- Testing → @docs/testing.mdc |
15 | | -- PRs → @docs/pr-management.mdc |
| 7 | +- **Type Safety**: Prefer strict types over `any` - they catch bugs and improve tooling. Use `unknown` for truly unknown types. |
| 8 | +- **Security**: Never log secrets. Validate external input. See @docs/security.md. |
| 9 | +- **Simplicity**: Follow existing patterns. Check neighboring files before inventing new approaches. |
16 | 10 |
|
17 | | -## 🟡 MANDATORY Workflow |
| 11 | +## Constraints |
18 | 12 |
|
19 | | -```bash |
20 | | -# BEFORE coding (parallel execution) |
21 | | -cat docs/[component].mdc & ls -la neighboring-files & git status |
22 | | - |
23 | | -# AFTER coding (sequential - fail fast) |
24 | | -pnpm run tsc && pnpm run lint && pnpm run test # ALL must pass |
25 | | -``` |
| 13 | +- **Tool count**: Target ≤20, hard limit 25 (AI agents have limited tool slots). |
| 14 | +- **Quality gate**: `pnpm run tsc && pnpm run lint && pnpm run test` must pass before committing. |
26 | 15 |
|
27 | | -## Repository Map |
| 16 | +## Repository Structure |
28 | 17 |
|
29 | 18 | ``` |
30 | 19 | sentry-mcp/ |
31 | 20 | ├── packages/ |
32 | | -│ ├── mcp-core/ # Core MCP implementation (private package) |
33 | | -│ │ ├── src/ |
34 | | -│ │ │ ├── tools/ # 19 tool modules |
35 | | -│ │ │ ├── server.ts # buildServer() function |
36 | | -│ │ │ ├── api-client/ # Sentry API |
37 | | -│ │ │ └── internal/ # Shared utils |
38 | | -│ │ └── scripts/ # Build scripts |
39 | | -│ ├── mcp-server/ # stdio transport (published as @sentry/mcp-server) |
| 21 | +│ ├── mcp-core/ # Core MCP implementation (private) |
40 | 22 | │ │ └── src/ |
41 | | -│ │ ├── cli/ # CLI argument parsing |
42 | | -│ │ ├── transports/ # stdio transport |
43 | | -│ │ └── index.ts # Main entry point |
44 | | -│ ├── mcp-cloudflare/ # Web app |
45 | | -│ ├── mcp-server-evals/ # AI tests |
| 23 | +│ │ ├── tools/ # 19 tool modules |
| 24 | +│ │ ├── server.ts # buildServer() |
| 25 | +│ │ ├── api-client/ # Sentry API |
| 26 | +│ │ └── internal/ # Shared utils |
| 27 | +│ ├── mcp-server/ # stdio transport (@sentry/mcp-server on npm) |
| 28 | +│ ├── mcp-cloudflare/ # Web app + OAuth |
| 29 | +│ ├── mcp-server-evals/ # AI evaluation tests |
46 | 30 | │ ├── mcp-server-mocks/ # MSW mocks |
47 | | -│ └── mcp-test-client/ # Test client |
48 | | -└── docs/ # All docs |
| 31 | +│ └── mcp-test-client/ # CLI test client |
| 32 | +└── docs/ # All documentation |
49 | 33 | ``` |
50 | 34 |
|
51 | | -## AI-Powered Search Tools |
| 35 | +## Essential Documentation |
52 | 36 |
|
53 | | -**search_events** (`packages/mcp-core/src/tools/search-events/`): |
54 | | -- Natural language → DiscoverQL queries |
55 | | -- GPT-4o agent with structured outputs |
56 | | -- Tools: `datasetAttributes`, `otelSemantics`, `whoami` |
57 | | -- Requires: `OPENAI_API_KEY` |
| 37 | +**Read before making changes:** |
| 38 | +- @docs/adding-tools.md — Tool implementation guide |
| 39 | +- @docs/testing.md — Testing requirements |
| 40 | +- @docs/common-patterns.md — Error handling, Zod schemas, response formatting |
| 41 | +- @docs/error-handling.md — Error types and propagation |
58 | 42 |
|
59 | | -**search_issues** (`packages/mcp-core/src/tools/search-issues/`): |
60 | | -- Natural language → issue search syntax |
61 | | -- GPT-4o agent with structured outputs |
62 | | -- Tools: `issueFields`, `whoami` |
63 | | -- Requires: `OPENAI_API_KEY` |
| 43 | +**Reference:** |
| 44 | +- @docs/architecture.md — System design |
| 45 | +- @docs/api-patterns.md — Sentry API client usage |
| 46 | +- @docs/quality-checks.md — Pre-commit checklist |
| 47 | +- @docs/pr-management.md — Commit/PR guidelines |
| 48 | +- @docs/security.md — Authentication patterns |
| 49 | +- @docs/releases/stdio.md — npm package release |
| 50 | +- @docs/releases/cloudflare.md — Cloudflare deployment |
64 | 51 |
|
65 | | -## 🟢 Key Commands |
| 52 | +## Commands |
66 | 53 |
|
67 | 54 | ```bash |
68 | 55 | # Development |
69 | | -pnpm run dev # Start development |
70 | | -pnpm run build # Build all packages |
71 | | -pnpm run generate-otel-namespaces # Update OpenTelemetry docs |
| 56 | +pnpm run dev # Start dev server |
| 57 | +pnpm run build # Build all packages |
72 | 58 |
|
73 | | -# Manual Testing (preferred for testing MCP changes) |
74 | | -pnpm -w run cli "who am I?" # Test with local dev server (default) |
75 | | -pnpm -w run cli --agent "who am I?" # Test agent mode (use_sentry tool) - approximately 2x slower |
76 | | -pnpm -w run cli --mcp-host=https://mcp.sentry.dev "query" # Test against production |
77 | | -pnpm -w run cli --access-token=TOKEN "query" # Test with local stdio mode |
| 59 | +# Testing |
| 60 | +pnpm -w run cli "who am I?" # Test local dev server |
| 61 | +pnpm -w run cli --access-token=TOKEN "q" # Test stdio transport |
| 62 | +pnpm -w run cli --agent "query" # Test agent mode (~2x slower) |
78 | 63 |
|
79 | | -# Quality checks (combine for speed) |
| 64 | +# Quality (run before committing) |
80 | 65 | pnpm run tsc && pnpm run lint && pnpm run test |
81 | 66 |
|
82 | | -# Token cost monitoring |
83 | | -pnpm run measure-tokens # Check tool definition overhead |
84 | | - |
85 | | -# Common workflows |
86 | | -pnpm run build && pnpm run test # Before PR |
87 | | -grep -r "TODO\|FIXME" src/ # Find tech debt |
| 67 | +# Token overhead |
| 68 | +pnpm run measure-tokens # Check tool definition size |
88 | 69 | ``` |
89 | 70 |
|
90 | | -## Quick Reference |
91 | | - |
92 | | -**Defaults:** |
93 | | -- Organization: `sentry` |
94 | | -- Project: `mcp-server` |
95 | | -- Transport: stdio |
96 | | -- Auth: access tokens (NOT OAuth) |
97 | | - |
98 | | -**Doc Index:** |
99 | | - |
100 | | -- Core Guidelines |
101 | | - - @docs/coding-guidelines.mdc — Code standards and patterns |
102 | | - - @docs/common-patterns.mdc — Reusable patterns and conventions |
103 | | - - @docs/quality-checks.mdc — Required checks before changes |
104 | | - - @docs/error-handling.mdc — Error handling patterns |
105 | | - |
106 | | -- API and Tools |
107 | | - - @docs/adding-tools.mdc — Add new MCP tools |
108 | | - - @docs/api-patterns.mdc — Sentry API usage |
109 | | - - @docs/search-events-api-patterns.md — search_events specifics |
110 | | - |
111 | | -- Infrastructure and Operations |
112 | | - - @docs/architecture.mdc — System design |
113 | | - - @docs/releases/cloudflare.mdc — Cloudflare Workers release |
114 | | - - @docs/releases/stdio.mdc — npm package release |
115 | | - - @docs/monitoring.mdc — Monitoring/telemetry |
116 | | - - @docs/security.mdc — Security and authentication |
117 | | - - @docs/token-cost-tracking.mdc — Track MCP tool definition overhead |
118 | | - - @docs/cursor.mdc — Cursor IDE integration |
119 | | - |
120 | | -- Testing |
121 | | - - @docs/testing.mdc — Testing strategies and patterns |
122 | | - - @docs/testing-stdio.md — Stdio testing playbook (build, run, test) |
123 | | - - @docs/testing-remote.md — Remote testing playbook (OAuth, web UI, CLI) |
124 | | - |
125 | | -- LLM-Specific |
126 | | - - @docs/llms/documentation-style-guide.mdc — How to write LLM docs |
127 | | - - @docs/llms/document-scopes.mdc — Doc scopes and purposes |
128 | | - |
129 | | -## Rules |
130 | | - |
131 | | -1. **Code**: Follow existing patterns. Check adjacent files |
132 | | -2. **Errors**: Try/catch all async. Log: `console.error('[ERROR]', error.message, error.stack)` |
133 | | - - Sentry API 429: Retry with exponential backoff |
134 | | - - Sentry API 401/403: Check token permissions |
135 | | -3. **Docs**: Update when changing functionality |
136 | | -4. **PR**: Follow `docs/pr-management.mdc` for commit/PR guidelines (includes AI attribution) |
137 | | -5. **Tasks**: Use TodoWrite for 3+ steps. Batch tool calls when possible |
138 | | - |
139 | | ---- |
140 | | -*Optimized for Codex CLI (OpenAI) and Claude Code* |
| 71 | +## Workflow |
| 72 | + |
| 73 | +1. Check neighboring files for existing patterns before writing new code. |
| 74 | +2. Update relevant docs when changing functionality. |
| 75 | +3. Follow @docs/error-handling.md for error types. |
| 76 | +4. Follow @docs/pr-management.md for commits and PRs. |
0 commit comments