diff --git a/packages/mcp-core/src/schema.ts b/packages/mcp-core/src/schema.ts index 43cf02666..da753b2d0 100644 --- a/packages/mcp-core/src/schema.ts +++ b/packages/mcp-core/src/schema.ts @@ -259,7 +259,7 @@ export const ParamInRelease = z .trim() .min(1) .describe( - "Release version that fixes the issue. Requires status `resolved`. Events from newer releases reopen it as a regression.", + "Full version of the release that fixes the issue, exactly as find_releases returns it (e.g. `my-app@1.2.3+45`). Requires status `resolved`. Events from newer releases reopen it as a regression.", ); export const ParamInCommit = z diff --git a/packages/mcp-core/src/toolDefinitions.json b/packages/mcp-core/src/toolDefinitions.json index 0965114a6..e25172f18 100644 --- a/packages/mcp-core/src/toolDefinitions.json +++ b/packages/mcp-core/src/toolDefinitions.json @@ -16228,7 +16228,7 @@ "inRelease": { "type": "string", "minLength": 1, - "description": "Release version that fixes the issue. Requires status `resolved`. Events from newer releases reopen it as a regression." + "description": "Full version of the release that fixes the issue, exactly as find_releases returns it (e.g. `my-app@1.2.3+45`). Requires status `resolved`. Events from newer releases reopen it as a regression." }, "inCommit": { "type": "string", diff --git a/packages/mcp-core/src/tools/catalog/find-releases.test.ts b/packages/mcp-core/src/tools/catalog/find-releases.test.ts index adb03acaf..e680b6973 100644 --- a/packages/mcp-core/src/tools/catalog/find-releases.test.ts +++ b/packages/mcp-core/src/tools/catalog/find-releases.test.ts @@ -160,7 +160,7 @@ describe("find_releases", () => { expect(getStructuredContent(result)).toEqual({ releases: [ { - version: "backend@1.2.3", + version: "backend@1.2.3+build.4", dateCreated: "2025-04-13T19:54:21.764Z", dateReleased: "2025-04-14T08:00:00.000Z", firstEvent: "2025-04-13T19:54:21.000Z", diff --git a/packages/mcp-core/src/tools/catalog/find-releases.ts b/packages/mcp-core/src/tools/catalog/find-releases.ts index fd5bccdd8..6c4bc0dc4 100644 --- a/packages/mcp-core/src/tools/catalog/find-releases.ts +++ b/packages/mcp-core/src/tools/catalog/find-releases.ts @@ -85,7 +85,7 @@ export default defineTool({ return structuredResult({ releases: releases.slice(0, RESULT_LIMIT).map((release) => ({ - version: release.shortVersion, + version: release.version, dateCreated: new Date(release.dateCreated).toISOString(), dateReleased: release.dateReleased ? new Date(release.dateReleased).toISOString() diff --git a/packages/mcp-core/src/tools/catalog/update-issue.test.ts b/packages/mcp-core/src/tools/catalog/update-issue.test.ts index e1fd4ae8e..b41246386 100644 --- a/packages/mcp-core/src/tools/catalog/update-issue.test.ts +++ b/packages/mcp-core/src/tools/catalog/update-issue.test.ts @@ -5,6 +5,8 @@ import { } from "@sentry/mcp-server-mocks"; import { HttpResponse, http } from "msw"; import { afterEach, describe, expect, it, vi } from "vitest"; +import { ApiValidationError } from "@sentry/api/client"; +import { UserInputError } from "../../errors"; import { logIssue } from "../../telem/logging"; import { prepareToolParams } from "../catalog-runtime/availability.js"; import { @@ -15,6 +17,7 @@ import updateIssue, { updateIssueOutputSchema } from "./update-issue.js"; vi.mock("../../telem/logging", () => ({ logIssue: vi.fn(), + logWarn: vi.fn(), })); type MockIssue = typeof issueFixture; @@ -936,10 +939,91 @@ describe("update_issue", () => { expect(structured(result).updated).toBe(false); }); + it("explains that inRelease needs the full release version", async () => { + mswServer.use( + http.get( + "https://sentry.io/api/0/organizations/sentry-mcp-evals/issues/CLOUDFLARE-MCP-41/", + () => HttpResponse.json(createIssue({ status: "unresolved" })), + ), + http.put( + "https://sentry.io/api/0/organizations/sentry-mcp-evals/issues/CLOUDFLARE-MCP-41/", + () => + HttpResponse.json( + { + statusDetails: { + inRelease: ["Unable to find a release with the given version."], + }, + }, + { status: 400 }, + ), + ), + ); + + const error = await updateIssue + .handler( + { + organizationSlug: "sentry-mcp-evals", + issueId: "CLOUDFLARE-MCP-41", + status: "resolved", + inRelease: "1.4.2", + assignedTo: undefined, + issueUrl: undefined, + regionUrl: null, + }, + serverContext, + ) + .catch((e: unknown) => e); + + expect(error).toBeInstanceOf(UserInputError); + expect((error as Error).message).toMatchInlineSnapshot( + `"Sentry rejected \`inRelease\` \`1.4.2\`: Unable to find a release with the given version. \`inRelease\` must match a release of this issue's project exactly as Sentry stores it, often with a package prefix and build suffix (e.g. \`my-app@1.2.3+45\`). Copy the version from find_releases. The issue was not changed."`, + ); + }); + + it("keeps other validation errors from the resolve request", async () => { + mswServer.use( + http.get( + "https://sentry.io/api/0/organizations/sentry-mcp-evals/issues/CLOUDFLARE-MCP-41/", + () => HttpResponse.json(createIssue({ status: "unresolved" })), + ), + http.put( + "https://sentry.io/api/0/organizations/sentry-mcp-evals/issues/CLOUDFLARE-MCP-41/", + () => + HttpResponse.json( + { assignedTo: ["Unknown actor input"] }, + { status: 400 }, + ), + ), + ); + + const error = await updateIssue + .handler( + { + organizationSlug: "sentry-mcp-evals", + issueId: "CLOUDFLARE-MCP-41", + status: "resolved", + inRelease: "backend@1.4.2", + assignedTo: undefined, + issueUrl: undefined, + regionUrl: null, + }, + serverContext, + ) + .catch((e: unknown) => e); + + expect(error).toBeInstanceOf(ApiValidationError); + }); + it.each([ { - name: "inRelease without resolved status", + name: "inRelease with resolvedInNextRelease", params: { status: "resolvedInNextRelease" as const, inRelease: "1.0.0" }, + error: + "`resolvedInNextRelease` picks the release itself, so it takes no `inRelease` or `inCommit`", + }, + { + name: "inRelease without resolved status", + params: { status: "unresolved" as const, inRelease: "1.0.0" }, error: "`inRelease` and `inCommit` can only be used when `status` is `resolved`", }, diff --git a/packages/mcp-core/src/tools/catalog/update-issue.ts b/packages/mcp-core/src/tools/catalog/update-issue.ts index 3a7c02a49..a60b91682 100644 --- a/packages/mcp-core/src/tools/catalog/update-issue.ts +++ b/packages/mcp-core/src/tools/catalog/update-issue.ts @@ -240,6 +240,12 @@ function buildResolution( return undefined; } + if (params.status === "resolvedInNextRelease") { + throw new UserInputError( + "`resolvedInNextRelease` picks the release itself, so it takes no `inRelease` or `inCommit`. Drop them, or use status `resolved` with `inRelease` to name an existing release.", + ); + } + if (params.status !== "resolved") { throw new UserInputError( "`inRelease` and `inCommit` can only be used when `status` is `resolved`", @@ -266,6 +272,25 @@ function buildResolution( }; } +const inReleaseErrorSchema = z.object({ + statusDetails: z.object({ inRelease: z.array(z.string()).min(1) }), +}); + +// Sentry matches `inRelease` against the stored version exactly, so a short +// name such as `1.2.3` for `my-app@1.2.3+45` fails. The API client only keeps +// a field error's body as raw text in `detail`. +function getInReleaseErrorReason(error: unknown): string | undefined { + if (!(error instanceof ApiValidationError) || !error.detail) { + return undefined; + } + try { + const parsed = inReleaseErrorSchema.safeParse(JSON.parse(error.detail)); + return parsed.success ? parsed.data.statusDetails.inRelease[0] : undefined; + } catch { + return undefined; + } +} + function isResolutionAlreadySet( issue: Issue, resolution: IssueResolutionDetails, @@ -1100,20 +1125,32 @@ export default defineTool({ } // Update the issue - const updatedIssue = await apiService.updateIssue({ - organizationSlug: orgSlug, - issueId: parsedIssueId, - status: updateStatus, - statusDetails: updateStatus === undefined ? undefined : resolution, - assignedTo: updateAssignedTo, - priority: updatePriority, - substatus: updateIgnore?.substatus, - ignoreDuration: updateIgnore?.ignoreDuration, - ignoreCount: updateIgnore?.ignoreCount, - ignoreWindow: updateIgnore?.ignoreWindow, - ignoreUserCount: updateIgnore?.ignoreUserCount, - ignoreUserWindow: updateIgnore?.ignoreUserWindow, - }); + const updatedIssue = await apiService + .updateIssue({ + organizationSlug: orgSlug, + issueId: parsedIssueId, + status: updateStatus, + statusDetails: updateStatus === undefined ? undefined : resolution, + assignedTo: updateAssignedTo, + priority: updatePriority, + substatus: updateIgnore?.substatus, + ignoreDuration: updateIgnore?.ignoreDuration, + ignoreCount: updateIgnore?.ignoreCount, + ignoreWindow: updateIgnore?.ignoreWindow, + ignoreUserCount: updateIgnore?.ignoreUserCount, + ignoreUserWindow: updateIgnore?.ignoreUserWindow, + }) + .catch((error: unknown) => { + const reason = + params.inRelease !== undefined && getInReleaseErrorReason(error); + if (reason) { + throw new UserInputError( + `Sentry rejected \`inRelease\` \`${params.inRelease}\`: ${reason} \`inRelease\` must match a release of this issue's project exactly as Sentry stores it, often with a package prefix and build suffix (e.g. \`my-app@1.2.3+45\`). Copy the version from find_releases. The issue was not changed.`, + { cause: error }, + ); + } + throw error; + }); // Only closing the issue raises what else the change covers. Each lookup // also calls Seer, and the endpoint's per-user rate limit is tight for