Skip to content

fix(mcp-core): align search_issues period with query time windows - #2905

Open
37chengshan wants to merge 2 commits into
getsentry:mainfrom
37chengshan:fix/search-issues-period-window
Open

37chengshan wants to merge 2 commits into
getsentry:mainfrom
37chengshan:fix/search-issues-period-window

Conversation

@37chengshan

Copy link
Copy Markdown

Summary

Aligns search_issues's statsPeriod (period) with time-window filters present in translated or explicit issue queries (such as lastSeen:-90d, firstSeen:-60d, timestamp:-45d, event.timestamp:..., activeSince:..., age:..., and ISO-8601 timestamps) when the caller has not explicitly supplied period.

Closes #2843

Root Cause

  1. search_issues declared period with .default("30d") in inputSchema. Because @modelcontextprotocol/server and prepareToolParams apply schema defaults before invoking handler, omitted period arrived as "30d", making it indistinguishable from an explicit period: "30d" argument.
  2. When the embedded search agent translated natural language such as "TypeError in my-service, any status, last 90 days" into error_type:TypeError my-service lastSeen:-90d, handler still forwarded statsPeriod=30d to /api/0/organizations/{org}/issues/. Sentry intersects statsPeriod ([now - 30d, now]) with query, silently dropping issues whose activity fell between 30 and 90 days ago while reporting executedSearch.query as ... lastSeen:-90d.

Changes

  • packages/mcp-core/src/tools/catalog/search-issues.ts:
    • Make inputSchema.period .optional() (matching search_events, search_errors, search_issue_events, etc.) while keeping (default: 30d) documented in the parameter description and applying the "30d" default in handler.
    • Resolve the effective period and any truncation/cap warning via resolveIssueSearchPeriod(...) after query translation and boolean rewriting, surfacing warnings through the existing notes: string[] field without altering searchIssuesOutputSchema (preserving closed-schema compatibility for cached tools/list clients per Closed outputSchemas make every added output field break clients holding an older tools/list #2293).
  • packages/mcp-core/src/tools/support/search-issues/period.ts:
    • Parse issue search AST filter tokens via @sentry/search-syntax (lastSeen, firstSeen, age, timestamp, event.timestamp, activeSince) for both relative durations (-90d, >-60d, +60d, <-90d, -12w, etc.) and absolute ISO-8601 dates/timestamps, ignoring quoted free-text literals and negated filters.
    • When period is omitted: default to "30d" (or Seer's statsPeriod rounded up to a supported SEARCH_ISSUES_PERIOD_VALUES bucket), widen up to "90d" when the query requests a wider window, never shrink below "30d" for shorter query filters (e.g. lastSeen:-7d), and add a clear cap note in notes if the requested window exceeds "90d".
    • When period is explicitly provided by the caller: always preserve the caller's period, and add an actionable note in notes when query or Seer's statsPeriod requests a wider window than period allows.
  • packages/mcp-core/src/toolDefinitions.json:
    • Regenerated tool schema metadata reflecting period as optional.
  • Tests:
    • Added unit tests in packages/mcp-core/src/tools/support/search-issues/period.test.ts covering period ceiling buckets, relative/absolute time extraction, older-than activity bounds, quoted/negated non-matches, 30d/31d/90d/>90d boundaries, and explicit vs. omitted period.
    • Added integration and MCP client/server JSON-RPC boundary tests in packages/mcp-core/src/tools/catalog/search-issues.test.ts covering agent translation, direct syntax, Seer stats_period, explicit shorter period warnings, >90d cap notes, and omitted period vs. explicit period: "30d" across InMemoryTransport.

Test Plan

  • vitest run src/tools/support/search-issues/period.test.ts src/tools/catalog/search-issues.test.ts src/server.metadata.test.ts src/server.test.ts
  • Full @sentry/mcp-core test suite (vitest run), tsc --noEmit, oxlint, oxfmt --check, ast-grep, and validate-skills

Co-Authored-By: Gemini <noreply@google.com>
@37chengshan
37chengshan requested a review from a team as a code owner December 4, 2026 13:14
@vercel

vercel Bot commented Dec 4, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated
sentry-local Skipped Skipped Dec 5, 2026 3:58am UTC

Request Review

@vercel
vercel Bot temporarily deployed to Preview – sentry-local December 4, 2026 13:15 Inactive
@vercel

vercel Bot commented Dec 4, 2026

Copy link
Copy Markdown

@37chengshan is attempting to deploy a commit to the Sentry Team on Vercel.

A member of the Team first needs to authorize it.

@github-actions github-actions Bot added the risk: medium PR risk score: medium label Dec 4, 2026
…iod-window

# Conflicts:
#	packages/mcp-core/src/tools/catalog/search-issues.test.ts
#	packages/mcp-core/src/tools/catalog/search-issues.ts
@vercel
vercel Bot temporarily deployed to Preview – sentry-local December 5, 2026 03:58 Inactive

This branch was previously deployed

1 inactive deployment
Preview – sentry-local — 0ed30b7d Deployed Dec 5, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

risk: medium PR risk score: medium

Projects

None yet

Development

Successfully merging this pull request may close these issues.

search_issues: a time window in a natural-language query is not applied to period

1 participant