From 2423a59e828d98ac259d45d00a61e7731c6a3d02 Mon Sep 17 00:00:00 2001 From: "sentry-junior[bot]" <264270552+sentry-junior[bot]@users.noreply.github.com> Date: Fri, 13 Nov 2026 16:24:06 +0000 Subject: [PATCH] fix(search-events): Say when Sentry skipped validateSearch Sentry's events/validate endpoint only checks RPC datasets. For errors it returns valid with a "not compatible" dataset note and checks nothing, but the embedded agent's validateSearch tool reported "Search validation passed." The agent then trusted queries with invented project: filters or unsupported functions such as latest(id), and the real /events/ call returned 400. Report the skip, and name what went unchecked. Also tell the agent that service, app, and host names and issue short IDs are not projects, and that a project scope from the request is already applied. Refs #2173 Co-Authored-By: Claude --- .../src/tools/support/search-events/config.ts | 1 + .../tools/support/search-events/utils.test.ts | 52 +++++++++++++++++++ .../src/tools/support/search-events/utils.ts | 11 ++++ 3 files changed, 64 insertions(+) diff --git a/packages/mcp-core/src/tools/support/search-events/config.ts b/packages/mcp-core/src/tools/support/search-events/config.ts index 92d27aa42..43750e2ac 100644 --- a/packages/mcp-core/src/tools/support/search-events/config.ts +++ b/packages/mcp-core/src/tools/support/search-events/config.ts @@ -45,6 +45,7 @@ TOOL USAGE GUIDELINES: 9. When several fields could match the user's request, choose the field whose description best matches it if applicable, not just the closest name 10. For non-replay datasets, call validateSearch after constructing the candidate request. If invalid, fix and validate again in this same pass 11. NEVER replace a structured field:value filter with message/log.body/full-text matching. If an explicit field is unavailable on the dataset, keep it and let validation fail instead of inventing a weaker query +12. Use a project: filter only for a Sentry project the user calls a project. Service, app, component, and host names are not projects; filter them with a field from datasetAttributes. Issue short IDs like PROJ-123 go in issue:. A project scope given with the request is already applied, so do not repeat it as project: CRITICAL - TOOL RESPONSE HANDLING: All tools return responses in this format: {error?: string, result?: data} 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 e34afd335..f7c672cb5 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 @@ -86,6 +86,58 @@ describe("validateSearch tool contract", () => { result: { valid: true, message: "Search validation passed." }, }); }); + + it("says validation was skipped when Sentry cannot validate the dataset", async () => { + // Sentry returns this for datasets outside RPC_DATASETS, such as errors, + // without checking the project: filter or the latest() function below. + mswServer.use( + http.get( + "https://sentry.io/api/0/organizations/test-org/events/validate/", + () => + HttpResponse.json({ + valid: true, + projects: [], + dataset: [ + { + name: "errors", + valid: true, + error: + "This dataset is not compatible with the validate endpoint, your request may still be valid", + }, + ], + environment: [], + field: [], + query: { valid: true, error: null, fields: [] }, + orderby: [], + }), + ), + ); + const tool = createValidateEventsSearchTool({ + apiService: new SentryApiService({ accessToken: "test-token" }), + organizationSlug: "test-org", + }); + type ToolInput = Parameters>[0]; + const schema = tool.inputSchema as z.ZodType; + const input = schema.parse({ + dataset: "errors", + query: "project:[checkout-api,checkout-worker]", + fields: ["issue", "latest(id)", "count()"], + sort: "-count()", + }); + + const result = await tool.execute!(input, { + toolCallId: "validate-search-skipped-test", + messages: [], + }); + + expect(result).toEqual({ + result: { + valid: true, + message: + "Search validation was skipped: This dataset is not compatible with the validate endpoint, your request may still be valid. Fields, functions, and filters, including project:, were not checked. Use only fields from datasetAttributes and functions from the dataset guidance.", + }, + }); + }); }); describe("formatEventValue", () => { 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 7c6aefa23..ea1489769 100644 --- a/packages/mcp-core/src/tools/support/search-events/utils.ts +++ b/packages/mcp-core/src/tools/support/search-events/utils.ts @@ -1518,6 +1518,17 @@ export function createValidateEventsSearchTool(options: { }); if (validation.valid) { + // Sentry only validates RPC datasets. For others, such as errors, it + // returns valid with a dataset note and checks nothing else. + const skipped = validation.dataset.find( + (entry) => entry.valid && entry.error, + ); + if (skipped) { + return { + valid: true, + message: `Search validation was skipped: ${skipped.error}. Fields, functions, and filters, including project:, were not checked. Use only fields from datasetAttributes and functions from the dataset guidance.`, + }; + } return { valid: true, message: "Search validation passed.",