Skip to content
Merged
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
2 changes: 1 addition & 1 deletion packages/mcp-core/src/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Comment thread
sentry-junior[bot] marked this conversation as resolved.
Resolved
Expand Down
2 changes: 1 addition & 1 deletion packages/mcp-core/src/toolDefinitions.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion packages/mcp-core/src/tools/catalog/find-releases.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
86 changes: 85 additions & 1 deletion packages/mcp-core/src/tools/catalog/update-issue.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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;
Expand Down Expand Up @@ -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`",
},
Expand Down
65 changes: 51 additions & 14 deletions packages/mcp-core/src/tools/catalog/update-issue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`",
Expand All @@ -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,
Expand Down Expand Up @@ -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
Expand Down
Loading