Skip to content
Open
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
5 changes: 2 additions & 3 deletions docs/contributing/search-events-api-patterns.md
Original file line number Diff line number Diff line change
Expand Up @@ -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**:
Expand Down Expand Up @@ -476,7 +476,6 @@ const tagsResponse = await apiService.listTags({
dataset: "events",
statsPeriod: "14d",
useCache: true,
useFlagsBackend: true,
});

// For spans/logs datasets
Expand Down
6 changes: 0 additions & 6 deletions packages/mcp-core/src/api-client/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand All @@ -2921,7 +2920,6 @@ export class SentryApiService {
start,
end,
useCache,
useFlagsBackend,
}: {
organizationSlug: string;
dataset?: "events" | "errors" | "replays" | "search_issues";
Expand All @@ -2930,7 +2928,6 @@ export class SentryApiService {
start?: string;
end?: string;
useCache?: boolean;
useFlagsBackend?: boolean;
},
opts?: RequestOptions,
): Promise<TagList> {
Expand All @@ -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()
Expand Down
30 changes: 30 additions & 0 deletions packages/mcp-core/src/tools/support/search-events/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -827,7 +827,6 @@ export async function fetchCustomAttributes(
start: attributeTimeParams.start,
end: attributeTimeParams.end,
useCache: true,
useFlagsBackend: true,
});

for (const tag of tagsResponse) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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/,
),
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ export function createIssueEventFieldsTool(options: {
project: projectId,
statsPeriod: "14d",
useCache: true,
useFlagsBackend: true,
});

// Build a map of available tags
Expand Down
Loading