From 43ea63df6b163e37f6e0c712ee864186742396cd Mon Sep 17 00:00:00 2001 From: "sentry-junior[bot]" <264270552+sentry-junior[bot]@users.noreply.github.com> Date: Sun, 15 Nov 2026 07:58:33 +0000 Subject: [PATCH] fix(mcp): Point get_sentry_resource at search_errors for errors list URLs Explore > Errors (Discover) list URLs such as /explore/errors/homepage/ fell through to the generic 'Could not determine resource type' error, so agents had to rebuild the page's project and time scope by hand. Recognize these pages, point at search_errors, and list the page's project, environment, time and query filters in the guidance. --- .../get-sentry-resource-resolve.test.ts | 22 ++++++++++++++ .../src/tools/catalog/get-sentry-resource.ts | 30 +++++++++++++++++-- 2 files changed, 49 insertions(+), 3 deletions(-) diff --git a/packages/mcp-core/src/tools/catalog/get-sentry-resource-resolve.test.ts b/packages/mcp-core/src/tools/catalog/get-sentry-resource-resolve.test.ts index fb51d0238..23670e053 100644 --- a/packages/mcp-core/src/tools/catalog/get-sentry-resource-resolve.test.ts +++ b/packages/mcp-core/src/tools/catalog/get-sentry-resource-resolve.test.ts @@ -451,10 +451,32 @@ describe("resolveResourceParams", () => { "https://sentry.io/api/0/projects/my-org/my-project/events/abc123/", "This is a Sentry API URL", ], + [ + "https://my-org.sentry.io/explore/errors/homepage/?dataset=errors&field=title&sort=-timestamp&referrer=weekly_report", + "Use `search_errors` to query error events", + ], + [ + "https://my-org.sentry.io/explore/discover/results/?dataset=errors", + "Use `search_errors` to query error events", + ], + [ + "https://sentry.io/organizations/my-org/discover/homepage/", + "Use `search_errors` to query error events", + ], ])("explains unsupported URL %s", (url, message) => { expect(() => resolveResourceParams({ url })).toThrow(message); }); + it("lists the page filters of an unsupported list URL", () => { + expect(() => + resolveResourceParams({ + url: "https://my-org.sentry.io/explore/errors/homepage/?dataset=errors&project=1&project=2&environment=prod&statsPeriod=7d&query=level%3Aerror&referrer=weekly_report", + }), + ).toThrow( + "The URL is scoped to: project=1, project=2, environment=prod, statsPeriod=7d, query=level:error.", + ); + }); + it("throws for unknown URL path (settings)", () => { expect(() => resolveResourceParams({ diff --git a/packages/mcp-core/src/tools/catalog/get-sentry-resource.ts b/packages/mcp-core/src/tools/catalog/get-sentry-resource.ts index 1f78bcfa3..e67de5502 100644 --- a/packages/mcp-core/src/tools/catalog/get-sentry-resource.ts +++ b/packages/mcp-core/src/tools/catalog/get-sentry-resource.ts @@ -111,18 +111,42 @@ const UNSUPPORTED_URL_GUIDANCE: Array<[RegExp, string]> = [ /(^|\/)(explore\/traces|performance|traces)\/?$/, "This is a trace search URL. Use `search_traces` to query traces, or pass a URL for one trace.", ], + [ + /(^|\/)(explore\/(errors|errors-v2|discover)|discover)(\/(homepage|results|queries))?\/?$/, + "This is an errors search URL. Use `search_errors` to query error events, or pass a URL for one issue or event.", + ], +]; + +// Page filters that a search tool needs to reproduce a list URL's scope. +const URL_SCOPE_PARAMS = [ + "project", + "environment", + "statsPeriod", + "start", + "end", + "query", ]; function getUnsupportedUrlGuidance(url: string): string | undefined { - let pathname: string; + let parsedUrl: URL; try { - pathname = new URL(url).pathname.replace(/^\/+|\/+$/g, ""); + parsedUrl = new URL(url); } catch { return undefined; } - return UNSUPPORTED_URL_GUIDANCE.find(([pattern]) => + const pathname = parsedUrl.pathname.replace(/^\/+|\/+$/g, ""); + const guidance = UNSUPPORTED_URL_GUIDANCE.find(([pattern]) => pattern.test(pathname), )?.[1]; + if (!guidance) { + return undefined; + } + const scope = URL_SCOPE_PARAMS.flatMap((name) => + parsedUrl.searchParams.getAll(name).map((value) => `${name}=${value}`), + ); + return scope.length > 0 + ? `${guidance} The URL is scoped to: ${scope.join(", ")}.` + : guidance; } export function resolveResourceParams(params: {