Skip to content
Draft
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
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
52 changes: 52 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 @@ -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<NonNullable<typeof tool.execute>>[0];
const schema = tool.inputSchema as z.ZodType<ToolInput>;
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", () => {
Expand Down
11 changes: 11 additions & 0 deletions packages/mcp-core/src/tools/support/search-events/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
Expand Down
Loading