Skip to content

feat(apidocs): Publish x-sentry-project-scope on operations - #132722

Merged
BYK merged 3 commits into
masterfrom
feat/apidocs-x-sentry-project-scope
Nov 27, 2026
Merged

BYK merged 3 commits into
masterfrom
feat/apidocs-x-sentry-project-scope

Conversation

@sentry-junior

@sentry-junior sentry-junior Bot commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

Adds an x-sentry-project-scope operation extension to the OpenAPI schema. It works like x-sentry-idempotent: the schema build stamps it on each operation before issue alias canonicalization.

The Sentry CLI and MCP server limit a caller to an org or project at the HTTP transport, using a hand-written table of endpoint rules (getsentry/toolkit#2549). With this extension they can read the same facts from the schema through @sentry/api/operations. Refs getsentry/toolkit#2237.

What the value means

The value is a string on an operation (path + method). It says how the request names the projects whose data the operation returns or changes:

Value Meaning
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 has no project's issues, events, replays, or other telemetry, such as settings, members, integrations, and saved views.
response:<pointer> A GET lookup by ID alone. The numeric project ID of the object it found is at <pointer> in the response body. <pointer> is an RFC 6901 JSON pointer, plus a * segment that matches every element of an array, e.g. response:/projects/*/id.

An operation with no value isn't known to respect a project limit.

Where values come from

The build derives two values from the schema:

  • path on every operation whose path contains {project_id_or_slug}.
  • filter on every other operation that documents the project query parameter (OrganizationParams.PROJECT in @extend_schema).

Endpoints declare the rest per method on the class, and a declared value wins over a derived filter:

project_scope = {"GET": "response:/projects/*/id"}

Endpoint.project_scope: dict[HTTP_METHOD_NAME, str] defaults to {}. The build fails when:

  • the value isn't filter, org-metadata, or response:<pointer> (path can't be declared),
  • response: or org-metadata is on a method other than GET,
  • the text after response: isn't a JSON pointer,
  • the pointer doesn't reach a string or integer field in the operation's 200 response schema (following $ref, allOf, oneOf, anyOf, and array items),
  • a method isn't in publish_status,
  • the declaration is on a path that already contains {project_id_or_slug}.

Declarations are collected for unpublished endpoints too and reset on every build. Subclasses inherit them, like idempotent_methods. The SCIM team details endpoint sets project_scope = {}, so it doesn't inherit org-metadata from team details. The rules are documented in src/sentry/apidocs/README.md.

Values in the schema

Paths are relative to /organizations/{organization_id_or_slug}/ unless shown otherwise.

  • path (derived): 91 operations.
  • filter (derived): 36 operations. These include issues/ (GET, PUT, DELETE), GET on events/, events-timeseries/, events-dropped/, trace-items/attributes/, replays/, replay-count/, monitors/, detectors/, workflows/, releases/, agents/conversations/, issues-stats/, sessions/, tags/, stats_v2/, and profiling/*, plus PUT/DELETE on detectors/ and workflows/.
  • response: (declared, GET):
    • issues/{issue_id}/ → response:/project/id
    • replays/{replay_id}/ → response:/data/project_id
    • monitors/{monitor_id_or_slug}/ → response:/project/id
    • detectors/{detector_id}/ → response:/projectId (null for the all-projects detector)
    • releases/{version}/ → response:/projects/*/id
  • org-metadata (declared, GET): the organization itself, projects/, teams/, user-teams/, members/, members/{member_id}/, environments/, dsn-lookup/, chunk-upload/, integrations/, integrations/{integration_id}/ (plus channels/, repos/, and channel-validate/), config/integrations/, available-actions/, sentry-apps/, sentry-app-installations/, sentry-app-components/, repos/, repos/{repo_id}/commits/, code-mappings/, dashboards/, dashboards/{dashboard_id}/, dashboards/{dashboard_id}/revisions/, discover/saved/, discover/saved/{query_id}/, group-search-views/, and workflows/{workflow_id}/. Also /teams/{organization_id_or_slug}/{team_id_or_slug}/, .../members/, and .../projects/.

Follow-ups

A getsentry/sentry-api-schema PR will carry the extension into the published schema and @sentry/api/operations. A getsentry/toolkit PR will then replace the hand-written scope table with these values. Both will link back here.

via @BYK.

--

View Session [Sentry]

sentry-junior Bot and others added 2 commits November 27, 2026 00:22
Add a project_scope declaration to Endpoint, published as the
x-sentry-project-scope operation extension. It says how a request names the
projects whose data it returns or changes: "path" (stamped automatically on
every path with {project_id_or_slug}), "filter" (the project query
parameter), "org-metadata" (read-only organization metadata), or
"response:<pointer>" (a GET by ID whose project ID is at a JSON pointer in
the response). The schema build validates declarations.

Clients such as the Sentry CLI and MCP server can then enforce a project limit
from the schema instead of a hand-written endpoint table.

Refs getsentry/toolkit#2237

Co-Authored-By: BYK <[email protected]>
The SCIM team details endpoint and the private insights tree and trace item
attribute details/merged endpoints inherit a project_scope that was not
checked against their handlers. Clear it so only the declared endpoints
publish a value.

Co-Authored-By: BYK <[email protected]>
@github-actions github-actions Bot added the Scope: Backend Automatically applied to PRs that change backend components label Nov 27, 2026
sentry-junior Bot added a commit to getsentry/toolkit that referenced this pull request Nov 27, 2026
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 <[email protected]>
@sentry-junior
sentry-junior Bot requested a review from BYK November 27, 2026 00:51
Comment thread src/sentry/apidocs/README.md Resolved
@sentry-junior
sentry-junior Bot requested a review from BYK November 27, 2026 10:55
BYK added a commit 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 <[email protected]>
sentry-junior Bot added a commit to getsentry/toolkit that referenced this pull request Nov 27, 2026
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 <[email protected]>
sentry-junior Bot added a commit to getsentry/toolkit that referenced this pull request Nov 27, 2026
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 <[email protected]>
sentry-junior Bot added a commit to getsentry/toolkit that referenced this pull request Nov 27, 2026
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 <[email protected]>
@BYK
BYK marked this pull request as ready for review November 27, 2026 13:35
@BYK
BYK requested review from a team as code owners November 27, 2026 13:35
Stamp "filter" on every non-project-path operation that documents the
project query parameter, instead of declaring it per endpoint. A declared
value still wins. Fail the schema build when a "response:" pointer does not
reach a string or integer field in the operation's 200 response schema.

Refs getsentry/toolkit#2237
@BYK
BYK merged commit cbe60ac into master Nov 27, 2026
109 checks passed
@BYK
BYK deleted the feat/apidocs-x-sentry-project-scope branch November 27, 2026 23:17
sentry-junior Bot added a commit to getsentry/toolkit that referenced this pull request Nov 28, 2026
3.5.0 carries Sentry's x-sentry-project-scope declarations
(getsentry/sentry#132722) as each operation's projectScope.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Scope: Backend Automatically applied to PRs that change backend components

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant