Skip to content

fix(mcp): Check an issue an ID alone names against the session's project - #2527

Open
sentry-junior[bot] wants to merge 5 commits into
mainfrom
fix/mcp-commands-numeric-issue-scope
Open

sentry-junior[bot] wants to merge 5 commits into
mainfrom
fix/mcp-commands-numeric-issue-scope

Conversation

@sentry-junior

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

Copy link
Copy Markdown
Contributor

Refs #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 fix(mcp): Limit sentry mcp --commands sessions to their target #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 fix(mcp): Limit sentry mcp --commands sessions to their target #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).

via @BYK.

--

View Session [Sentry]

@sentry-junior
sentry-junior Bot added this pull request to stack #1926 November 26, 2026 12:20
@vercel

vercel Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

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

Project Deployment Actions Updated
cli Ready Ready Preview Nov 28, 2026 1:41am UTC
1 Skipped Deployment
Project Deployment Actions Updated
sentry-local Skipped Skipped Nov 28, 2026 1:41am UTC

Request Review

@github-actions github-actions Bot added the risk: medium PR risk score: medium label Nov 26, 2026

@BYK BYK left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

We should do this right away in a follow up PR>

sentry-junior Bot and others added 3 commits November 27, 2026 11:40
The SDK's fake process started with `exitCode: 0`. Stricli records a
failure with `exitCode ??= code`, which a 0 swallows, so `sdk.run()`
resolved `undefined` for a command that failed, such as one whose API
request returned 404. The exit code now starts unset, as on Node's own
`process`.

Ported from the same fix in #1922, which the scope checks in this stack
need: a refused request has to reach the caller as an error.

Refs #2237

Co-Authored-By: BYK <126780+BYK@users.noreply.github.com>
In a project-scoped `sentry mcp --commands` session, the command surface
checks the targets a call names, but a numeric issue ID, an issue URL,
a share link, a selector (`@latest`), or search text names no project,
so `issue view 12345` or `issue resolve 12345` reached an issue in
another project of the same organization.

The stdio runner now passes `limitToTarget` to the CLI SDK, which makes
the session's org and project a limit instead of a default. Issue
lookups check the issue they find before a command reads or changes it:
`getIssueInOrg` and `getIssueByShortId` refuse another organization
before the request and another project after it, the issue and Feedback
selectors and issue search look only in the session's project, and
`event view` checks a numeric issue before it reads the issue's events.

Fixes #2237

Co-Authored-By: BYK <126780+BYK@users.noreply.github.com>
`limitToTarget` now defaults to `true`: with `org` (and `project`) set,
`createSentrySDK()` refuses an issue outside them, including one an ID
alone names (`issue view 12345`, `@latest`). Pass `limitToTarget: false`
to use `org` and `project` only as defaults, as before.

`sentry mcp --commands` still passes `limitToTarget: true` explicitly, so
its sessions don't depend on the default.

BREAKING CHANGE: `createSentrySDK({ org, project })` no longer reads or
changes issues outside `org`/`project`. Callers that use them only to skip
typing the slug and look up issues elsewhere must pass
`limitToTarget: false`.

Refs #2237

Co-Authored-By: BYK <126780+BYK@users.noreply.github.com>
@sentry-junior
sentry-junior Bot force-pushed the fix/mcp-commands-numeric-issue-scope branch from d76215d to 25e63d8 Compare November 27, 2026 11:56
@cursor

cursor Bot commented Nov 27, 2026

Copy link
Copy Markdown
Contributor

This PR is too large for Bugbot to review. It changes 50,402 lines and 3,791,240 characters. Split the change into smaller pull requests to get a review.

@sentry-junior

sentry-junior Bot commented Nov 27, 2026

Copy link
Copy Markdown
Contributor Author

bugbot run

@BYK
BYK enabled stacked auto-merge November 27, 2026 23:28

@cursor cursor Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit c77ff29. Configure here.

In a project-scoped session, the issue search runs in that project
alone, so the no-match and several-match errors name it, and their
recovery command lists that project's issues.

This branch was successfully deployed

1 active and 1 inactive deployments
Preview – cli — b9062ad0 Deployed Nov 28, 2026 by vercel[bot]
Preview – sentry-local — b9062ad0 Deployed Nov 28, 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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant