Repository navigation
feat(mcp): Build the scope rules from Sentry's x-sentry-project-scope - #2552
Open
sentry-junior[bot] wants to merge 7 commits into
Open
sentry-junior[bot] wants to merge 7 commits into
sentry-junior[bot] wants to merge 7 commits into
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
BYK
added a commit
to getsentry/sentry
that referenced
this pull request
Nov 27, 2026
…132723) `@sentry/api/operations` now carries Sentry's `x-sentry-project-scope` OpenAPI extension, added in #132722, as `ApiOperation.projectScope`. Clients that limit a caller to some projects can read it instead of keeping their own endpoint table. getsentry/toolkit#2552 consumes it for the Sentry CLI and MCP project scope. ```ts export type ApiProjectScope = "path" | "filter" | "org-metadata" | `response:${string}`; // on ApiOperation readonly projectScope?: ApiProjectScope; ``` The values: - `path`: the path names the project. - `filter`: an organization endpoint that takes the `project` query parameter (numeric project IDs) and returns or changes only those projects' data. - `org-metadata`: a read-only organization endpoint whose response holds no project's telemetry. `GET` only. - `response:<pointer>`: a `GET` that looks something up by ID alone. The numeric ID of its project is at `<pointer>` in the response body. `<pointer>` is an RFC 6901 JSON pointer (`~0`/`~1` escapes) in which a `*` segment matches every array element, such as `response:/projects/*/id`. The field is left out when an operation has no extension, which means the operation is not known to respect a project limit. `ApiProjectScope` is exported from `@sentry/api/operations` next to `ApiOperation`. Like the `x-sentry-routing` check, the build throws on a non-string value, on an unknown value, on a malformed pointer, and on `org-metadata` or `response:` on a method other than `GET`. These are the same rules that #132722's schema build enforces. The released catalog has no `projectScope` values until #132722 merges and the schema is rebuilt. Refs getsentry/toolkit#2237 <!-- junior-request-attribution:start --> via @BYK. <!-- junior-request-attribution:end --> <!-- junior-session-footer:start --> <!-- junior-conversation-id:agent%3Aee8e94869cd8853bb9ac177d49cf5de5 --> -- [View Session](https://junior-prod.sentry.dev/conversations/agent%3Aee8e94869cd8853bb9ac177d49cf5de5) [[Sentry]](https://sentry.sentry.io/explore/conversations/agent%3Aee8e94869cd8853bb9ac177d49cf5de5/?project=4510944073809921) <!-- junior-session-footer:end --> Co-authored-by: sentry-junior[bot] <264270552+sentry-junior[bot]@users.noreply.github.com> Co-authored-by: BYK <126780+BYK@users.noreply.github.com>
sentry-junior
Bot
force-pushed
the
feat/scope-rules-from-catalog
branch
from
November 27, 2026 11:56
84b0a46 to
7dd2a00
Compare
sentry-junior
Bot
force-pushed
the
feat/scope-rules-from-catalog
branch
from
November 27, 2026 12:08
7dd2a00 to
3dc3e75
Compare
The scope rules of `limitToTarget` were a hand-written endpoint table. Sentry now declares them with the `x-sentry-project-scope` OpenAPI extension, which `@sentry/api` carries as `ApiOperation.projectScope`. `script/generate-api-schema.ts` extracts them at build time into `src/generated/project-scope-operations.json`, as it does the idempotent writes, and `target-scope-rules.ts` builds its rules from them: - `org-metadata`: an organization read the project scope may send. - `filter`: an organization endpoint filtered to the scope's project. - `response:<pointer>`: a lookup by an ID alone, checked by the project IDs at the pointer of its response; requests under its path look it up first. Hand rules remain only where the schema can't say it: project paths, account reads, getsentry's `customers/`, endpoints the schema doesn't publish (short IDs, event IDs, share links, traces), `trace-meta` and `trace-logs` (they ignore `project`), and release writes (a release spans projects). This needs a `@sentry/api` release with `projectScope`. Until then the generated list is empty and a project scope refuses the endpoints it would cover. The scope tests run on a fixture of the declarations, and `target-scope-catalog.test.ts` checks the fixture against the catalog once it has them. Refs #2237 Co-Authored-By: BYK <126780+BYK@users.noreply.github.com>
The installed `@sentry/api` (1.74) has no `projectScope`, so the generated catalog list is empty and a project scope refused every endpoint the catalog covers, `chunk-upload/` included. A scoped `sourcemap upload` was refused before its token check. Until the `@sentry/api` 3.x bump, the rules come from `interim-project-scope-operations.json`, a copy of what getsentry/sentry#132722 declares. It was the tests' fixture, so the tests now run on the same rules the CLI enforces. Once the catalog has any declarations it wins, and a guard test checks that every interim entry is in it. The copy and `projectScopeDeclarations` are marked for deletion with the bump. Refs #2237 Co-Authored-By: BYK <126780+BYK@users.noreply.github.com>
On `main`, `@sentry/api`'s operation catalog gives paths relative to `/api/0`, and the CLI prefixes `API_BASE_PATH` itself. The scope rules and the interim declarations match full request paths, so the extracted `projectScope` operations get the same prefix. Refs #2237 Co-Authored-By: BYK <126780+BYK@users.noreply.github.com>
sentry-junior
Bot
force-pushed
the
feat/scope-rules-from-catalog
branch
from
November 27, 2026 12:14
3dc3e75 to
5709ba8
Compare
The interim declarations as a list of objects put the @sentry/mcp-server bundle 906 bytes over its 3.75 MB budget. Keying them by method, then by path relative to /api/0, cuts 1.5 KB; the generated catalog file uses the same shape.
… missing target-scope-rules.ts imports it, but ensure-generated and the schema step's outputs listed only the other two schema files, so a checkout missing just this one skipped generation and failed on the import.
BYK
approved these changes
Nov 27, 2026
BYK
marked this pull request as ready for review
November 27, 2026 23:27
BYK
enabled stacked auto-merge
November 27, 2026 23:28
3.5.0 carries Sentry's x-sentry-project-scope declarations (getsentry/sentry#132722) as each operation's projectScope.
@sentry/api 3.5.0 carries Sentry's x-sentry-project-scope declarations on each operation, and the CLI already bundles that catalog. Build the rules from it directly, and delete the interim copy of the declarations and the generated project-scope-operations.json. Sentry now derives `filter` for stats_v2, sessions and AI conversation details from their `project` parameter, so a project scope filters them instead of refusing them.
Contributor
📊 MCP Server Token Cost ReportSummary
Per-Tool Breakdown
Note: This measures the static overhead of tool definitions sent to LLM clients with every request. Lower is better. MCP Apps viewsEach
The budget applies to raw bytes, and the view's generator fails over it. |
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Refs #2237. Stacked on #2549.
This replaces most of the hand-written endpoint table behind
limitToTargetwith rules Sentry declares in its own schema.It bumps
@sentry/apito 3.5.0, the first release that carries Sentry'sx-sentry-project-scopeextension (getsentry/sentry#132722) asApiOperation.projectScope.What changes
target-scope-rules.tsreadsprojectScopefrom@sentry/api3.5.0'soperationscatalog, which the CLI already bundles, so no generated copy of the declarations is needed. It builds a rule for each operation whose scope isn'tpath:org-metadata: an org read that the project scope may send.filter: an org endpoint that gets filtered to the scope's project.response:<pointer>: a lookup by an ID alone. The response is checked against the numeric project IDs at that JSON pointer, where*matches each array element. A write to the same path, or any request below it, looks the resource up first.What stays hand-written, because the schema can't say it:
customers/:org/;trace/andtrace-meta/;trace-logs, which ignoresproject, so it looks the trace up first;Behavior changes
filterfrom an endpoint'sprojectparameter, so a project scope sends these with?project=<id>instead of refusing them:organizations/:org/stats_v2/organizations/:org/sessions/organizations/:org/agents/conversations/{conversation_id}/via @BYK.
--
View Session [Sentry]