From d084bdc058969ecc5f9743fcccd3a6a17e6ac519 Mon Sep 17 00:00:00 2001 From: "sentry-junior[bot]" <264270552+sentry-junior[bot]@users.noreply.github.com> Date: Mon, 16 Nov 2026 16:10:45 +0000 Subject: [PATCH] fix(tools): Explain link_issue's installation 404 for integration tokens Sentry answers GET /organizations/{org}/sentry-app-installations/ with 404 "Could not find requested organization" when the token's user is not an org member, such as an internal integration's proxy user. link_issue passed that through after it had already read the issue in the same org, so agents retried with other issue ID and URL forms. Translate that 404 into a UserInputError that says a user token or OAuth sign-in is needed. Reported through MCP feedback MCP-SERVER-GQW. --- docs/specs/issue-linking.md | 3 +++ .../tools/support/issue-linking/app.test.ts | 16 +++++++++++++ .../src/tools/support/issue-linking/app.ts | 24 ++++++++++++++++++- 3 files changed, 42 insertions(+), 1 deletion(-) diff --git a/docs/specs/issue-linking.md b/docs/specs/issue-linking.md index 2a1bbc649..6691b11db 100644 --- a/docs/specs/issue-linking.md +++ b/docs/specs/issue-linking.md @@ -35,6 +35,9 @@ inferred from their URLs. `link_issue` accepts optional `fields` for additional values required by the App's issue-link form. The client reads the installed component and resolves its form choices before invoking its link callback. Missing or ambiguous fields are reported without submitting the callback. +Sentry lists App installations only for organization members. An integration +token gets a 404 "Could not find requested organization" there even when it can +read the issue. The tool reports that a user token or OAuth sign-in is needed. Supported fields are single-value selects, text, and textarea. Other field types and multi-select fields are reported as unsupported. diff --git a/packages/mcp-core/src/tools/support/issue-linking/app.test.ts b/packages/mcp-core/src/tools/support/issue-linking/app.test.ts index f49d25643..ac6459dc0 100644 --- a/packages/mcp-core/src/tools/support/issue-linking/app.test.ts +++ b/packages/mcp-core/src/tools/support/issue-linking/app.test.ts @@ -437,6 +437,22 @@ describe("linkAppIssue", () => { ); expect(actions).toBe(1); }); + + it("explains the installation-list 404 that tokens without org membership get", async () => { + mockDiscovery(); + // Sentry's response to an internal integration token for an org it can read. + mswServer.use( + http.get(`${base}/organizations/example/sentry-app-installations/`, () => + HttpResponse.json( + { detail: "Could not find requested organization" }, + { status: 404 }, + ), + ), + ); + await expect(linkAppIssue(api, params)).rejects.toThrow( + "Sentry only lists Sentry App installations for organization members", + ); + }); }); describe("unlinkAppIssue", () => { diff --git a/packages/mcp-core/src/tools/support/issue-linking/app.ts b/packages/mcp-core/src/tools/support/issue-linking/app.ts index 71fea223a..543fbfcf2 100644 --- a/packages/mcp-core/src/tools/support/issue-linking/app.ts +++ b/packages/mcp-core/src/tools/support/issue-linking/app.ts @@ -300,6 +300,28 @@ async function resolveFields( return values; } +/** + * Sentry answers 404 "Could not find requested organization" when the token's + * user is not an org member, such as an internal integration's proxy user, even + * though the caller already read the issue in that org. + */ +async function listInstallations( + api: AppIssueLinkApi, + params: AppIssueLinkParams, +) { + try { + return await api.listSentryAppInstallations(params); + } catch (error) { + if (error instanceof ApiClientError && error.status === 404) { + throw new UserInputError( + `Sentry returned 404 when listing Sentry App installations for organization '${params.organizationSlug}'. Sentry only lists Sentry App installations for organization members, so integration tokens get this 404 even when they can read the issue. Link Sentry App issues with a user token or an OAuth sign-in; a different issue ID or URL won't help.`, + { cause: error }, + ); + } + throw error; + } +} + /** Prepare a complete form even on retries, since an existing association may disappear. */ export async function linkAppIssue( api: AppIssueLinkApi, @@ -309,7 +331,7 @@ export async function linkAppIssue( if (!appSlug) throw new UserInputError("Provide appSlug for this external issue URL."); const [installations, components, links] = await Promise.all([ - api.listSentryAppInstallations(params), + listInstallations(api, params), api.listSentryAppComponents(params), api.getIssueExternalLinks(params), ]);