diff --git a/packages/mcp-core/src/tools/catalog/search-issue-events.test.ts b/packages/mcp-core/src/tools/catalog/search-issue-events.test.ts index 4f6a0f4bb..2e8a29c22 100644 --- a/packages/mcp-core/src/tools/catalog/search-issue-events.test.ts +++ b/packages/mcp-core/src/tools/catalog/search-issue-events.test.ts @@ -770,6 +770,102 @@ describe("search_issue_events", () => { ); }); + it("runs open-ended 'since' ranges until now", async () => { + // Regression: "since " and timestamp:>= queries have no end. + // The agent schema required both start and end, so these requests + // failed with "The AI was unable to process your query". + vi.useFakeTimers({ toFake: ["Date"] }); + vi.setSystemTime(new Date("2026-11-13T19:00:00.000Z")); + + const output = { + query: "", + fields: ["id", "timestamp", "title"], + sort: "-timestamp", + timeRange: { start: "2026-11-12T06:39:00Z" }, + explanation: "", + }; + mockGenerateText.mockResolvedValue({ + ...mockAIResponse(), + text: JSON.stringify(output), + experimental_output: output, + }); + + let requestUrl: URL | undefined; + mswServer.use( + http.get( + "https://sentry.io/api/0/organizations/*/issues/*/events/", + ({ request }) => { + requestUrl = new URL(request.url); + return HttpResponse.json([]); + }, + ), + ); + + try { + await searchIssueEvents.handler( + { + organizationSlug: "test-org", + issueId: "MCP-41", + query: "timestamp:>=2026-11-12T06:39:00Z", + sort: "-timestamp", + projectSlug: null, + regionUrl: null, + limit: 50, + includeExplanation: false, + }, + mockContext, + ); + } finally { + vi.useRealTimers(); + } + + expect(requestUrl?.searchParams.get("start")).toBe("2026-11-12T06:39:00Z"); + expect(requestUrl?.searchParams.get("end")).toBe( + "2026-11-13T19:00:00.000Z", + ); + expect(requestUrl?.searchParams.get("statsPeriod")).toBeNull(); + }); + + it("uses the default 14d window when the agent omits timeRange", async () => { + const output = { + query: "", + fields: ["id", "timestamp"], + sort: "-timestamp", + }; + mockGenerateText.mockResolvedValue({ + ...mockAIResponse(), + text: JSON.stringify(output), + experimental_output: output, + }); + + let requestUrl: URL | undefined; + mswServer.use( + http.get( + "https://sentry.io/api/0/organizations/*/issues/*/events/", + ({ request }) => { + requestUrl = new URL(request.url); + return HttpResponse.json([]); + }, + ), + ); + + await searchIssueEvents.handler( + { + organizationSlug: "test-org", + issueId: "MCP-41", + query: "all events", + sort: "-timestamp", + projectSlug: null, + regionUrl: null, + limit: 50, + includeExplanation: false, + }, + mockContext, + ); + + expect(requestUrl?.searchParams.get("statsPeriod")).toBe("14d"); + }); + it("should validate sort field is included in fields array", async () => { // Agent returns sort field not in fields array (validation should fail) mockGenerateText.mockResolvedValue( diff --git a/packages/mcp-core/src/tools/catalog/search-issue-events.ts b/packages/mcp-core/src/tools/catalog/search-issue-events.ts index 8ff800e6e..dc3ff9df7 100644 --- a/packages/mcp-core/src/tools/catalog/search-issue-events.ts +++ b/packages/mcp-core/src/tools/catalog/search-issue-events.ts @@ -226,9 +226,17 @@ export default defineTool({ fields = requestedFields.length > 0 ? requestedFields : RECOMMENDED_FIELDS; - timeParams = parsed.timeRange - ? { ...parsed.timeRange } - : { statsPeriod: "14d" }; + if (!parsed.timeRange) { + timeParams = { statsPeriod: "14d" }; + } else if ("start" in parsed.timeRange) { + // "since X" ranges have no end; run them until now. + timeParams = { + start: parsed.timeRange.start, + end: parsed.timeRange.end ?? new Date().toISOString(), + }; + } else { + timeParams = { ...parsed.timeRange }; + } } else { // Direct mode: use provided params as-is query = params.query ?? ""; diff --git a/packages/mcp-core/src/tools/support/search-issue-events/agent.ts b/packages/mcp-core/src/tools/support/search-issue-events/agent.ts index 42fc3d69c..749035561 100644 --- a/packages/mcp-core/src/tools/support/search-issue-events/agent.ts +++ b/packages/mcp-core/src/tools/support/search-issue-events/agent.ts @@ -28,12 +28,18 @@ export const searchIssueEventsAgentOutputSchema = z }), z.object({ start: z.string().describe("ISO 8601 start time"), - end: z.string().describe("ISO 8601 end time"), + end: z + .string() + .optional() + .describe( + "ISO 8601 end time. Omit for open-ended ranges like 'since X'; the search then runs until now.", + ), }), z.null(), ]) + .default(null) .describe( - "Time range for filtering events. Use either statsPeriod for relative time or start/end for absolute time. Use null for default 14-day window.", + "Time range for filtering events. Use either statsPeriod for relative time or start (and optional end) for absolute time. Use null for default 14-day window.", ), explanation: z .string() diff --git a/packages/mcp-core/src/tools/support/search-issue-events/config.ts b/packages/mcp-core/src/tools/support/search-issue-events/config.ts index a681a663d..5c8d624c8 100644 --- a/packages/mcp-core/src/tools/support/search-issue-events/config.ts +++ b/packages/mcp-core/src/tools/support/search-issue-events/config.ts @@ -54,7 +54,10 @@ For time-based queries ("last hour", "yesterday", "from Dec 16"): - "yesterday" → {"statsPeriod": "24h"} - "last week" → {"statsPeriod": "7d"} - Absolute: Use start/end (ISO 8601 format) - - "from Dec 16 2025 17:50 UTC" → {"start": "2025-12-16T17:50:00Z", "end": "2025-12-17T23:59:59Z"} + - "between Dec 16 2025 17:50 and Dec 17 2025 09:00 UTC" → {"start": "2025-12-16T17:50:00Z", "end": "2025-12-17T09:00:00Z"} +- Open-ended: For "since X", "after X", or timestamp:>=X, set only start. Omitting end means "until now". + - "since Dec 16 2025 17:50 UTC" → {"start": "2025-12-16T17:50:00Z"} + - "timestamp:>=2025-12-16T17:50:00Z" → {"start": "2025-12-16T17:50:00Z"} - Default: If no time mentioned, use {"statsPeriod": "14d"} FIELD SELECTION: @@ -101,7 +104,8 @@ Return a JSON object with: - "timeRange": Optional time range - Relative: {"statsPeriod": "24h"} - Absolute: {"start": "2025-01-01T00:00:00Z", "end": "2025-01-02T00:00:00Z"} - - Omit for default 14-day window + - Open-ended: {"start": "2025-01-01T00:00:00Z"} (until now) + - null for default 14-day window - "explanation": Brief explanation of how you translated the query CORRECT QUERY EXAMPLES: