Skip to content

fix(mcp): Limit sentry mcp --commands sessions to their target - #2554

Open
sentry-junior[bot] wants to merge 1 commit into
feat/cli-first-mcp-executefrom
fix/mcp-commands-limit-to-target
Open

sentry-junior[bot] wants to merge 1 commit into
feat/cli-first-mcp-executefrom
fix/mcp-commands-limit-to-target

Conversation

@sentry-junior

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

Copy link
Copy Markdown
Contributor

Refs #2237. Based on #1922.

The scope fix for #2237 (#2527 → #2541 → #2549 → #2552) moved off #1922 onto main. This PR keeps the parts that only make sense with #1922's sentry mcp --commands surface:

  • The stdio runner (packages/cli/src/lib/mcp/command-surface.ts) passes limitToTarget: true to createSentrySDK(), so the session's org and project are a limit, not only defaults.
  • mcp-core constraints.ts notes that an ID alone (a numeric issue ID, an event, trace or replay ID) names no project, so the runner checks what it finds.
  • The --commands section of docs/architecture/overview.md describes the transport scope and the x-sentry-project-scope declarations.

limitToTarget and the transport scope come from #2527–#2552, which #1922 doesn't have yet. Keep this a draft until they land on main and #1922 picks them up.

via @BYK.

--

View Session [Sentry]

The `--commands` pieces of the scope fix for #2237, split out when the
rest of the stack moved off #1922 onto `main`:

- The stdio runner passes `limitToTarget: true` to the CLI SDK, so the
  session's org and project are a limit, not only defaults.
- The command-surface constraints note that an ID alone (a numeric issue
  ID, an event, trace or replay ID) is checked by the runner.
- `command-surface-scope.test.ts` runs the commands of a project-scoped
  session against a mocked Sentry API and checks each kind of ID.
- The architecture overview describes what the transport scope does for
  a `--commands` session.

These need `limitToTarget` and the transport scope from the stack that
starts at #2527, so they build once #1922 has that stack.

Refs #2237

Co-Authored-By: BYK <126780+BYK@users.noreply.github.com>
@vercel

vercel Bot commented Nov 27, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
cli Error Error Nov 27, 2026 11:58am UTC
sentry-local Ready Ready Preview Nov 27, 2026 11:58am UTC

Request Review

github-actions Bot pushed a commit to Fields-Education/sentry-mcp that referenced this pull request Nov 30, 2026
…ect (getsentry#2527)

Refs getsentry#2237. Based on `main`.

In a project-scoped `sentry mcp --commands` session (`acme/web`), the
command surface checks the targets a call names. Some identifiers name
no project: a numeric issue ID, an issue URL, a share link, a selector
such as `@latest`, or search text. The session's org and project reached
the CLI only as defaults (`SENTRY_ORG`/`SENTRY_PROJECT`), so nothing
compared the issue the CLI found with the session. Examples that got
through:

- `issue view 12345` read an issue in another project.
- `issue resolve 12345` changed an issue in another project.
- `issue view @latest` and `feedback view @latest` picked the newest
issue in the whole organization.
- `event view https://acme.sentry.io/issues/12345/` read another
project's events.

As proposed in the issue, the CLI now checks the issue after it looks it
up and before a command reads or changes anything.

**Changes**

- **SDK option.** New `SentryOptions.limitToTarget` makes
`org`/`project` a limit instead of a default. It defaults to `true`, and
`limitToTarget: false` opts out. The SDK passes it to the invocation as
the internal env vars `SENTRY_CLI_SCOPE_ORG`/`SENTRY_CLI_SCOPE_PROJECT`.
The `sentry mcp --commands` runner wiring that sets it now lives in
getsentry#2554.
- **Check helpers.** `lib/target-scope.ts` refuses an issue in another
organization or project with a `ResolutionError`. In a project scope, an
issue whose project is unknown is refused too.
- **Lookups by ID.** `getIssueInOrg` and `getIssueByShortId` refuse
another organization before the request and another project after it.
Every lookup by ID goes through these two: numeric, `<org>/<id>`, URL,
share link, short ID and alias.
- **Selectors and search.** `findSelectorIssue`, issue search and the
Feedback `@latest` selector look only in the session's project, then
check the result.
- **`event view`.** For a numeric issue or an issue URL, it checks the
issue before it reads the issue's events. Before, its project lookup was
best-effort, and it was skipped when the call named a project.
- **Docs.** The SDK option table (`library-usage.md`) now describes the
limit. The `--commands` notes (`docs/architecture/overview.md`, mcp-core
`constraints.ts`) now live in getsentry#2554.

**Breaking change:** `createSentrySDK({ org, project })` callers now get
`org`/`project` as a limit, not just a default, so a command that
reaches another organization or project fails. Pass `limitToTarget:
false` to keep the old behavior.

**Follow-up:** events, traces and replays fetched by an opaque ID
(`event view <event-id>`, `trace view <trace-id>`, `replay view
<replay-id>`) are not checked against the session's project yet. This PR
covers issue lookups only (Feedback included).

<!-- junior-request-attribution:start -->
via @BYK.
<!-- junior-request-attribution:end -->

<!-- junior-session-footer:start -->
<!-- junior-conversation-id:agent%3A30387dbb15a73c1ea95ce25e5f09b56a -->

--

[View
Session](https://junior-prod.sentry.dev/conversations/agent%3A30387dbb15a73c1ea95ce25e5f09b56a)
[[Sentry]](https://sentry.sentry.io/explore/conversations/agent%3A30387dbb15a73c1ea95ce25e5f09b56a/?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>
@github-actions

Copy link
Copy Markdown
Contributor

This PR has had no activity for 3 days. It closes in 2 days unless someone pushes, comments, or adds the WIP label.

@github-actions github-actions Bot added the Stale label Nov 30, 2026
@sentry-junior sentry-junior Bot added the WIP label Nov 30, 2026
@BYK
BYK marked this pull request as ready for review November 30, 2026 20:43
@BYK
BYK requested a review from a team as a code owner November 30, 2026 20:43
@sentry-junior
sentry-junior Bot requested a review from BYK November 30, 2026 20:43
@github-actions github-actions Bot added the risk: medium PR risk score: medium label Nov 30, 2026

This branch had an error being deployed

1 failed and 1 active deployments
Preview – sentry-local — 0f4c6839 Deployed Nov 27, 2026 by vercel[bot]
Preview – cli — 0f4c6839 Deployed Nov 27, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

risk: medium PR risk score: medium Stale WIP

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant