Skip to content

Commit c258f79

Browse files
dcramercodex
andauthored
Add OAuth permission scopes system for fine-grained access control (#535)
## Summary Implements an OAuth-style permission scopes system that allows users to choose their access level when authenticating with Sentry. Users can select from three permission levels during the OAuth flow: Read-Only (default), Issue Triage, or Project Management. ## Key Changes - **Permission System**: Added hierarchical scope system in `packages/mcp-server/src/permissions.ts` with scope expansion and validation - **OAuth Flow**: Enhanced approval dialog to present permission options with clear descriptions of what each level allows - **Tool Access Control**: All MCP tools now declare required scopes and are filtered based on granted permissions - **User Experience**: Permission selection UI shows required vs optional permissions with visual distinction - **Documentation**: Added comprehensive guide in `docs/permissions-and-scopes.md` covering usage, scope hierarchy, and tool requirements The system is NOT backward compatible - if no scopes are specified, read-only access is granted. Scopes can also be configured via CLI with `--scopes` flag or `MCP_SCOPES` environment variable. Fixes #525 --- *Generated with Claude Code* --------- Co-authored-by: Codex CLI Agent <noreply@openai.com>
1 parent 1025650 commit c258f79

92 files changed

Lines changed: 2059 additions & 463 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎AGENTS.md‎

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
# CLAUDE.md
2+
3+
## 🔴 CRITICAL Requirements
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)
10+
11+
**MANDATORY reads:**
12+
- Start here: CLAUDE.md — Contributor doc map
13+
- Tools → @docs/adding-tools.mdc
14+
- Prompts → @docs/adding-prompts.mdc
15+
- Resources → @docs/adding-resources.mdc
16+
- Testing → @docs/testing.mdc
17+
- PRs → @docs/pr-management.mdc
18+
19+
## 🟡 MANDATORY Workflow
20+
21+
```bash
22+
# BEFORE coding (parallel execution)
23+
cat docs/[component].mdc & ls -la neighboring-files & git status
24+
25+
# AFTER coding (sequential - fail fast)
26+
pnpm run tsc && pnpm run lint && pnpm run test # ALL must pass
27+
```
28+
29+
## Repository Map
30+
31+
```
32+
sentry-mcp/
33+
├── packages/
34+
│ ├── mcp-server/ # Main MCP server
35+
│ │ ├── src/
36+
│ │ │ ├── tools/ # 19 tool modules
37+
│ │ │ ├── prompts.ts # MCP prompts
38+
│ │ │ ├── resources.ts # MCP resources
39+
│ │ │ ├── server.ts # MCP protocol
40+
│ │ │ ├── api-client/ # Sentry API
41+
│ │ │ └── internal/ # Shared utils
42+
│ │ └── scripts/ # Build scripts
43+
│ ├── mcp-cloudflare/ # Web app
44+
│ ├── mcp-server-evals/ # AI tests
45+
│ ├── mcp-server-mocks/ # MSW mocks
46+
│ └── mcp-test-client/ # Test client
47+
└── docs/ # All docs
48+
```
49+
50+
## AI-Powered Search Tools
51+
52+
**search_events** (`packages/mcp-server/src/tools/search-events/`):
53+
- Natural language → DiscoverQL queries
54+
- GPT-4o agent with structured outputs
55+
- Tools: `datasetAttributes`, `otelSemantics`, `whoami`
56+
- Requires: `OPENAI_API_KEY`
57+
58+
**search_issues** (`packages/mcp-server/src/tools/search-issues/`):
59+
- Natural language → issue search syntax
60+
- GPT-4o agent with structured outputs
61+
- Tools: `issueFields`, `whoami`
62+
- Requires: `OPENAI_API_KEY`
63+
64+
## 🟢 Key Commands
65+
66+
```bash
67+
# Development
68+
pnpm run dev # Start development
69+
pnpm run build # Build all packages
70+
pnpm run generate-otel-namespaces # Update OpenTelemetry docs
71+
72+
# Quality checks (combine for speed)
73+
pnpm run tsc && pnpm run lint && pnpm run test
74+
75+
# Common workflows
76+
pnpm run build && pnpm run test # Before PR
77+
grep -r "TODO\|FIXME" src/ # Find tech debt
78+
```
79+
80+
## Quick Reference
81+
82+
**Defaults:**
83+
- Organization: `sentry`
84+
- Project: `mcp-server`
85+
- Transport: stdio
86+
- Auth: access tokens (NOT OAuth)
87+
88+
**Doc Index:**
89+
90+
- Core Guidelines
91+
- @docs/coding-guidelines.mdc — Code standards and patterns
92+
- @docs/common-patterns.mdc — Reusable patterns and conventions
93+
- @docs/quality-checks.mdc — Required checks before changes
94+
- @docs/error-handling.mdc — Error handling patterns
95+
96+
- API and Tools
97+
- @docs/adding-tools.mdc — Add new MCP tools
98+
- @docs/adding-prompts.mdc — Add prompts
99+
- @docs/adding-resources.mdc — Add resources
100+
- @docs/api-patterns.mdc — Sentry API usage
101+
- @docs/search-events-api-patterns.md — search_events specifics
102+
103+
- Infrastructure and Operations
104+
- @docs/architecture.mdc — System design
105+
- @docs/deployment.mdc — Deploy (Cloudflare)
106+
- @docs/monitoring.mdc — Monitoring/telemetry
107+
- @docs/security.mdc — Security and authentication
108+
- @docs/cursor.mdc — Cursor IDE integration
109+
110+
- LLM-Specific
111+
- @docs/llms/documentation-style-guide.mdc — How to write LLM docs
112+
- @docs/llms/document-scopes.mdc — Doc scopes and purposes
113+
114+
## Rules
115+
116+
1. **Code**: Follow existing patterns. Check adjacent files
117+
2. **Errors**: Try/catch all async. Log: `console.error('[ERROR]', error.message, error.stack)`
118+
- Sentry API 429: Retry with exponential backoff
119+
- Sentry API 401/403: Check token permissions
120+
3. **Docs**: Update when changing functionality
121+
4. **PR**: Follow `docs/pr-management.mdc` for commit/PR guidelines (includes AI attribution)
122+
5. **Tasks**: Use TodoWrite for 3+ steps. Batch tool calls when possible
123+
124+
---
125+
*Optimized for Codex CLI (OpenAI) and Claude Code*

