From 16abca901fef9776b195c3acb7dc5e9938c42001 Mon Sep 17 00:00:00 2001 From: "sentry-junior[bot]" <264270552+sentry-junior[bot]@users.noreply.github.com> Date: Wed, 11 Nov 2026 12:32:59 +0000 Subject: [PATCH] fix(search-events): List tags, not feature flags, for error and issue event searches The issue event and errors-dataset field lookups called the org tags endpoint with useFlagsBackend=1. Sentry then reads the flags backend and returns feature flag keys instead of tags (organization_tags.py), so custom tags such as sessionId never reached the embedded agent. The agent, told that unlisted tags make queries fail, removed valid filters from the query. Drop the flag from both lookups, remove the now-unused listTags option, and fix the docs that recommended it. --- .../search-events-api-patterns.md | 5 +- packages/mcp-core/src/api-client/client.ts | 6 --- .../tools/support/search-events/utils.test.ts | 30 ++++++++++++ .../src/tools/support/search-events/utils.ts | 1 - .../support/search-issue-events/utils.test.ts | 48 +++++++++++++++++++ .../support/search-issue-events/utils.ts | 1 - 6 files changed, 80 insertions(+), 11 deletions(-) create mode 100644 packages/mcp-core/src/tools/support/search-issue-events/utils.test.ts diff --git a/docs/contributing/search-events-api-patterns.md b/docs/contributing/search-events-api-patterns.md index 85d6096b2..872a8902d 100644 --- a/docs/contributing/search-events-api-patterns.md +++ b/docs/contributing/search-events-api-patterns.md @@ -386,12 +386,12 @@ Before translating queries, the tool fetches available attributes/fields for the - `project`: Numeric project ID (optional) - `statsPeriod`: Time range (e.g., `24h`) - `useCache`: Set to `1` for performance -- `useFlagsBackend`: Set to `1` for latest features +- Do not send `useFlagsBackend=1`: it makes the endpoint return feature flag keys instead of tags **Example**: ``` -https://us.sentry.io/api/0/organizations/sentry/tags/?dataset=events&project=4509062593708032&statsPeriod=24h&useCache=1&useFlagsBackend=1 +https://us.sentry.io/api/0/organizations/sentry/tags/?dataset=events&project=4509062593708032&statsPeriod=24h&useCache=1 ``` **Response Format**: @@ -476,7 +476,6 @@ const tagsResponse = await apiService.listTags({ dataset: "events", statsPeriod: "14d", useCache: true, - useFlagsBackend: true, }); // For spans/logs datasets diff --git a/packages/mcp-core/src/api-client/client.ts b/packages/mcp-core/src/api-client/client.ts index c90f0fde1..670b110cf 100644 --- a/packages/mcp-core/src/api-client/client.ts +++ b/packages/mcp-core/src/api-client/client.ts @@ -2896,7 +2896,6 @@ export class SentryApiService { * @param params.project Numeric project ID to filter tags * @param params.statsPeriod Time range for tag statistics (e.g., "24h", "7d") * @param params.useCache Whether to use cached results - * @param params.useFlagsBackend Whether to use flags backend features * @param opts Request options * @returns Array of available tags with metadata * @@ -2921,7 +2920,6 @@ export class SentryApiService { start, end, useCache, - useFlagsBackend, }: { organizationSlug: string; dataset?: "events" | "errors" | "replays" | "search_issues"; @@ -2930,7 +2928,6 @@ export class SentryApiService { start?: string; end?: string; useCache?: boolean; - useFlagsBackend?: boolean; }, opts?: RequestOptions, ): Promise { @@ -2945,9 +2942,6 @@ export class SentryApiService { if (useCache !== undefined) { searchQuery.set("useCache", useCache ? "1" : "0"); } - if (useFlagsBackend !== undefined) { - searchQuery.set("useFlagsBackend", useFlagsBackend ? "1" : "0"); - } const body = await this.requestJSON( searchQuery.toString() diff --git a/packages/mcp-core/src/tools/support/search-events/utils.test.ts b/packages/mcp-core/src/tools/support/search-events/utils.test.ts index 426628738..254c86699 100644 --- a/packages/mcp-core/src/tools/support/search-events/utils.test.ts +++ b/packages/mcp-core/src/tools/support/search-events/utils.test.ts @@ -781,6 +781,36 @@ describe("fetchCustomAttributes", () => { mswServer.resetHandlers(); }); + it("lists tags, not feature flags, for the errors dataset", async () => { + const requests: URLSearchParams[] = []; + mswServer.use( + http.get( + "https://sentry.io/api/0/organizations/test-org/tags/", + ({ request }) => { + const params = new URL(request.url).searchParams; + requests.push(params); + if (params.get("useFlagsBackend") === "1") { + return HttpResponse.json([]); + } + return HttpResponse.json([ + { key: "sessionId", name: "sessionId", totalValues: 12 }, + ]); + }, + ), + ); + + const { attributes } = await fetchCustomAttributes( + apiService, + "test-org", + "errors", + "123", + ); + + expect(requests).toHaveLength(1); + expect(requests[0].has("useFlagsBackend")).toBe(false); + expect(Object.keys(attributes)).toEqual(["sessionId"]); + }); + describe("403 permission errors", () => { it("should throw 403 'no multi-project access' error as UserInputError", async () => { // Mock the API to return a 403 error like in the Sentry issue diff --git a/packages/mcp-core/src/tools/support/search-events/utils.ts b/packages/mcp-core/src/tools/support/search-events/utils.ts index 5226b68d7..28e36028d 100644 --- a/packages/mcp-core/src/tools/support/search-events/utils.ts +++ b/packages/mcp-core/src/tools/support/search-events/utils.ts @@ -827,7 +827,6 @@ export async function fetchCustomAttributes( start: attributeTimeParams.start, end: attributeTimeParams.end, useCache: true, - useFlagsBackend: true, }); for (const tag of tagsResponse) { diff --git a/packages/mcp-core/src/tools/support/search-issue-events/utils.test.ts b/packages/mcp-core/src/tools/support/search-issue-events/utils.test.ts new file mode 100644 index 000000000..5608d8e58 --- /dev/null +++ b/packages/mcp-core/src/tools/support/search-issue-events/utils.test.ts @@ -0,0 +1,48 @@ +import { mswServer } from "@sentry/mcp-server-mocks"; +import { HttpResponse, http } from "msw"; +import { describe, expect, it } from "vitest"; +import { SentryApiService } from "../../../api-client"; +import { createIssueEventFieldsTool } from "./utils"; + +describe("createIssueEventFieldsTool", () => { + it("lists the project's custom tags, not feature flags", async () => { + const requests: URLSearchParams[] = []; + mswServer.use( + http.get( + "https://sentry.io/api/0/organizations/test-org/tags/", + ({ request }) => { + const params = new URL(request.url).searchParams; + requests.push(params); + // useFlagsBackend=1 makes Sentry return feature flag keys instead + // of tags, which left custom tags such as sessionId out of the list. + if (params.get("useFlagsBackend") === "1") { + return HttpResponse.json([]); + } + return HttpResponse.json([ + { key: "sessionId", name: "sessionId", totalValues: 12 }, + ]); + }, + ), + ); + + const tool = createIssueEventFieldsTool({ + apiService: new SentryApiService({ accessToken: "test-token" }), + organizationSlug: "test-org", + projectId: "123", + }); + const output = await tool.execute!( + {}, + { toolCallId: "issue-event-fields-test", messages: [] }, + ); + + expect(requests).toHaveLength(1); + expect(requests[0].get("dataset")).toBe("events"); + expect(requests[0].get("project")).toBe("123"); + expect(requests[0].has("useFlagsBackend")).toBe(false); + expect(output).toEqual({ + result: expect.stringMatching( + /Project-Specific Tags \(from API\):\n- sessionId: sessionId\n/, + ), + }); + }); +}); diff --git a/packages/mcp-core/src/tools/support/search-issue-events/utils.ts b/packages/mcp-core/src/tools/support/search-issue-events/utils.ts index 6c3e4fa5b..2e3153851 100644 --- a/packages/mcp-core/src/tools/support/search-issue-events/utils.ts +++ b/packages/mcp-core/src/tools/support/search-issue-events/utils.ts @@ -37,7 +37,6 @@ export function createIssueEventFieldsTool(options: { project: projectId, statsPeriod: "14d", useCache: true, - useFlagsBackend: true, }); // Build a map of available tags