# CLAUDE.md
## π΄ CRITICAL Requirements
**MANDATORY before ANY code:**
1. TypeScript: NEVER use `any`. Use `unknown` or proper types
2. Security: NO API keys in logs. NO vulnerabilities
3. Validation: `pnpm run tsc && pnpm run lint && pnpm run test`
4. Tools limit: β€20 (hard limit: 25)
**MANDATORY reads:**
- Start here: CLAUDE.md β Contributor doc map
- Tools β @docs/adding-tools.mdc
- Testing β @docs/testing.mdc
- PRs β @docs/pr-management.mdc
## π‘ MANDATORY Workflow
```bash
# BEFORE coding (parallel execution)
cat docs/[component].mdc & ls -la neighboring-files & git status
# AFTER coding (sequential - fail fast)
pnpm run tsc && pnpm run lint && pnpm run test # ALL must pass
```
## Repository Map
```
sentry-mcp/
βββ packages/
β βββ mcp-server/ # Main MCP server
β β βββ src/
β β β βββ tools/ # 19 tool modules
β β β βββ server.ts # MCP protocol
β β β βββ api-client/ # Sentry API
β β β βββ internal/ # Shared utils
β β βββ scripts/ # Build scripts
β βββ mcp-cloudflare/ # Web app
β βββ mcp-server-evals/ # AI tests
β βββ mcp-server-mocks/ # MSW mocks
β βββ mcp-test-client/ # Test client
βββ docs/ # All docs
```
## AI-Powered Search Tools
**search_events** (`packages/mcp-server/src/tools/search-events/`):
- Natural language β DiscoverQL queries
- GPT-4o agent with structured outputs
- Tools: `datasetAttributes`, `otelSemantics`, `whoami`
- Requires: `OPENAI_API_KEY`
**search_issues** (`packages/mcp-server/src/tools/search-issues/`):
- Natural language β issue search syntax
- GPT-4o agent with structured outputs
- Tools: `issueFields`, `whoami`
- Requires: `OPENAI_API_KEY`
## π’ Key Commands
```bash
# Development
pnpm run dev # Start development
pnpm run build # Build all packages
pnpm run generate-otel-namespaces # Update OpenTelemetry docs
# Manual Testing (preferred for testing MCP changes)
pnpm -w run cli "who am I?" # Test with local dev server (default)
pnpm -w run cli --agent "who am I?" # Test agent mode (use_sentry tool) - approximately 2x slower
pnpm -w run cli --mcp-host=https://mcp.sentry.dev "query" # Test against production
pnpm -w run cli --access-token=TOKEN "query" # Test with local stdio mode
# Quality checks (combine for speed)
pnpm run tsc && pnpm run lint && pnpm run test
# Token cost monitoring
pnpm run measure-tokens # Check tool definition overhead
# Common workflows
pnpm run build && pnpm run test # Before PR
grep -r "TODO\|FIXME" src/ # Find tech debt
```
## Quick Reference
**Defaults:**
- Organization: `sentry`
- Project: `mcp-server`
- Transport: stdio
- Auth: access tokens (NOT OAuth)
**Doc Index:**
- Core Guidelines
- @docs/coding-guidelines.mdc β Code standards and patterns
- @docs/common-patterns.mdc β Reusable patterns and conventions
- @docs/quality-checks.mdc β Required checks before changes
- @docs/error-handling.mdc β Error handling patterns
- API and Tools
- @docs/adding-tools.mdc β Add new MCP tools
- @docs/api-patterns.mdc β Sentry API usage
- @docs/search-events-api-patterns.md β search_events specifics
- Infrastructure and Operations
- @docs/architecture.mdc β System design
- @docs/releases/cloudflare.mdc β Cloudflare Workers release
- @docs/releases/stdio.mdc β npm package release
- @docs/monitoring.mdc β Monitoring/telemetry
- @docs/security.mdc β Security and authentication
- @docs/token-cost-tracking.mdc β Track MCP tool definition overhead
- @docs/cursor.mdc β Cursor IDE integration
- Testing
- @docs/testing.mdc β Testing strategies and patterns
- @docs/testing-stdio.md β Stdio testing playbook (build, run, test)
- @docs/testing-remote.md β Remote testing playbook (OAuth, web UI, CLI)
- LLM-Specific
- @docs/llms/documentation-style-guide.mdc β How to write LLM docs
- @docs/llms/document-scopes.mdc β Doc scopes and purposes
## Rules
1. **Code**: Follow existing patterns. Check adjacent files
2. **Errors**: Try/catch all async. Log: `console.error('[ERROR]', error.message, error.stack)`
- Sentry API 429: Retry with exponential backoff
- Sentry API 401/403: Check token permissions
3. **Docs**: Update when changing functionality
4. **PR**: Follow `docs/pr-management.mdc` for commit/PR guidelines (includes AI attribution)
5. **Tasks**: Use TodoWrite for 3+ steps. Batch tool calls when possible
---
*Optimized for Codex CLI (OpenAI) and Claude Code*