Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions docs/specs/issue-linking.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
16 changes: 16 additions & 0 deletions packages/mcp-core/src/tools/support/issue-linking/app.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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", () => {
Expand Down
24 changes: 23 additions & 1 deletion packages/mcp-core/src/tools/support/issue-linking/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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),
]);
Expand Down
Loading