From d0ed242ca361761fce033a4d71aac6f757196498 Mon Sep 17 00:00:00 2001 From: "sentry-junior[bot]" <264270552+sentry-junior[bot]@users.noreply.github.com> Date: Mon, 23 Nov 2026 19:04:26 +0000 Subject: [PATCH 1/4] feat(mcp): Return Seer investigations from related issues Sentry's related issues endpoint added an investigations type (getsentry/sentry#132090). It fills a separate top-level investigations list with the Seer investigations whose evidence named the issue. find_related_issues asks for it by default and returns each investigation's title, link, hypothesis, and reason. get_issue_details asks for it too and lists the investigations' titles and links. update_issue's resolve side quest asks only for the types that find issues, since it doesn't read investigations. Co-Authored-By: Christina Long <60594860+Christinarlong@users.noreply.github.com> --- packages/mcp-core/src/api-client/client.ts | 13 +++++ packages/mcp-core/src/api-client/schema.ts | 27 ++++++++- packages/mcp-core/src/api-client/types.ts | 2 + .../src/internal/update-issue-side-quests.ts | 6 +- packages/mcp-core/src/skillDefinitions.json | 6 +- packages/mcp-core/src/toolDefinitions.json | 58 +++++++++++++++++-- .../tools/catalog/find-related-issues.test.ts | 41 +++++++++++++ .../src/tools/catalog/find-related-issues.ts | 33 ++++++++++- .../get-issue-details.structured.test.ts | 1 + .../tools/catalog/get-issue-details.test.ts | 23 +++++++- .../src/tools/catalog/get-issue-details.ts | 44 ++++++++++---- .../src/tools/catalog/update-issue.test.ts | 1 + .../src/tools/catalog/update-issue.ts | 3 + packages/mcp-core/src/utils/url-utils.test.ts | 15 +++++ packages/mcp-core/src/utils/url-utils.ts | 15 +++++ .../src/fixtures/related-issues.json | 1 + 16 files changed, 259 insertions(+), 30 deletions(-) diff --git a/packages/mcp-core/src/api-client/client.ts b/packages/mcp-core/src/api-client/client.ts index ef6aa882bd..4b132196a8 100644 --- a/packages/mcp-core/src/api-client/client.ts +++ b/packages/mcp-core/src/api-client/client.ts @@ -104,6 +104,7 @@ import { getAIConversationUrl as getAIConversationUrlUtil, getContinuousProfileUrl as getContinuousProfileUrlUtil, getDashboardUrl as getDashboardUrlUtil, + getInvestigationUrl as getInvestigationUrlUtil, getIssueUrl as getIssueUrlUtil, getLogUrl as getLogUrlUtil, getMonitorUrl as getMonitorUrlUtil, @@ -861,6 +862,18 @@ export class SentryApiService { return getTraceUrlUtil(this.host, organizationSlug, traceId, this.protocol); } + getInvestigationUrl( + organizationSlug: string, + investigationId: string, + ): string { + return getInvestigationUrlUtil( + this.host, + organizationSlug, + investigationId, + this.protocol, + ); + } + getLogUrl(organizationSlug: string, logId: string): string { return getLogUrlUtil(this.host, organizationSlug, logId, this.protocol); } diff --git a/packages/mcp-core/src/api-client/schema.ts b/packages/mcp-core/src/api-client/schema.ts index 31bca87c14..5ac589aeb6 100644 --- a/packages/mcp-core/src/api-client/schema.ts +++ b/packages/mcp-core/src/api-client/schema.ts @@ -902,8 +902,8 @@ export const ISSUE_STATUSES = [ "unresolved", ] as const; -/** Relation types the related issues endpoint supports (`RelationType`). */ -export const RELATED_ISSUE_TYPES = [ +/** Relation types that find related issues, filling the response's `data`. */ +export const ISSUE_RELATION_TYPES = [ "similar_stacktrace", "same_trace", "contributing", @@ -911,6 +911,15 @@ export const RELATED_ISSUE_TYPES = [ "same_supergroup", ] as const; +/** + * Relation types the related issues endpoint supports (`RelationType`). + * investigations fills the response's `investigations` instead of `data`. + */ +export const RELATED_ISSUE_TYPES = [ + ...ISSUE_RELATION_TYPES, + "investigations", +] as const; + /** Outcome of each requested relation type (`RelationTypeStatus`). */ export const RELATED_ISSUE_TYPE_STATUSES = [ "ok", @@ -926,6 +935,7 @@ export const RELATED_ISSUE_TYPE_STATUSES = [ * * Upstream source of truth in getsentry/sentry: * - `src/sentry/issues/related/types.py` (`RelatedIssuesResponse`) + * - `src/sentry/issues/related/investigations.py` * - `src/sentry/issues/endpoints/group_related.py` */ export const RelatedIssuesResponseSchema = z.object({ @@ -935,7 +945,7 @@ export const RelatedIssuesResponseSchema = z.object({ relations: z.array( z .object({ - type: z.enum(RELATED_ISSUE_TYPES), + type: z.enum(ISSUE_RELATION_TYPES), score: z.number().optional(), }) .passthrough(), @@ -958,6 +968,17 @@ export const RelatedIssuesResponseSchema = z.object({ .passthrough(), ), }), + // Seer investigations that linked the issue, from the investigations type. + // Missing from Sentry versions without that type. + investigations: z + .array( + z.object({ + investigation: z.object({ id: z.string(), title: z.string() }), + hypothesisStatement: z.string(), + reason: z.string().nullable(), + }), + ) + .default([]), }); export const FrameInterface = z diff --git a/packages/mcp-core/src/api-client/types.ts b/packages/mcp-core/src/api-client/types.ts index 505c8cd1f1..92553ecc41 100644 --- a/packages/mcp-core/src/api-client/types.ts +++ b/packages/mcp-core/src/api-client/types.ts @@ -81,6 +81,7 @@ import type { FlamegraphProfileSchema, FlamegraphSchema, GenericEventSchema, + ISSUE_RELATION_TYPES, IssueActivityListResponseSchema, IssueActivitySchema, IssueAlertRuleListSchema, @@ -256,6 +257,7 @@ export type StacktraceLink = z.infer; export type SourceMapDebug = z.infer; export type RelatedIssues = z.infer; export type RelatedIssueType = (typeof RELATED_ISSUE_TYPES)[number]; +export type IssueRelationType = (typeof ISSUE_RELATION_TYPES)[number]; export type EventAttachment = z.infer; export type Tag = z.infer; diff --git a/packages/mcp-core/src/internal/update-issue-side-quests.ts b/packages/mcp-core/src/internal/update-issue-side-quests.ts index 29c4d8256d..9d2488fe37 100644 --- a/packages/mcp-core/src/internal/update-issue-side-quests.ts +++ b/packages/mcp-core/src/internal/update-issue-side-quests.ts @@ -1,6 +1,6 @@ import { getActiveSpan } from "@sentry/core"; import { inlineCode } from "@sentry/toolkit-core/markdown"; -import type { RelatedIssueType, RelatedIssues } from "../api-client/types"; +import type { IssueRelationType, RelatedIssues } from "../api-client/types"; import { type SideQuest, type SideQuestCandidate, @@ -51,7 +51,7 @@ export const RELATED_ISSUES_OPEN_COUNT_ATTRIBUTE = /** Related issues to request per relation type. */ export const RELATED_ISSUES_LIMIT = 5; -const RELATION_LABELS: Record = { +const RELATION_LABELS: Record = { similar_stacktrace: "similar stack trace", same_trace: "same trace", contributing: "contributing", @@ -64,7 +64,7 @@ const RELATION_LABELS: Record = { * exist than the response holds. */ function isPartial({ data }: RelatedIssues): boolean { - const perType = new Map(); + const perType = new Map(); for (const { relations } of data) { for (const { type } of relations) { perType.set(type, (perType.get(type) ?? 0) + 1); diff --git a/packages/mcp-core/src/skillDefinitions.json b/packages/mcp-core/src/skillDefinitions.json index 4c48b44e07..25d0a52721 100644 --- a/packages/mcp-core/src/skillDefinitions.json +++ b/packages/mcp-core/src/skillDefinitions.json @@ -44,7 +44,7 @@ }, { "name": "find_related_issues", - "description": "Find Sentry issues related to an issue: likely duplicates with a similar stack trace or the same title in the same project, other errors in the same trace, issues Seer found to share a root cause, and the error issues behind a metric alert. Returns each related issue with its status and why it's related. Use it before resolving or ignoring an issue.", + "description": "Find Sentry issues related to an issue: likely duplicates with a similar stack trace or the same title in the same project, other errors in the same trace, issues Seer found to share a root cause, and the error issues behind a metric alert, plus the Seer investigations that linked it. Returns each related issue with its status and why it's related. Use it before resolving or ignoring an issue.", "requiredScopes": ["event:read"] }, { @@ -279,7 +279,7 @@ }, { "name": "find_related_issues", - "description": "Find Sentry issues related to an issue: likely duplicates with a similar stack trace or the same title in the same project, other errors in the same trace, issues Seer found to share a root cause, and the error issues behind a metric alert. Returns each related issue with its status and why it's related. Use it before resolving or ignoring an issue.", + "description": "Find Sentry issues related to an issue: likely duplicates with a similar stack trace or the same title in the same project, other errors in the same trace, issues Seer found to share a root cause, and the error issues behind a metric alert, plus the Seer investigations that linked it. Returns each related issue with its status and why it's related. Use it before resolving or ignoring an issue.", "requiredScopes": ["event:read"] }, { @@ -430,7 +430,7 @@ }, { "name": "find_related_issues", - "description": "Find Sentry issues related to an issue: likely duplicates with a similar stack trace or the same title in the same project, other errors in the same trace, issues Seer found to share a root cause, and the error issues behind a metric alert. Returns each related issue with its status and why it's related. Use it before resolving or ignoring an issue.", + "description": "Find Sentry issues related to an issue: likely duplicates with a similar stack trace or the same title in the same project, other errors in the same trace, issues Seer found to share a root cause, and the error issues behind a metric alert, plus the Seer investigations that linked it. Returns each related issue with its status and why it's related. Use it before resolving or ignoring an issue.", "requiredScopes": ["event:read"] }, { diff --git a/packages/mcp-core/src/toolDefinitions.json b/packages/mcp-core/src/toolDefinitions.json index 5d124006bb..28a9b68a91 100644 --- a/packages/mcp-core/src/toolDefinitions.json +++ b/packages/mcp-core/src/toolDefinitions.json @@ -3116,7 +3116,7 @@ { "name": "find_related_issues", "title": "Find Related Issues", - "description": "Find Sentry issues related to an issue: likely duplicates with a similar stack trace or the same title in the same project, other errors in the same trace, issues Seer found to share a root cause, and the error issues behind a metric alert. Returns each related issue with its status and why it's related. Use it before resolving or ignoring an issue.", + "description": "Find Sentry issues related to an issue: likely duplicates with a similar stack trace or the same title in the same project, other errors in the same trace, issues Seer found to share a root cause, and the error issues behind a metric alert, plus the Seer investigations that linked it. Returns each related issue with its status and why it's related. Use it before resolving or ignoring an issue.", "inputSchema": { "type": "object", "properties": { @@ -3147,7 +3147,7 @@ }, "types": { "default": null, - "description": "Relation types; all when omitted. similar_stacktrace: likely duplicates. same_trace: errors in the same trace. contributing: errors behind a metric issue. same_title: errors with the same title, last 14 days. same_supergroup: same root cause per Seer.", + "description": "All when omitted. similar_stacktrace: likely duplicates. same_trace: same trace. contributing: behind a metric issue. same_title: same title, last 14 days. same_supergroup: same Seer root cause. investigations: Seer investigations that linked this issue.", "anyOf": [ { "type": "array", @@ -3158,7 +3158,8 @@ "same_trace", "contributing", "same_title", - "same_supergroup" + "same_supergroup", + "investigations" ] } }, @@ -3309,6 +3310,31 @@ }, "description": "Issues matched by more relation types first." }, + "investigations": { + "type": "array", + "items": { + "type": "object", + "properties": { + "title": { + "type": "string" + }, + "url": { + "type": "string" + }, + "hypothesis": { + "type": "string", + "description": "The hypothesis whose evidence named this issue." + }, + "reason": { + "description": "Why Seer found this issue relevant.", + "type": ["string", "null"] + } + }, + "required": ["title", "url", "hypothesis", "reason"], + "additionalProperties": false + }, + "description": "Seer investigations that linked this issue, most recent first." + }, "relationTypes": { "type": "array", "items": { @@ -3321,7 +3347,8 @@ "same_trace", "contributing", "same_title", - "same_supergroup" + "same_supergroup", + "investigations" ] }, "status": { @@ -3395,6 +3422,7 @@ "organizationSlug", "issueId", "relatedIssues", + "investigations", "relationTypes", "notes", "suggestedActions" @@ -7518,6 +7546,23 @@ "additionalProperties": false } }, + "investigations": { + "type": "array", + "items": { + "type": "object", + "properties": { + "title": { + "type": "string" + }, + "url": { + "type": "string" + } + }, + "required": ["title", "url"], + "additionalProperties": false + }, + "description": "Seer investigations whose evidence pointed to this issue." + }, "unavailableTypes": { "type": "array", "items": { @@ -7527,13 +7572,14 @@ "same_trace", "contributing", "same_title", - "same_supergroup" + "same_supergroup", + "investigations" ] }, "description": "Relation types that failed, so some may be missing." } }, - "required": ["issues", "unavailableTypes"], + "required": ["issues", "investigations", "unavailableTypes"], "additionalProperties": false }, "event": { diff --git a/packages/mcp-core/src/tools/catalog/find-related-issues.test.ts b/packages/mcp-core/src/tools/catalog/find-related-issues.test.ts index 7a31fd7922..de4d585079 100644 --- a/packages/mcp-core/src/tools/catalog/find-related-issues.test.ts +++ b/packages/mcp-core/src/tools/catalog/find-related-issues.test.ts @@ -60,6 +60,7 @@ describe("find_related_issues", () => { ); expect(structuredContent).toMatchInlineSnapshot(` { + "investigations": [], "issueId": "CLOUDFLARE-MCP-41", "notes": [], "organizationSlug": "sentry-mcp-evals", @@ -196,6 +197,45 @@ describe("find_related_issues", () => { "contributing", "same_title", "same_supergroup", + "investigations", + ]); + }); + + it("returns the investigations that linked the issue, apart from related issues", async () => { + mswServer.use( + http.get(RELATED_URL, () => + HttpResponse.json({ + data: [], + investigations: [ + { + investigation: { id: "42", title: "Duplicate tool registration" }, + hypothesisStatement: + "The server registers its tools again on every restart.", + reason: "Its stack trace shows the second registration.", + }, + ], + meta: { types: [{ type: "investigations", status: "ok" }] }, + }), + ), + ); + + const result = await findRelatedIssues.handler( + { ...params, types: ["investigations"] }, + context, + ); + const structuredContent = getStructuredContent(result); + + expect(findRelatedIssuesOutputSchema.parse(structuredContent)).toEqual( + structuredContent, + ); + expect(structuredContent.relatedIssues).toEqual([]); + expect(structuredContent.investigations).toEqual([ + { + title: "Duplicate tool registration", + url: "https://sentry-mcp-evals.sentry.io/seer/investigations/42/", + hypothesis: "The server registers its tools again on every restart.", + reason: "Its stack trace shows the second registration.", + }, ]); }); @@ -413,6 +453,7 @@ describe("find_related_issues through the MCP server", () => { "contributing", "same_title", "same_supergroup", + "investigations", ]); expect(relatedRequest?.searchParams.get("limit")).toBe("10"); diff --git a/packages/mcp-core/src/tools/catalog/find-related-issues.ts b/packages/mcp-core/src/tools/catalog/find-related-issues.ts index caec2cf4a0..6ee03cc4d8 100644 --- a/packages/mcp-core/src/tools/catalog/find-related-issues.ts +++ b/packages/mcp-core/src/tools/catalog/find-related-issues.ts @@ -1,6 +1,7 @@ import { getActiveSpan } from "@sentry/core"; import { z } from "zod"; import { + ISSUE_RELATION_TYPES, RELATED_ISSUE_TYPE_STATUSES, RELATED_ISSUE_TYPES, } from "../../api-client/schema"; @@ -38,7 +39,7 @@ export const findRelatedIssuesOutputSchema = z.object({ relations: z .array( z.object({ - type: z.enum(RELATED_ISSUE_TYPES), + type: z.enum(ISSUE_RELATION_TYPES), score: z .number() .nullable() @@ -51,6 +52,21 @@ export const findRelatedIssuesOutputSchema = z.object({ }), ) .describe("Issues matched by more relation types first."), + investigations: z + .array( + z.object({ + title: z.string(), + url: z.string(), + hypothesis: z + .string() + .describe("The hypothesis whose evidence named this issue."), + reason: z + .string() + .nullable() + .describe("Why Seer found this issue relevant."), + }), + ) + .describe("Seer investigations that linked this issue, most recent first."), relationTypes: z .array( z.object({ @@ -103,7 +119,7 @@ export default defineTool({ skills: ["inspect", "triage", "seer"], requiredScopes: ["event:read"], description: - "Find Sentry issues related to an issue: likely duplicates with a similar stack trace or the same title in the same project, other errors in the same trace, issues Seer found to share a root cause, and the error issues behind a metric alert. Returns each related issue with its status and why it's related. Use it before resolving or ignoring an issue.", + "Find Sentry issues related to an issue: likely duplicates with a similar stack trace or the same title in the same project, other errors in the same trace, issues Seer found to share a root cause, and the error issues behind a metric alert, plus the Seer investigations that linked it. Returns each related issue with its status and why it's related. Use it before resolving or ignoring an issue.", inputSchema: { organizationSlug: ParamOrganizationSlug.optional(), regionUrl: ParamRegionUrl.nullable().default(null), @@ -114,7 +130,7 @@ export default defineTool({ .nullable() .default(null) .describe( - "Relation types; all when omitted. similar_stacktrace: likely duplicates. same_trace: errors in the same trace. contributing: errors behind a metric issue. same_title: errors with the same title, last 14 days. same_supergroup: same root cause per Seer.", + "All when omitted. similar_stacktrace: likely duplicates. same_trace: same trace. contributing: behind a metric issue. same_title: same title, last 14 days. same_supergroup: same Seer root cause. investigations: Seer investigations that linked this issue.", ), limit: z .number() @@ -210,6 +226,17 @@ export default defineTool({ organizationSlug: parsed.organizationSlug, issueId: parsed.issueId, relatedIssues, + investigations: related.investigations.map( + ({ investigation, hypothesisStatement, reason }) => ({ + title: investigation.title, + url: apiService.getInvestigationUrl( + parsed.organizationSlug, + investigation.id, + ), + hypothesis: hypothesisStatement, + reason, + }), + ), relationTypes: related.meta.types.map((meta) => ({ type: meta.type, status: meta.status, diff --git a/packages/mcp-core/src/tools/catalog/get-issue-details.structured.test.ts b/packages/mcp-core/src/tools/catalog/get-issue-details.structured.test.ts index f3a58ddcd9..6528791743 100644 --- a/packages/mcp-core/src/tools/catalog/get-issue-details.structured.test.ts +++ b/packages/mcp-core/src/tools/catalog/get-issue-details.structured.test.ts @@ -617,6 +617,7 @@ describe("get_issue_details structuredContent for a realistic error", () => { "usersImpacted": 41, }, "relatedIssues": { + "investigations": [], "issues": [ { "project": "CLOUDFLARE-MCP", diff --git a/packages/mcp-core/src/tools/catalog/get-issue-details.test.ts b/packages/mcp-core/src/tools/catalog/get-issue-details.test.ts index 3289277f28..a049a5e5df 100644 --- a/packages/mcp-core/src/tools/catalog/get-issue-details.test.ts +++ b/packages/mcp-core/src/tools/catalog/get-issue-details.test.ts @@ -2079,6 +2079,7 @@ describe("structuredContent", () => { "same_trace", "contributing", "same_supergroup", + "investigations", ]); expect(requests[0]?.searchParams.get("limit")).toBe("5"); // the latest event is the endpoint's default @@ -2100,6 +2101,7 @@ describe("structuredContent", () => { relations: ["same_trace"], }, ], + investigations: [], unavailableTypes: [], }); expect(payload.suggestedActions[0]).toEqual({ @@ -2139,6 +2141,7 @@ describe("structuredContent", () => { expect(payload.relatedIssues).toEqual({ issues: [], + investigations: [], unavailableTypes: [], }); expect( @@ -2252,10 +2255,11 @@ describe("structuredContent", () => { "same_trace", "contributing", "same_supergroup", + "investigations", ]); }); - it("lists same-supergroup issues", async () => { + it("lists same-supergroup issues and the investigations that linked this one", async () => { mockLatestEvent(); captureRelatedRequest(() => HttpResponse.json({ @@ -2265,6 +2269,13 @@ describe("structuredContent", () => { relations: [{ type: "same_supergroup" }], }, ], + investigations: [ + { + investigation: { id: "42", title: "Checkout outage" }, + hypothesisStatement: "A bad deploy broke the payment client.", + reason: null, + }, + ], meta: { types: [ { @@ -2272,16 +2283,24 @@ describe("structuredContent", () => { status: "ok", supergroup: { id: "17", title: "Payment client times out" }, }, + { type: "investigations", status: "ok" }, ], }, }), ); const result = await getIssueDetails.handler(params, experimentalContext); + const payload = parsePayload(result); - expect(parsePayload(result).relatedIssues?.issues).toMatchObject([ + expect(payload.relatedIssues?.issues).toMatchObject([ { shortId: "CLOUDFLARE-MCP-42", relations: ["same_supergroup"] }, ]); + expect(payload.relatedIssues?.investigations).toEqual([ + { + title: "Checkout outage", + url: "https://sentry-mcp-evals.sentry.io/seer/investigations/42/", + }, + ]); }); }); diff --git a/packages/mcp-core/src/tools/catalog/get-issue-details.ts b/packages/mcp-core/src/tools/catalog/get-issue-details.ts index 2d58eff8ff..40fe6ef2ac 100644 --- a/packages/mcp-core/src/tools/catalog/get-issue-details.ts +++ b/packages/mcp-core/src/tools/catalog/get-issue-details.ts @@ -1,7 +1,11 @@ import { z } from "zod"; import type { SentryApiService } from "../../api-client"; import { ApiClientError, ApiNotFoundError } from "../../api-client"; -import { ISSUE_STATUSES, RELATED_ISSUE_TYPES } from "../../api-client/schema"; +import { + ISSUE_RELATION_TYPES, + ISSUE_STATUSES, + RELATED_ISSUE_TYPES, +} from "../../api-client/schema"; import type { AutofixRunState, CommitterList, @@ -94,6 +98,7 @@ const ISSUE_DETAILS_RELATED_TYPES = [ "same_trace", "contributing", "same_supergroup", + "investigations", ] as const satisfies readonly RelatedIssueType[]; /** @@ -132,9 +137,12 @@ export const getIssueDetailsOutputSchema = z.object({ title: z.string(), status: z.enum(ISSUE_STATUSES).nullable(), project: z.string().nullable(), - relations: z.array(z.enum(RELATED_ISSUE_TYPES)), + relations: z.array(z.enum(ISSUE_RELATION_TYPES)), }), ), + investigations: z + .array(z.object({ title: z.string(), url: z.string() })) + .describe("Seer investigations whose evidence pointed to this issue."), unavailableTypes: z .array(z.enum(RELATED_ISSUE_TYPES)) .describe("Relation types that failed, so some may be missing."), @@ -259,14 +267,21 @@ function toIssueStatus( } /** - * The endpoint's top few related issues. Same-trace and same-supergroup issues can be in any - * project, so a project-scoped session drops the ones outside its project, as - * find_related_issues does. + * The endpoint's top few related issues and the investigations that linked this one. + * Same-trace and same-supergroup issues can be in any project, so a project-scoped session + * drops the ones outside its project, as find_related_issues does. */ -function buildRelatedIssues( - related: RelatedIssues, - projectSlug: string | null | undefined, -): NonNullable { +function buildRelatedIssues({ + related, + projectSlug, + organizationSlug, + apiService, +}: { + related: RelatedIssues; + projectSlug: string | null | undefined; + organizationSlug: string; + apiService: SentryApiService; +}): NonNullable { const inScope = projectSlug ? related.data.filter(({ issue }) => issue.project.slug === projectSlug) : related.data; @@ -280,6 +295,10 @@ function buildRelatedIssues( project: nonEmptyString(issue.project.name), relations: relations.map((relation) => relation.type), })), + investigations: related.investigations.map(({ investigation }) => ({ + title: investigation.title, + url: apiService.getInvestigationUrl(organizationSlug, investigation.id), + })), unavailableTypes: related.meta.types .filter((meta) => meta.status === "unavailable") .map((meta) => meta.type), @@ -346,7 +365,12 @@ function buildIssueDetailsPayload({ packageNames, }); const related = relatedIssues - ? buildRelatedIssues(relatedIssues, projectSlug) + ? buildRelatedIssues({ + related: relatedIssues, + projectSlug, + organizationSlug, + apiService, + }) : undefined; return { 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 b48d992c8b..2ba8b18bbf 100644 --- a/packages/mcp-core/src/tools/catalog/update-issue.test.ts +++ b/packages/mcp-core/src/tools/catalog/update-issue.test.ts @@ -2035,6 +2035,7 @@ describe("update_issue", () => { ); expect(requests).toHaveLength(1); + // Every type that finds issues; the quest doesn't read investigations. expect(requests[0]?.searchParams.getAll("type")).toEqual([ "similar_stacktrace", "same_trace", diff --git a/packages/mcp-core/src/tools/catalog/update-issue.ts b/packages/mcp-core/src/tools/catalog/update-issue.ts index f6f18a05c8..4d5a61cda6 100644 --- a/packages/mcp-core/src/tools/catalog/update-issue.ts +++ b/packages/mcp-core/src/tools/catalog/update-issue.ts @@ -1,5 +1,6 @@ import { z } from "zod"; import type { SentryApiService } from "../../api-client"; +import { ISSUE_RELATION_TYPES } from "../../api-client/schema"; import type { AssignedTo, Issue, @@ -921,6 +922,8 @@ async function tryGetRelatedIssues( return await apiService.getRelatedIssues({ organizationSlug, issueId, + // The side quest reads only the related issues, not investigations + types: ISSUE_RELATION_TYPES, limit: RELATED_ISSUES_LIMIT, }); } catch (error) { diff --git a/packages/mcp-core/src/utils/url-utils.test.ts b/packages/mcp-core/src/utils/url-utils.test.ts index bfd2a07422..f91a2fdf89 100644 --- a/packages/mcp-core/src/utils/url-utils.test.ts +++ b/packages/mcp-core/src/utils/url-utils.test.ts @@ -3,6 +3,7 @@ import { extractConversationIdFromSearchQuery, getAIConversationUrl, getEventsExplorerUrl, + getInvestigationUrl, getIssuesSearchUrl, getIssueUrl, getLogUrl, @@ -310,6 +311,20 @@ describe("url-utils", () => { }); }); + describe("getInvestigationUrl", () => { + it("links the investigation on the org subdomain for SaaS", () => { + expect(getInvestigationUrl("us.sentry.io", "myorg", "42")).toBe( + "https://myorg.sentry.io/seer/investigations/42/", + ); + }); + + it("links the investigation under the org path for self-hosted", () => { + expect(getInvestigationUrl("sentry.example.com", "myorg", "42")).toBe( + "https://sentry.example.com/organizations/myorg/seer/investigations/42/", + ); + }); + }); + describe("getLogUrl", () => { it("pins the log in the logs explorer for SaaS", () => { const result = getLogUrl("us.sentry.io", "myorg", "abc123"); diff --git a/packages/mcp-core/src/utils/url-utils.ts b/packages/mcp-core/src/utils/url-utils.ts index 3fb5c07031..bb48674896 100644 --- a/packages/mcp-core/src/utils/url-utils.ts +++ b/packages/mcp-core/src/utils/url-utils.ts @@ -588,6 +588,21 @@ export function getTraceUrl( ); } +/** A Seer investigation's page in the Sentry UI. */ +export function getInvestigationUrl( + host: string, + organizationSlug: string, + investigationId: string, + protocol: SentryProtocol = "https", +): string { + return getSentryWebBaseUrl( + host, + organizationSlug, + `/seer/investigations/${investigationId}/`, + protocol, + ); +} + export function getLogUrl( host: string, organizationSlug: string, diff --git a/packages/mcp-server-mocks/src/fixtures/related-issues.json b/packages/mcp-server-mocks/src/fixtures/related-issues.json index 48e1ba4445..5ff790c1ea 100644 --- a/packages/mcp-server-mocks/src/fixtures/related-issues.json +++ b/packages/mcp-server-mocks/src/fixtures/related-issues.json @@ -106,6 +106,7 @@ "relations": [{ "type": "same_trace" }] } ], + "investigations": [], "meta": { "types": [ { From 5b4b1104cfe8e6d08b27f9feda53bc1a51f4914e Mon Sep 17 00:00:00 2001 From: "sentry-junior[bot]" <264270552+sentry-junior[bot]@users.noreply.github.com> Date: Tue, 24 Nov 2026 22:06:41 +0000 Subject: [PATCH 2/4] ref(mcp): Keep investigations out of find_related_issues find_related_issues is for deciding whether to resolve or ignore an issue, and investigations don't help with that. It now asks only for the issue relation types and drops its investigations output. get_issue_details still asks for investigations and shows them. Co-Authored-By: Christina Long <60594860+Christinarlong@users.noreply.github.com> --- packages/mcp-core/src/skillDefinitions.json | 6 +- packages/mcp-core/src/toolDefinitions.json | 36 ++---------- .../tools/catalog/find-related-issues.test.ts | 43 +------------- .../src/tools/catalog/find-related-issues.ts | 58 ++++++------------- .../src/fixtures/related-issues.json | 1 - 5 files changed, 27 insertions(+), 117 deletions(-) diff --git a/packages/mcp-core/src/skillDefinitions.json b/packages/mcp-core/src/skillDefinitions.json index 25d0a52721..4c48b44e07 100644 --- a/packages/mcp-core/src/skillDefinitions.json +++ b/packages/mcp-core/src/skillDefinitions.json @@ -44,7 +44,7 @@ }, { "name": "find_related_issues", - "description": "Find Sentry issues related to an issue: likely duplicates with a similar stack trace or the same title in the same project, other errors in the same trace, issues Seer found to share a root cause, and the error issues behind a metric alert, plus the Seer investigations that linked it. Returns each related issue with its status and why it's related. Use it before resolving or ignoring an issue.", + "description": "Find Sentry issues related to an issue: likely duplicates with a similar stack trace or the same title in the same project, other errors in the same trace, issues Seer found to share a root cause, and the error issues behind a metric alert. Returns each related issue with its status and why it's related. Use it before resolving or ignoring an issue.", "requiredScopes": ["event:read"] }, { @@ -279,7 +279,7 @@ }, { "name": "find_related_issues", - "description": "Find Sentry issues related to an issue: likely duplicates with a similar stack trace or the same title in the same project, other errors in the same trace, issues Seer found to share a root cause, and the error issues behind a metric alert, plus the Seer investigations that linked it. Returns each related issue with its status and why it's related. Use it before resolving or ignoring an issue.", + "description": "Find Sentry issues related to an issue: likely duplicates with a similar stack trace or the same title in the same project, other errors in the same trace, issues Seer found to share a root cause, and the error issues behind a metric alert. Returns each related issue with its status and why it's related. Use it before resolving or ignoring an issue.", "requiredScopes": ["event:read"] }, { @@ -430,7 +430,7 @@ }, { "name": "find_related_issues", - "description": "Find Sentry issues related to an issue: likely duplicates with a similar stack trace or the same title in the same project, other errors in the same trace, issues Seer found to share a root cause, and the error issues behind a metric alert, plus the Seer investigations that linked it. Returns each related issue with its status and why it's related. Use it before resolving or ignoring an issue.", + "description": "Find Sentry issues related to an issue: likely duplicates with a similar stack trace or the same title in the same project, other errors in the same trace, issues Seer found to share a root cause, and the error issues behind a metric alert. Returns each related issue with its status and why it's related. Use it before resolving or ignoring an issue.", "requiredScopes": ["event:read"] }, { diff --git a/packages/mcp-core/src/toolDefinitions.json b/packages/mcp-core/src/toolDefinitions.json index 28a9b68a91..4ee41f6eb4 100644 --- a/packages/mcp-core/src/toolDefinitions.json +++ b/packages/mcp-core/src/toolDefinitions.json @@ -3116,7 +3116,7 @@ { "name": "find_related_issues", "title": "Find Related Issues", - "description": "Find Sentry issues related to an issue: likely duplicates with a similar stack trace or the same title in the same project, other errors in the same trace, issues Seer found to share a root cause, and the error issues behind a metric alert, plus the Seer investigations that linked it. Returns each related issue with its status and why it's related. Use it before resolving or ignoring an issue.", + "description": "Find Sentry issues related to an issue: likely duplicates with a similar stack trace or the same title in the same project, other errors in the same trace, issues Seer found to share a root cause, and the error issues behind a metric alert. Returns each related issue with its status and why it's related. Use it before resolving or ignoring an issue.", "inputSchema": { "type": "object", "properties": { @@ -3147,7 +3147,7 @@ }, "types": { "default": null, - "description": "All when omitted. similar_stacktrace: likely duplicates. same_trace: same trace. contributing: behind a metric issue. same_title: same title, last 14 days. same_supergroup: same Seer root cause. investigations: Seer investigations that linked this issue.", + "description": "Relation types; all when omitted. similar_stacktrace: likely duplicates. same_trace: errors in the same trace. contributing: errors behind a metric issue. same_title: errors with the same title, last 14 days. same_supergroup: same root cause per Seer.", "anyOf": [ { "type": "array", @@ -3158,8 +3158,7 @@ "same_trace", "contributing", "same_title", - "same_supergroup", - "investigations" + "same_supergroup" ] } }, @@ -3310,31 +3309,6 @@ }, "description": "Issues matched by more relation types first." }, - "investigations": { - "type": "array", - "items": { - "type": "object", - "properties": { - "title": { - "type": "string" - }, - "url": { - "type": "string" - }, - "hypothesis": { - "type": "string", - "description": "The hypothesis whose evidence named this issue." - }, - "reason": { - "description": "Why Seer found this issue relevant.", - "type": ["string", "null"] - } - }, - "required": ["title", "url", "hypothesis", "reason"], - "additionalProperties": false - }, - "description": "Seer investigations that linked this issue, most recent first." - }, "relationTypes": { "type": "array", "items": { @@ -3347,8 +3321,7 @@ "same_trace", "contributing", "same_title", - "same_supergroup", - "investigations" + "same_supergroup" ] }, "status": { @@ -3422,7 +3395,6 @@ "organizationSlug", "issueId", "relatedIssues", - "investigations", "relationTypes", "notes", "suggestedActions" diff --git a/packages/mcp-core/src/tools/catalog/find-related-issues.test.ts b/packages/mcp-core/src/tools/catalog/find-related-issues.test.ts index de4d585079..232759ac3a 100644 --- a/packages/mcp-core/src/tools/catalog/find-related-issues.test.ts +++ b/packages/mcp-core/src/tools/catalog/find-related-issues.test.ts @@ -60,7 +60,6 @@ describe("find_related_issues", () => { ); expect(structuredContent).toMatchInlineSnapshot(` { - "investigations": [], "issueId": "CLOUDFLARE-MCP-41", "notes": [], "organizationSlug": "sentry-mcp-evals", @@ -180,7 +179,7 @@ describe("find_related_issues", () => { // Left to its default, Sentry would return every type it has, including // ones added after this release, which the response enum rejects. - it("names every known type when given an empty list", async () => { + it("names every issue relation type when given an empty list", async () => { let requested: URLSearchParams | undefined; mswServer.use( http.get(RELATED_URL, ({ request }) => { @@ -197,45 +196,6 @@ describe("find_related_issues", () => { "contributing", "same_title", "same_supergroup", - "investigations", - ]); - }); - - it("returns the investigations that linked the issue, apart from related issues", async () => { - mswServer.use( - http.get(RELATED_URL, () => - HttpResponse.json({ - data: [], - investigations: [ - { - investigation: { id: "42", title: "Duplicate tool registration" }, - hypothesisStatement: - "The server registers its tools again on every restart.", - reason: "Its stack trace shows the second registration.", - }, - ], - meta: { types: [{ type: "investigations", status: "ok" }] }, - }), - ), - ); - - const result = await findRelatedIssues.handler( - { ...params, types: ["investigations"] }, - context, - ); - const structuredContent = getStructuredContent(result); - - expect(findRelatedIssuesOutputSchema.parse(structuredContent)).toEqual( - structuredContent, - ); - expect(structuredContent.relatedIssues).toEqual([]); - expect(structuredContent.investigations).toEqual([ - { - title: "Duplicate tool registration", - url: "https://sentry-mcp-evals.sentry.io/seer/investigations/42/", - hypothesis: "The server registers its tools again on every restart.", - reason: "Its stack trace shows the second registration.", - }, ]); }); @@ -453,7 +413,6 @@ describe("find_related_issues through the MCP server", () => { "contributing", "same_title", "same_supergroup", - "investigations", ]); expect(relatedRequest?.searchParams.get("limit")).toBe("10"); diff --git a/packages/mcp-core/src/tools/catalog/find-related-issues.ts b/packages/mcp-core/src/tools/catalog/find-related-issues.ts index 6ee03cc4d8..fad95af6b4 100644 --- a/packages/mcp-core/src/tools/catalog/find-related-issues.ts +++ b/packages/mcp-core/src/tools/catalog/find-related-issues.ts @@ -3,7 +3,6 @@ import { z } from "zod"; import { ISSUE_RELATION_TYPES, RELATED_ISSUE_TYPE_STATUSES, - RELATED_ISSUE_TYPES, } from "../../api-client/schema"; import type { RelatedIssues } from "../../api-client/types"; import { apiServiceFromContext } from "../../internal/tool-helpers/api"; @@ -52,25 +51,10 @@ export const findRelatedIssuesOutputSchema = z.object({ }), ) .describe("Issues matched by more relation types first."), - investigations: z - .array( - z.object({ - title: z.string(), - url: z.string(), - hypothesis: z - .string() - .describe("The hypothesis whose evidence named this issue."), - reason: z - .string() - .nullable() - .describe("Why Seer found this issue relevant."), - }), - ) - .describe("Seer investigations that linked this issue, most recent first."), relationTypes: z .array( z.object({ - type: z.enum(RELATED_ISSUE_TYPES), + type: z.enum(ISSUE_RELATION_TYPES), status: z .enum(RELATED_ISSUE_TYPE_STATUSES) .describe( @@ -119,18 +103,18 @@ export default defineTool({ skills: ["inspect", "triage", "seer"], requiredScopes: ["event:read"], description: - "Find Sentry issues related to an issue: likely duplicates with a similar stack trace or the same title in the same project, other errors in the same trace, issues Seer found to share a root cause, and the error issues behind a metric alert, plus the Seer investigations that linked it. Returns each related issue with its status and why it's related. Use it before resolving or ignoring an issue.", + "Find Sentry issues related to an issue: likely duplicates with a similar stack trace or the same title in the same project, other errors in the same trace, issues Seer found to share a root cause, and the error issues behind a metric alert. Returns each related issue with its status and why it's related. Use it before resolving or ignoring an issue.", inputSchema: { organizationSlug: ParamOrganizationSlug.optional(), regionUrl: ParamRegionUrl.nullable().default(null), issueId: ParamIssueShortId.optional(), issueUrl: ParamIssueUrl.optional(), types: z - .array(z.enum(RELATED_ISSUE_TYPES)) + .array(z.enum(ISSUE_RELATION_TYPES)) .nullable() .default(null) .describe( - "All when omitted. similar_stacktrace: likely duplicates. same_trace: same trace. contributing: behind a metric issue. same_title: same title, last 14 days. same_supergroup: same Seer root cause. investigations: Seer investigations that linked this issue.", + "Relation types; all when omitted. similar_stacktrace: likely duplicates. same_trace: errors in the same trace. contributing: errors behind a metric issue. same_title: errors with the same title, last 14 days. same_supergroup: same root cause per Seer.", ), limit: z .number() @@ -173,7 +157,8 @@ export default defineTool({ const related = await apiService.getRelatedIssues({ organizationSlug: parsed.organizationSlug, issueId: parsed.issueId, - types: params.types ?? undefined, + // Not investigations: get_issue_details shows those + types: params.types?.length ? params.types : ISSUE_RELATION_TYPES, limit: params.limit, }); @@ -226,25 +211,20 @@ export default defineTool({ organizationSlug: parsed.organizationSlug, issueId: parsed.issueId, relatedIssues, - investigations: related.investigations.map( - ({ investigation, hypothesisStatement, reason }) => ({ - title: investigation.title, - url: apiService.getInvestigationUrl( - parsed.organizationSlug, - investigation.id, - ), - hypothesis: hypothesisStatement, - reason, - }), + relationTypes: related.meta.types.flatMap((meta) => + meta.type === "investigations" + ? [] + : [ + { + type: meta.type, + status: meta.status, + detail: meta.detail ?? null, + traceId: meta.traceId ?? null, + title: meta.title ?? null, + supergroup: meta.supergroup?.title ?? null, + }, + ], ), - relationTypes: related.meta.types.map((meta) => ({ - type: meta.type, - status: meta.status, - detail: meta.detail ?? null, - traceId: meta.traceId ?? null, - title: meta.title ?? null, - supergroup: meta.supergroup?.title ?? null, - })), notes, suggestedActions: inspectFirst ? [inspectFirst] : [], }); diff --git a/packages/mcp-server-mocks/src/fixtures/related-issues.json b/packages/mcp-server-mocks/src/fixtures/related-issues.json index 5ff790c1ea..48e1ba4445 100644 --- a/packages/mcp-server-mocks/src/fixtures/related-issues.json +++ b/packages/mcp-server-mocks/src/fixtures/related-issues.json @@ -106,7 +106,6 @@ "relations": [{ "type": "same_trace" }] } ], - "investigations": [], "meta": { "types": [ { From e9e9d106fb09f83d76d0f23101c070d1dd7da3c9 Mon Sep 17 00:00:00 2001 From: "sentry-junior[bot]" <264270552+sentry-junior[bot]@users.noreply.github.com> Date: Tue, 24 Nov 2026 23:25:57 +0000 Subject: [PATCH 3/4] feat(mcp): Return why an investigation linked the issue get_issue_details now returns each linked investigation's reason, so an agent can see why Seer tied the investigation to this issue without opening it. --- packages/mcp-core/src/toolDefinitions.json | 6 +++++- .../src/tools/catalog/get-issue-details.test.ts | 3 ++- .../src/tools/catalog/get-issue-details.ts | 14 ++++++++++++-- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/packages/mcp-core/src/toolDefinitions.json b/packages/mcp-core/src/toolDefinitions.json index 4ee41f6eb4..ac08b7ce98 100644 --- a/packages/mcp-core/src/toolDefinitions.json +++ b/packages/mcp-core/src/toolDefinitions.json @@ -7528,9 +7528,13 @@ }, "url": { "type": "string" + }, + "reason": { + "description": "Why Seer found this issue relevant.", + "type": ["string", "null"] } }, - "required": ["title", "url"], + "required": ["title", "url", "reason"], "additionalProperties": false }, "description": "Seer investigations whose evidence pointed to this issue." diff --git a/packages/mcp-core/src/tools/catalog/get-issue-details.test.ts b/packages/mcp-core/src/tools/catalog/get-issue-details.test.ts index a049a5e5df..e3cf54e071 100644 --- a/packages/mcp-core/src/tools/catalog/get-issue-details.test.ts +++ b/packages/mcp-core/src/tools/catalog/get-issue-details.test.ts @@ -2273,7 +2273,7 @@ describe("structuredContent", () => { { investigation: { id: "42", title: "Checkout outage" }, hypothesisStatement: "A bad deploy broke the payment client.", - reason: null, + reason: "Its timeouts start with the deploy.", }, ], meta: { @@ -2299,6 +2299,7 @@ describe("structuredContent", () => { { title: "Checkout outage", url: "https://sentry-mcp-evals.sentry.io/seer/investigations/42/", + reason: "Its timeouts start with the deploy.", }, ]); }); diff --git a/packages/mcp-core/src/tools/catalog/get-issue-details.ts b/packages/mcp-core/src/tools/catalog/get-issue-details.ts index 40fe6ef2ac..ebc75635b5 100644 --- a/packages/mcp-core/src/tools/catalog/get-issue-details.ts +++ b/packages/mcp-core/src/tools/catalog/get-issue-details.ts @@ -141,7 +141,16 @@ export const getIssueDetailsOutputSchema = z.object({ }), ), investigations: z - .array(z.object({ title: z.string(), url: z.string() })) + .array( + z.object({ + title: z.string(), + url: z.string(), + reason: z + .string() + .nullable() + .describe("Why Seer found this issue relevant."), + }), + ) .describe("Seer investigations whose evidence pointed to this issue."), unavailableTypes: z .array(z.enum(RELATED_ISSUE_TYPES)) @@ -295,9 +304,10 @@ function buildRelatedIssues({ project: nonEmptyString(issue.project.name), relations: relations.map((relation) => relation.type), })), - investigations: related.investigations.map(({ investigation }) => ({ + investigations: related.investigations.map(({ investigation, reason }) => ({ title: investigation.title, url: apiService.getInvestigationUrl(organizationSlug, investigation.id), + reason, })), unavailableTypes: related.meta.types .filter((meta) => meta.status === "unavailable") From 611b5538b38aed4272112420db2db1be23881260 Mon Sep 17 00:00:00 2001 From: "sentry-junior[bot]" <264270552+sentry-junior[bot]@users.noreply.github.com> Date: Tue, 24 Nov 2026 23:27:54 +0000 Subject: [PATCH 4/4] ref(mcp): Clarify related issue type comments Co-Authored-By: Christina Long <60594860+Christinarlong@users.noreply.github.com> --- packages/mcp-core/src/api-client/schema.ts | 1 - packages/mcp-core/src/tools/catalog/find-related-issues.ts | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/mcp-core/src/api-client/schema.ts b/packages/mcp-core/src/api-client/schema.ts index 5ac589aeb6..1bdd311272 100644 --- a/packages/mcp-core/src/api-client/schema.ts +++ b/packages/mcp-core/src/api-client/schema.ts @@ -935,7 +935,6 @@ export const RELATED_ISSUE_TYPE_STATUSES = [ * * Upstream source of truth in getsentry/sentry: * - `src/sentry/issues/related/types.py` (`RelatedIssuesResponse`) - * - `src/sentry/issues/related/investigations.py` * - `src/sentry/issues/endpoints/group_related.py` */ export const RelatedIssuesResponseSchema = z.object({ diff --git a/packages/mcp-core/src/tools/catalog/find-related-issues.ts b/packages/mcp-core/src/tools/catalog/find-related-issues.ts index fad95af6b4..d9985030c5 100644 --- a/packages/mcp-core/src/tools/catalog/find-related-issues.ts +++ b/packages/mcp-core/src/tools/catalog/find-related-issues.ts @@ -211,6 +211,7 @@ export default defineTool({ organizationSlug: parsed.organizationSlug, issueId: parsed.issueId, relatedIssues, + // investigations is never requested here; this only narrows the shared enum relationTypes: related.meta.types.flatMap((meta) => meta.type === "investigations" ? []