diff --git a/packages/mcp-core/src/api-client/client.ts b/packages/mcp-core/src/api-client/client.ts index 7f848ce72..300630ca6 100644 --- a/packages/mcp-core/src/api-client/client.ts +++ b/packages/mcp-core/src/api-client/client.ts @@ -113,6 +113,7 @@ import { getReleaseUrl as getReleaseUrlUtil, getReplaysSearchUrl as getReplaysSearchUrlUtil, getReplayUrl as getReplayUrlUtil, + getSeerAutoReloadUrl as getSeerAutoReloadUrlUtil, getTraceMetricsExploreUrl, getTraceUrl as getTraceUrlUtil, getUptimeMonitorUrl as getUptimeMonitorUrlUtil, @@ -861,6 +862,10 @@ export class SentryApiService { return getTraceUrlUtil(this.host, organizationSlug, traceId, this.protocol); } + getSeerAutoReloadUrl(organizationSlug: string): string { + return getSeerAutoReloadUrlUtil(this.host, organizationSlug, this.protocol); + } + getLogUrl(organizationSlug: string, logId: string): string { return getLogUrlUtil(this.host, organizationSlug, logId, this.protocol); } diff --git a/packages/mcp-core/src/internal/tool-helpers/seer.test.ts b/packages/mcp-core/src/internal/tool-helpers/seer.test.ts index e082bfc55..a5d02a08d 100644 --- a/packages/mcp-core/src/internal/tool-helpers/seer.test.ts +++ b/packages/mcp-core/src/internal/tool-helpers/seer.test.ts @@ -150,45 +150,65 @@ describe("seer-utils", () => { }); describe("getSeerPaymentRequiredMessage", () => { + const autoReloadUrl = "https://my-org.sentry.io/billing#modal"; + it("explains each 402 code from the API schema", () => { expect( - getSeerPaymentRequiredMessage({ - detail: "Out of credits", - code: "seer_out_of_credits", - }), - ).toBe(SEER_START_OUT_OF_CREDITS_MESSAGE); + getSeerPaymentRequiredMessage( + { + detail: "Out of credits", + code: "seer_out_of_credits", + }, + autoReloadUrl, + ), + ).toContain(SEER_START_OUT_OF_CREDITS_MESSAGE); expect( - getSeerPaymentRequiredMessage({ - detail: "No quota", - code: "seer_out_of_quota", - }), + getSeerPaymentRequiredMessage( + { + detail: "No quota", + code: "seer_out_of_quota", + }, + autoReloadUrl, + ), ).toContain("not have enough Seer quota"); }); it.each([ - ["daily_cap_exceeded", "daily Seer spend limit"], - ["not_enough_credits", SEER_START_OUT_OF_CREDITS_MESSAGE], - [null, SEER_START_OUT_OF_CREDITS_MESSAGE], - ["constructor", SEER_START_OUT_OF_CREDITS_MESSAGE], + ["daily_cap_exceeded", "daily Seer spend limit", ":daily_cap_exceeded"], + [ + "not_enough_credits", + SEER_START_OUT_OF_CREDITS_MESSAGE, + ":not_enough_credits", + ], + [null, SEER_START_OUT_OF_CREDITS_MESSAGE, ""], + ["constructor", SEER_START_OUT_OF_CREDITS_MESSAGE, ""], ])( "explains an out-of-credits 402 with denial reason %s", - (denialReason, message) => { - expect( - getSeerPaymentRequiredMessage({ + (denialReason, message, reasonSuffix) => { + const result = getSeerPaymentRequiredMessage( + { detail: "Out of credits", code: "seer_out_of_credits", denialReason, - }), - ).toContain(message); + }, + autoReloadUrl, + ); + expect(result).toContain(message); + expect(result.split("\n").at(-1)).toBe( + `Configure auto-reload: ${autoReloadUrl}${reasonSuffix}`, + ); }, ); it("treats a 402 without a known code as out of quota", () => { - expect(getSeerPaymentRequiredMessage("No budget")).toContain( - "not have enough Seer quota", - ); expect( - getSeerPaymentRequiredMessage({ detail: "x", code: "constructor" }), + getSeerPaymentRequiredMessage("No budget", autoReloadUrl), + ).toContain("not have enough Seer quota"); + expect( + getSeerPaymentRequiredMessage( + { detail: "x", code: "constructor" }, + autoReloadUrl, + ), ).toContain("not have enough Seer quota"); }); }); diff --git a/packages/mcp-core/src/internal/tool-helpers/seer.ts b/packages/mcp-core/src/internal/tool-helpers/seer.ts index 2e6d35f63..defde4b64 100644 --- a/packages/mcp-core/src/internal/tool-helpers/seer.ts +++ b/packages/mcp-core/src/internal/tool-helpers/seer.ts @@ -155,17 +155,25 @@ function lookupKnownKey( * Sentry versions send the out-of-quota 402 as a bare string with no code, so * anything that isn't out of credits is treated as out of quota. */ -export function getSeerPaymentRequiredMessage(responseBody: unknown): string { +export function getSeerPaymentRequiredMessage( + responseBody: unknown, + autoReloadUrl: string, +): string { if ( !isPlainObject(responseBody) || !lookupKnownKey(SEER_OUT_OF_CREDITS_CODES, responseBody["code"]) ) { return SEER_NO_QUOTA_MESSAGE; } - return ( - lookupKnownKey(SEER_DENIAL_MESSAGES, responseBody["denialReason"]) ?? - SEER_START_OUT_OF_CREDITS_MESSAGE - ); + const denialReason = responseBody["denialReason"]; + const message = lookupKnownKey(SEER_DENIAL_MESSAGES, denialReason); + return message + ? `${message}${formatAutoReloadLink(`${autoReloadUrl}:${denialReason as string}`)}` + : `${SEER_START_OUT_OF_CREDITS_MESSAGE}${formatAutoReloadLink(autoReloadUrl)}`; +} + +function formatAutoReloadLink(url: string): string { + return `\n\nConfigure auto-reload: ${url}`; } /** @@ -194,9 +202,10 @@ export function getSeerSetupRequiredMessage( */ export function getFailureReasonGuidance( failureReason: string | null | undefined, + autoReloadUrl: string, ): string { if (failureReason === "out_of_credits") { - return `\n${SEER_CONTINUE_OUT_OF_CREDITS_MESSAGE}\n`; + return `\n${SEER_CONTINUE_OUT_OF_CREDITS_MESSAGE}${formatAutoReloadLink(autoReloadUrl)}\n`; } return ""; } diff --git a/packages/mcp-core/src/tools/catalog/analyze-issue-with-seer.test.ts b/packages/mcp-core/src/tools/catalog/analyze-issue-with-seer.test.ts index 91954344b..79a5b7472 100644 --- a/packages/mcp-core/src/tools/catalog/analyze-issue-with-seer.test.ts +++ b/packages/mcp-core/src/tools/catalog/analyze-issue-with-seer.test.ts @@ -434,7 +434,7 @@ describe("analyze_issue_with_seer", () => { "Your organization does not have enough credits to start an Autofix run.", code: "seer_out_of_credits", }, - "Your organization does not have enough credits to start an Autofix run. Someone with billing access can adjust Seer spend and auto-reload in Sentry.", + "Your organization does not have enough credits to start an Autofix run. Someone with billing access can adjust Seer spend and auto-reload in Sentry.\n\nConfigure auto-reload: https://sentry-mcp-evals.sentry.io/settings/billing/overview/#open-seer-auto-reload-modal", ], [ "out of credits, not enough credits", @@ -444,7 +444,7 @@ describe("analyze_issue_with_seer", () => { code: "seer_out_of_credits", denialReason: "not_enough_credits", }, - "Your organization does not have enough credits to start an Autofix run. Someone with billing access can adjust Seer spend and auto-reload in Sentry.", + "Your organization does not have enough credits to start an Autofix run. Someone with billing access can adjust Seer spend and auto-reload in Sentry.\n\nConfigure auto-reload: https://sentry-mcp-evals.sentry.io/settings/billing/overview/#open-seer-auto-reload-modal:not_enough_credits", ], [ "out of credits, null denial reason", @@ -454,7 +454,7 @@ describe("analyze_issue_with_seer", () => { code: "seer_out_of_credits", denialReason: null, }, - "Your organization does not have enough credits to start an Autofix run. Someone with billing access can adjust Seer spend and auto-reload in Sentry.", + "Your organization does not have enough credits to start an Autofix run. Someone with billing access can adjust Seer spend and auto-reload in Sentry.\n\nConfigure auto-reload: https://sentry-mcp-evals.sentry.io/settings/billing/overview/#open-seer-auto-reload-modal", ], [ "daily spend limit reached", @@ -464,7 +464,7 @@ describe("analyze_issue_with_seer", () => { code: "seer_out_of_credits", denialReason: "daily_cap_exceeded", }, - "Your organization has reached its daily Seer spend limit. Someone with billing access can raise the limit in Sentry, or you can try again tomorrow.", + "Your organization has reached its daily Seer spend limit. Someone with billing access can raise the limit in Sentry, or you can try again tomorrow.\n\nConfigure auto-reload: https://sentry-mcp-evals.sentry.io/settings/billing/overview/#open-seer-auto-reload-modal:daily_cap_exceeded", ], [ "out of quota", @@ -786,7 +786,7 @@ describe("analyze_issue_with_seer", () => { expect(result).toContain("## Analysis Failed"); expect(result).toContain( - "Your organization does not have enough credits to continue your Autofix run. Someone with billing access can adjust Seer spend and auto-reload in Sentry.", + "Your organization does not have enough credits to continue your Autofix run. Someone with billing access can adjust Seer spend and auto-reload in Sentry.\n\nConfigure auto-reload: https://sentry-mcp-evals.sentry.io/settings/billing/overview/#open-seer-auto-reload-modal", ); }); diff --git a/packages/mcp-core/src/tools/catalog/analyze-issue-with-seer.ts b/packages/mcp-core/src/tools/catalog/analyze-issue-with-seer.ts index 352608080..c036e890e 100644 --- a/packages/mcp-core/src/tools/catalog/analyze-issue-with-seer.ts +++ b/packages/mcp-core/src/tools/catalog/analyze-issue-with-seer.ts @@ -118,7 +118,7 @@ export default defineTool({ // Sentry answers 402 before starting a run when the org is out of // Seer credits or quota. if (error instanceof ApiError && error.status === 402) { - output += `## Analysis Not Started\n\n${getSeerPaymentRequiredMessage(error.responseBody)}\n`; + output += `## Analysis Not Started\n\n${getSeerPaymentRequiredMessage(error.responseBody, apiService.getSeerAutoReloadUrl(orgSlug))}\n`; // The failed run may already hold paid-for analysis, e.g. a root // cause found before the org ran out of credits. const previousOutput = previousRun @@ -213,6 +213,7 @@ export default defineTool({ output += `\n**Status**: ${status}\n`; output += getFailureReasonGuidance( autofixState.autofix.failure_reason, + apiService.getSeerAutoReloadUrl(orgSlug), ); output += getHumanInterventionGuidance(status); } diff --git a/packages/mcp-core/src/utils/url-utils.test.ts b/packages/mcp-core/src/utils/url-utils.test.ts index bfd2a0742..05412e06a 100644 --- a/packages/mcp-core/src/utils/url-utils.test.ts +++ b/packages/mcp-core/src/utils/url-utils.test.ts @@ -11,6 +11,7 @@ import { getReleaseUrl, getReplaysSearchUrl, getReplayUrl, + getSeerAutoReloadUrl, getTraceMetricsExploreUrl, getTraceUrl, getUptimeMonitorUrl, @@ -169,6 +170,14 @@ describe("url-utils", () => { }); }); + describe("getSeerAutoReloadUrl", () => { + it("links the org's billing settings on a dedicated host", () => { + expect(getSeerAutoReloadUrl("acme.my.sentry.io", "myorg")).toBe( + "https://acme.my.sentry.io/settings/myorg/billing/overview/#open-seer-auto-reload-modal", + ); + }); + }); + describe("getReleaseUrl", () => { it("should encode release versions in the path segment", () => { const result = getReleaseUrl( diff --git a/packages/mcp-core/src/utils/url-utils.ts b/packages/mcp-core/src/utils/url-utils.ts index 3fb5c0703..f331e0c5f 100644 --- a/packages/mcp-core/src/utils/url-utils.ts +++ b/packages/mcp-core/src/utils/url-utils.ts @@ -346,6 +346,23 @@ export function getIssueUrl( ); } +/** + * Generates a link to the billing page with the Seer auto-reload modal open. + * @param host The Sentry host (may include regional subdomain for API access) + * @param organizationSlug Organization identifier + * @returns The complete billing URL + */ +export function getSeerAutoReloadUrl( + host: string, + organizationSlug: string, + protocol: SentryProtocol = "https", +): string { + const base = isPublicSentryHost(host) + ? `${protocol}://${organizationSlug}.sentry.io/settings/billing/overview/` + : `${protocol}://${host}/settings/${organizationSlug}/billing/overview/`; + return `${base}#open-seer-auto-reload-modal`; +} + /** * Generates a Sentry dashboard URL. * @param host The Sentry host (may include regional subdomain for API access)