Skip to content

feat(mcp): Default organizationSlug to the user's only organization - #1836

Merged
BYK merged 3 commits into
mainfrom
feat/mcp-default-single-org
Nov 3, 2026
Merged

BYK merged 3 commits into
mainfrom
feat/mcp-default-single-org

Conversation

@sentry-junior

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

Copy link
Copy Markdown
Contributor

When a tool call leaves out organizationSlug and the login can reach exactly one organization, the call now uses that organization. When the login can reach several, a tool that requires the slug fails with a retry the model can run as is, plus the other organizations. This is the MCP version of the CLI recovery in #1634, and it finishes the part #1678 held back. The server never chooses between organizations.

Why now

Over the last 7 days (sentry/mcp-server spans, extrapolated counts):

  • organizationSlug: Required failures: about 4.3K, from search_issues, find_projects, search_errors, search_logs, and calls through execute_sentry_tool. get_sentry_resource adds about 1.9K more with "organizationSlug is required when not using a URL".
  • The script that sent about 89% of the earlier ~31K/week has stopped. The rest is spread out: no user accounts for more than 2 of the 40 sampled failures.

How it works

  • No schema or handler edits. getFilteredInputSchema makes a required organizationSlug optional at registration time, so the MCP SDK no longer rejects the call before our code runs. Then prepareToolCallParams runs applyDefaultOrganization. Both top-level calls and execute_sentry_tool go through it, before withRoutedCredential, so stdio account routing (feat(mcp-server): Route stdio tool calls to the stored account that knows the org #1802) gets the defaulted slug.
  • It runs only when the call has no slug after constraint injection and no Sentry URL parameter (it reuses getTargetOrganizationSlug). Org-scoped sessions never reach it.
  • One organization: the call uses its slug. If the tool takes regionUrl and the caller didn't set one, the call also gets the organization's regionUrl. On self-hosted that value is empty, so regionUrl stays unset.
  • Several organizations: for a required slug, the error looks like Retry example: `search_issues(organizationSlug='org-a', period='1h')` and lists the other organizations. Catalog tools get the execute_sentry_tool(name=…, arguments=…) form, and values equal to a schema default are left out. For an optional slug (URL-or-ID tools such as get_sentry_resource), the call runs as before.
  • Listing fails (for example, a token without org:read): the error falls back to the find_organizations hint from fix(mcp): Accept 1h and minute periods; guide models to find_organizations on missing org #1678.
  • Multiple logins: organizations from every account are merged.

Fit with #1669

  • The organization list comes from SentryApiService.listOrganizations, which already uses the shared endpoints/organizations wrapper and transport (ref(mcp): Send Sentry API requests through the shared transport #1722, ref(mcp): Send SentryApiService requests through a shared request core #1737). No new endpoint code.
  • The resolve step lives in mcp-core's constraint and param-prep layer. The design keeps that layer in mcp-core ("an MCP tool fills them from tool parameters and session constraints"), so 11.3 can keep it as is.
  • The MCP hosts don't wire a CacheStore yet (7.1 is still open). Instead, the list is memoized per context and credential for 5 minutes, which matches the stable tier. When 7.1 lands, the /organizations/ request gets cached per identity on its own, and this memo can be dropped. It doesn't conflict with 8.4–8.7 or 11.x.
  • This doesn't complete a task in the plan. The closest is 11.3's resolve step.

Token cost

measure-tokens is unchanged at 9,014. That script reads the raw tool schemas, and those didn't change. In the registered schemas, organizationSlug is no longer in the required list on 8 direct tools, which comes to 5,014 → 4,990 input-schema tokens.

Open questions

  • A null slug still gets the find_organizations hint. Accepting null would add anyOf to every schema.
  • When an optional-slug tool like get_sentry_resource is called by a user with several organizations, it keeps its own error. It doesn't list the organizations yet.

via @BYK.

--

View Session [Sentry]

A tool call that omits organizationSlug now uses the organization when
the login can access exactly one. With several, a tool that requires it
fails with a ready-to-run retry and the list of organizations, the same
recovery the CLI added in #1634. The server never picks between
organizations.

Tool registration makes a required organizationSlug optional, and the
shared param-prep step fills it before credential routing, so no tool
schema or handler changes. The organization list is fetched through
the shared client and memoized per context for five minutes.

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

vercel Bot commented Nov 3, 2026 •

Copy link
Copy Markdown

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

1 Skipped Deployment
Project Deployment Actions Updated
sentry-local Skipped Skipped Nov 3, 2026 12:57am UTC

Request Review

@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 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 6c2b69b. Configure here.

With several logins, a login whose organization listing fails is skipped,
so one remaining organization could be defaulted while the failed login
hid another. Default only when every login answered; otherwise the
required-slug error says some logins could not list their organizations.
A partial list is not memoized.
…l URL

The URL check that lets a Sentry URL stand in for organizationSlug also
ran for tools that require the slug. Uptime monitor tools take their
target as `url`, so https://example.com/health was read as organization
"example" and the default was skipped. Only optional slugs check URLs now;
a tool that requires the slug never reads it from a URL.
@BYK
BYK merged commit ce1b210 into main Nov 3, 2026
35 checks passed
@BYK
BYK deleted the feat/mcp-default-single-org branch November 3, 2026 10:24

This branch was successfully deployed

1 active and 1 inactive deployments
Actions — 4ae48dfb Deployed Nov 3, 2026 by sentry-junior[bot] via eval #1507
Preview — 4ae48dfb Deployed Nov 3, 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