‎CLAUDE.md‎

Lines changed: 0 additions & 109 deletions
This file was deleted.

‎CLAUDE.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
AGENTS.md

‎README.md‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ To contribute changes, you'll need to set up your local environment:
8282
- `COOKIE_SECRET=my-super-secret-cookie`
8383

8484
4. **Start the development server:**
85+
8586
```shell
8687
pnpm dev
8788
```
@@ -135,3 +136,7 @@ The automated reviews should be treated as:
135136
- ❌ **Not replacements** for human code review
136137

137138
When addressing automated feedback, focus on the underlying concerns rather than strictly following every suggestion.
139+
140+
### Contributor Documentation
141+
142+
Looking to contribute or explore the full documentation map? See `CLAUDE.md` (also available as `AGENTS.md`) for contributor workflows and the complete docs index. The `docs/` folder contains the per-topic guides and tool-integrated `.mdc` files.

‎biome.json‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@
44
"enabled": true
55
},
66
"files": {
7-
"ignore": ["worker-configuration.d.ts", "tsconfig*.json"]
7+
"ignore": [
8+
"worker-configuration.d.ts",
9+
"tsconfig*.json",
10+
"packages/mcp-server-mocks/src/fixtures/**"
11+
]
812
},
913
"vcs": {
1014
"enabled": true,
@@ -15,6 +19,9 @@
1519
"enabled": true,
1620
"rules": {
1721
"recommended": true,
22+
"correctness": {
23+
"noUnusedImports": "warn"
24+
},
1825
"suspicious": {
1926
"noExplicitAny": "off",
2027
"noDebugger": "off",

‎docs/README.md‎

Lines changed: 13 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,68 +1,26 @@
1-
# Documentation for Contributors
1+
# Contributor Docs
22

3-
This directory contains documentation to help LLMs (Language Learning Models) and human contributors work more effectively with the Sentry MCP codebase.
3+
This directory contains contributor documentation used by humans and LLMs. To avoid duplication, the canonical documentation map and contributor workflow live in `CLAUDE.md` (also available as `AGENTS.md`).
44

55
## Purpose
66

7-
These documents provide structured guidance to ensure consistent, high-quality contributions that align with the project's standards and patterns. All documentation files use the `.mdc` format for better AI tool compatibility.
7+
- Central home for all contributor-focused docs (.mdc files)
8+
- Consumed by tools (e.g., Cursor) via direct file references
89

9-
## Directory Structure
10+
## Start Here
1011

11-
This directory serves a dual purpose:
12-
1. Central documentation repository for all contributors
13-
2. Source for `.cursor/rules/` via symlink (for Cursor IDE integration)
12+
- Doc map and workflow: see `CLAUDE.md` / `AGENTS.md`
13+
- Per-topic guides live in this folder (e.g., `adding-tools.mdc`)
1414

15-
## Contents
15+
## Integration with Tools
1616

17-
### Core Guidelines
18-
- `coding-guidelines.mdc` - Coding standards, patterns, and best practices
19-
- `coding-practices.mdc` - General coding practices and conventions
20-
- `package-management.mdc` - Package and dependency management
17+
- Cursor IDE: this folder is referenced directly as contextual rules
18+
- Other AI tools: reference specific `.mdc` files as needed
2119

22-
### API and Tools
23-
- `adding-new-tools.mdc` - How to add new MCP tools
24-
- `adding-prompts.mdc` - Guidelines for adding new prompts
25-
- `adding-new-resources.mdc` - How to add new MCP resources
26-
- `api-client-patterns.mdc` - Working with the Sentry API client
27-
- `search-events-api-patterns.md` - Comprehensive guide to search_events API patterns
28-
- `using-api-mocks.mdc` - Testing with API mocks
20+
## LLM-Specific
2921

30-
### Infrastructure and Operations
31-
- `deployment-and-infrastructure.mdc` - Deployment processes and infrastructure
32-
- `observability-and-monitoring.mdc` - Monitoring and telemetry practices
33-
- `security-and-authentication.mdc` - Security best practices
34-
35-
## For LLMs
36-
37-
When working with this codebase:
38-
1. Always read relevant `.mdc` files before making changes
39-
2. Follow the patterns and conventions outlined in these guides
40-
3. Run all quality checks as specified in the guidelines
41-
4. Maintain consistency with existing code
42-
43-
## Integration with Development Tools
44-
45-
### Cursor IDE
46-
The `.cursor/rules/` directory is symlinked to this `docs/` folder, ensuring that Cursor IDE automatically picks up all documentation as contextual rules.
47-
48-
### Other AI Tools
49-
These `.mdc` files are designed to be easily consumed by various AI development assistants and can be referenced directly when needed.
50-
51-
## LLM-Specific Guidelines
52-
53-
The `llms/` subdirectory contains meta-documentation for LLMs:
54-
- `documentation-style-guide.mdc` - How to write effective LLM documentation
55-
- `document-scopes.mdc` - Purpose and content for each doc
56-
- `documentation-todos.mdc` - Tasks for documentation improvement
22+
- Meta-docs live under `llms/` (e.g., `llms/document-scopes.mdc`)
5723

5824
## Maintenance
5925

60-
These documents should be updated when:
61-
- New patterns or conventions are adopted
62-
- Common issues arise that need documentation
63-
- The architecture or tooling changes significantly
64-
- New tools, resources, or features are added
65-
66-
## Note
67-
68-
This documentation supplements but does not replace the root-level CLAUDE.md file, which remains the primary instruction set for Claude Code when working with this repository. The CLAUDE.md file will be refactored into multiple focused documents within this directory.
26+
Update docs when patterns change, new tools are added, or common issues arise. Keep the index in `CLAUDE.md` authoritative; avoid mirroring it here.

‎docs/adding-tools.mdc‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ try {
303303

304304
### Implementation Guidelines
305305

306-
1. **Create a CLAUDE.md file** in the tool directory documenting:
306+
1. **Create an AGENTS.md file** in the tool directory documenting:
307307
- The embedded agent's prompt and behavior
308308
- Common translation patterns
309309
- Known limitations

‎docs/architecture.mdc‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ A separate web chat application that uses the MCP server.
5656

5757
**Note**: This is NOT part of the MCP server itself - it's a demonstration of how to build a chat interface that consumes MCP.
5858

59-
See [Cloudflare Web App Documentation](./cloudflare/overview.md) for details.
59+
See "Overview" in @docs/cloudflare/overview.md for details.
6060

6161
### packages/mcp-server-evals
6262

‎docs/cloudflare/architecture.md‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ SENTRY_CLIENT_SECRET = "..." # OAuth app secret
183183

184184
## Related Documentation
185185

186-
- [Authentication Flow](./authentication.md)
187-
- [Chat Interface Features](./chat-interface.md)
188-
- [Deployment Guide](./deployment.md)
189-
- [Core MCP Server](../architecture.mdc)
186+
- See "OAuth Architecture" in @docs/cloudflare/oauth-architecture.md
187+
- See "Chat Interface" in @docs/cloudflare/architecture.md
188+
- See "Deployment" in @docs/cloudflare/deployment.md
189+
- See "Architecture" in @docs/architecture.mdc

0 commit comments

Comments
 (0)