Skip to content
Open
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
5 changes: 5 additions & 0 deletions packages/mcp-core/src/api-client/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ import {
getReleaseUrl as getReleaseUrlUtil,
getReplaysSearchUrl as getReplaysSearchUrlUtil,
getReplayUrl as getReplayUrlUtil,
getSeerAutoReloadUrl as getSeerAutoReloadUrlUtil,
getTraceMetricsExploreUrl,
getTraceUrl as getTraceUrlUtil,
getUptimeMonitorUrl as getUptimeMonitorUrlUtil,
Expand Down Expand Up @@ -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);
}
Expand Down
64 changes: 42 additions & 22 deletions packages/mcp-core/src/internal/tool-helpers/seer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
});
});
Expand Down
21 changes: 15 additions & 6 deletions packages/mcp-core/src/internal/tool-helpers/seer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,17 +155,25 @@ function lookupKnownKey<K extends string, V>(
* 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}`;
}

/**
Expand Down Expand Up @@ -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 "";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand Down Expand Up @@ -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",
);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -213,6 +213,7 @@ export default defineTool({
output += `\n**Status**: ${status}\n`;
output += getFailureReasonGuidance(
autofixState.autofix.failure_reason,
apiService.getSeerAutoReloadUrl(orgSlug),
);
output += getHumanInterventionGuidance(status);
}
Expand Down
9 changes: 9 additions & 0 deletions packages/mcp-core/src/utils/url-utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
getReleaseUrl,
getReplaysSearchUrl,
getReplayUrl,
getSeerAutoReloadUrl,
getTraceMetricsExploreUrl,
getTraceUrl,
getUptimeMonitorUrl,
Expand Down Expand Up @@ -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(
Expand Down
17 changes: 17 additions & 0 deletions packages/mcp-core/src/utils/url-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`;
}
Comment thread
srest2021 marked this conversation as resolved.
Resolved

/**
* Generates a Sentry dashboard URL.
* @param host The Sentry host (may include regional subdomain for API access)
Expand Down
Loading