Skip to content

feat(mcp): Return structured output from search_errors - #1987

Merged
dcramer merged 3 commits into
mainfrom
feat/search-errors-structured-output
Nov 5, 2026
Merged

dcramer merged 3 commits into
mainfrom
feat/search-errors-structured-output

Conversation

@sentry-junior

@sentry-junior sentry-junior Bot commented Nov 5, 2026

Copy link
Copy Markdown
Contributor

search_errors now declares an outputSchema. Every success path returns structuredContent: sample rows, aggregate rows, and time series. This follows the Structured Content policy in docs/contributing/tool-responses.md.

What the model sees: pretty JSON instead of markdown. Everything the markdown showed has a named field:

  • presentationHint: the presentation hint plus the dashboard-link hint.
  • url: the dashboard link.
  • notes[]: empty-result guidance, plus the Seer, unknown-environment, project-suggestion, and dropped-events notes.
  • resultType: samples, aggregates, or timeSeries.
  • timeSeries: total, peak, ingestion, and per-bucket incomplete/outsideRetention, capped at 48 buckets with a bucketCount.
  • suggestedActions: one get_sentry_resource issue action for the first matching issue. It goes through execute_sentry_tool when that tool is catalog-only, and is omitted when the tool isn't available.

The generic "Next Steps" bullets are dropped, per the doc.

No-leak:

  • Each row's values holds only the requested fields, and links holds the derived issueUrl.
  • Time-series output is mapped field by field from the passthrough series, bucket, and ingestion metadata.
  • Regression tests cover both paths.

Shared pieces, so other dataset tools can opt in one at a time:

  • support/search-events/structured.ts: each dataset config declares its row-link Zod shape, and buildSearchEventsOutputSchema(dataset) derives the schema from it. rowLinks is typed against that shape, so a key mismatch is a compile error.
  • runSearchEvents takes output: "structured", which the types only allow together with lockDataset: true.
  • internal/tool-helpers/suggested-actions.ts adds buildSuggestedToolAction. ai-conversation-actions.ts now uses it, with no behavior change.
  • formatters.ts extracts summarizeTimeSeries and shared hint constants. Markdown output is unchanged.
  • Legacy search_events stays markdown. docs/specs/search-events.md documents the structured payload.

Token cost:

  • measure-tokens total is unchanged at 47,079, because the script does not count outputSchema.
  • Real tools/list cost for this tool is about 738 tokens of description and input plus about 732 tokens of outputSchema (tiktoken).
  • Per call, on a realistic 10-row errors fixture: markdown 1,712 tokens vs JSON 2,007 (1.17x).

Stacking and conflicts:

  • The logs, traces, metrics, profiles, and replays branches build on this one, so merge it first.
  • toolDefinitions.json will conflict with the sibling outputSchema PRs. Regenerate it on rebase with pnpm run --filter @sentry/mcp-core generate-definitions.

Checks:

  • pnpm --filter @sentry/mcp-core run tsc passed.
  • Root pnpm run lint passed.
  • The full mcp-core vitest suite passed: 142 files, 2,083 tests.
  • generate-definitions was run.
  • Root pnpm run tsc was not used for the final pass: its mcp-cloudflare build uploads source maps to Sentry.
  • Evals were skipped because they need provider API keys.

A separate review pass came back ready with no must-fix items. Its follow-ups are in d384421.

via @dcramer.

--

View Session [Sentry]

sentry-junior Bot and others added 2 commits November 5, 2026 18:27
search_errors now declares an outputSchema and returns structuredContent
on every success path: sample rows, aggregate rows, and time series.

Rows carry only the requested fields plus derived issue links, so
upstream keys the search did not ask for never reach the model. The
presentation hint, dashboard link, empty-result guidance, Seer and
environment notes, and dropped-event notes move into named fields. The
first matching issue becomes a get_issue_details suggested action.

The shared pieces live in search-events/structured.ts so the other
dataset tools can opt in one at a time. The legacy search_events tool
keeps its markdown output.

Co-Authored-By: David Cramer <[email protected]>
- Declare each dataset's row-link Zod shape in its structured config and
  derive the output schema from it, so rowLinks and the schema cannot
  drift apart.
- Require lockDataset when runSearchEvents returns structured output.
- Point the issue follow-up at get_sentry_resource.
- Snapshot the full time-series payload and assert passthrough keys from
  the series, bucket, and ingestion metadata never reach the result.
- Describe the structured payload in the search-events spec.

Co-Authored-By: David Cramer <[email protected]>
@vercel

vercel Bot commented Nov 5, 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 Nov 5, 2026 7:50pm UTC

Request Review

Copy suggested-actions.ts and ai-conversation-actions.ts byte-for-byte
from the get_replay_details change, which exports MAX_SUGGESTED_ACTIONS
and SuggestedActionValue, so every structured-output branch adds the
same bytes and they merge cleanly in any order.

Co-Authored-By: David Cramer <[email protected]>
@sentry-junior
sentry-junior Bot added this pull request to stack #2007 November 5, 2026 19:55
@dcramer
dcramer merged commit b7616d3 into main Nov 5, 2026
37 of 38 checks passed
@dcramer
dcramer deleted the feat/search-errors-structured-output branch November 5, 2026 21:46
dcramer added a commit that referenced this pull request Nov 5, 2026
`search_logs` now declares an `outputSchema` and returns
`structuredContent` on every success path. It uses the shared dataset
search payload from #1987 and follows the Structured Content policy in
`docs/contributing/tool-responses.md`. The model now sees pretty JSON
instead of markdown.

- Rows carry only the requested fields in `values`, plus derived
`logUrl` and `traceUrl` links in `links`, mapped explicitly.
- The console-style presentation hint and empty-result guidance move
into named fields.
- The first row with a trace becomes a `get_sentry_resource` suggested
action.
- Tests snapshot `structuredContent` and assert that passthrough API
fields don't leak.

**Stack and merge order:** #1987 (search_errors) → logs → traces →
metrics → profiles → replays (the replays PR isn't open yet). This PR
targets `feat/search-errors-structured-output` and is 1st after #1987 in
the stack. Merge in that order; GitHub retargets each PR as its base
merges.
- If #1987 or a parent PR is squash-merged, rebase this branch with `git
rebase --onto <new base> <old parent head> <this branch>` so the
parent's commits don't replay.
- `toolDefinitions.json` will conflict along the stack and with the
sibling structured-output PRs. Regenerate it on rebase with `pnpm run
--filter @sentry/mcp-core generate-definitions`.
- The shared `suggested-actions.ts` / `ai-conversation-actions.ts` come
from #1987 and are byte-identical to the canonical copies (blobs
`ee84917` / `63ff7bd`).

**Tokens**
- `measure-tokens` total is unchanged at 47,079: the description and
input schema are unchanged, and the script doesn't count `outputSchema`.
- `outputSchema` adds ~745 tokens to `tools/list`.
- Per call on a realistic fixture: markdown 2478 → JSON 2679 tokens
(1.08x).

**Checks:** package-scoped only, run with `SENTRY_AUTH_TOKEN` unset.
- `pnpm run --filter @sentry/mcp-core generate-definitions`, `pnpm
--filter @sentry/mcp-core run tsc`, `pnpm run lint`
- full mcp-core vitest on the top stacked branch (profiles): 146 files,
2096 passed, 6 skipped; on this branch, tool-helpers + search-events +
search tool tests: 337 passed
- Root `pnpm run tsc` was not run because its cloudflare build uploads
source maps. Evals were skipped because they need API keys.

<!-- junior-request-attribution:start -->
via @dcramer.
<!-- junior-request-attribution:end -->

<!-- junior-session-footer:start -->
<!-- junior-conversation-id:agent%3A018aa877508ecba7895b5d9d7ca8674a -->

--

[View
Session](https://junior-prod.sentry.dev/conversations/agent%3A018aa877508ecba7895b5d9d7ca8674a)
[[Sentry]](https://sentry.sentry.io/explore/conversations/agent%3A018aa877508ecba7895b5d9d7ca8674a/?project=4510944073809921)

<!-- junior-session-footer:end -->

Co-authored-by: sentry-junior[bot] <264270552+sentry-junior[bot]@users.noreply.github.com>
Co-authored-by: David Cramer <[email protected]>
dcramer added a commit that referenced this pull request Nov 5, 2026
`search_traces` now declares an `outputSchema` and returns
`structuredContent` on every success path, using the shared dataset
search payload from #1987. The model now sees pretty JSON instead of
markdown.

- Rows carry only the requested fields, plus a derived `traceUrl` link.
- The timeline presentation hint and empty-result guidance move into
named fields.
- A note says `span.duration` values are in milliseconds; the markdown
appended "ms".
- The first row with a trace becomes a `get_sentry_resource` suggested
action.
- Tests snapshot `structuredContent` and assert that passthrough fields
don't leak.

**Stack and merge order:** #1987 (search_errors) → logs → traces →
metrics → profiles → replays (the replays PR isn't open yet). This PR
targets `feat/search-logs-structured-output` and is 2nd after #1987 in
the stack. Merge in that order; GitHub retargets each PR as its base
merges.
- If #1987 or a parent PR is squash-merged, rebase this branch with `git
rebase --onto <new base> <old parent head> <this branch>` so the
parent's commits don't replay.
- `toolDefinitions.json` will conflict along the stack and with the
sibling structured-output PRs. Regenerate it on rebase with `pnpm run
--filter @sentry/mcp-core generate-definitions`.
- The shared `suggested-actions.ts` / `ai-conversation-actions.ts` come
from #1987 and are byte-identical to the canonical copies (blobs
`ee84917` / `63ff7bd`).

**Tokens**
- `measure-tokens` total is unchanged at 47,079: the description and
input schema are unchanged, and the script doesn't count `outputSchema`.
- `outputSchema` adds ~732 tokens to `tools/list`.
- Per call on a realistic fixture: markdown 1876 → JSON 2199 tokens
(1.17x).

**Checks:** package-scoped only, run with `SENTRY_AUTH_TOKEN` unset.
- `pnpm run --filter @sentry/mcp-core generate-definitions`, `pnpm
--filter @sentry/mcp-core run tsc`, `pnpm run lint`
- full mcp-core vitest on the top stacked branch (profiles): 146 files,
2096 passed; on this branch, tool-helpers + search-events + search tool
tests: 340 passed
- Root `pnpm run tsc` was not run because its cloudflare build uploads
source maps. Evals were skipped because they need API keys.

<!-- junior-request-attribution:start -->
via @dcramer.
<!-- junior-request-attribution:end -->

<!-- junior-session-footer:start -->
<!-- junior-conversation-id:agent%3A018aa877508ecba7895b5d9d7ca8674a -->

--

[View
Session](https://junior-prod.sentry.dev/conversations/agent%3A018aa877508ecba7895b5d9d7ca8674a)
[[Sentry]](https://sentry.sentry.io/explore/conversations/agent%3A018aa877508ecba7895b5d9d7ca8674a/?project=4510944073809921)

<!-- junior-session-footer:end -->

Co-authored-by: sentry-junior[bot] <264270552+sentry-junior[bot]@users.noreply.github.com>
Co-authored-by: David Cramer <[email protected]>
dcramer added a commit that referenced this pull request Nov 5, 2026
`search_metrics` now declares an `outputSchema` and returns
`structuredContent` on every success path, using the shared dataset
search payload from #1987. The model now sees pretty JSON instead of
markdown.

- Rows carry only the requested fields, plus a derived `traceUrl` link.
- The follow-up action opens the first sample's trace with
`get_sentry_resource`.
- Metric presentation hints move into `METRIC_RESULT_HINTS`, so markdown
and structured output share them.
- Tests snapshot `structuredContent` and assert that passthrough fields
don't leak.

**Stack and merge order:** #1987 (search_errors) → logs → traces →
metrics → profiles → replays (the replays PR isn't open yet). This PR
targets `feat/search-traces-structured-output` and is 3rd after #1987 in
the stack. Merge in that order; GitHub retargets each PR as its base
merges.
- If #1987 or a parent PR is squash-merged, rebase this branch with `git
rebase --onto <new base> <old parent head> <this branch>` so the
parent's commits don't replay.
- `toolDefinitions.json` will conflict along the stack and with the
sibling structured-output PRs. Regenerate it on rebase with `pnpm run
--filter @sentry/mcp-core generate-definitions`.
- The shared `suggested-actions.ts` / `ai-conversation-actions.ts` come
from #1987 and are byte-identical to the canonical copies (blobs
`ee84917` / `63ff7bd`).

**Tokens**
- `measure-tokens` total is unchanged at 47,079: the description and
input schema are unchanged, and the script doesn't count `outputSchema`.
- `outputSchema` adds ~732 tokens to `tools/list`.
- Per call on a realistic fixture: markdown 1937 → JSON 2262 tokens
(1.17x).

**Checks:** package-scoped only, run with `SENTRY_AUTH_TOKEN` unset.
- `pnpm run --filter @sentry/mcp-core generate-definitions`, `pnpm
--filter @sentry/mcp-core run tsc`, `pnpm run lint`
- full mcp-core vitest on the top stacked branch (profiles): 146 files,
2096 passed; on this branch, tool-helpers + search-events + search tool
tests: 343 passed
- Root `pnpm run tsc` was not run because its cloudflare build uploads
source maps. Evals were skipped because they need API keys.

<!-- junior-request-attribution:start -->
via @dcramer.
<!-- junior-request-attribution:end -->

<!-- junior-session-footer:start -->
<!-- junior-conversation-id:agent%3A018aa877508ecba7895b5d9d7ca8674a -->

--

[View
Session](https://junior-prod.sentry.dev/conversations/agent%3A018aa877508ecba7895b5d9d7ca8674a)
[[Sentry]](https://sentry.sentry.io/explore/conversations/agent%3A018aa877508ecba7895b5d9d7ca8674a/?project=4510944073809921)

<!-- junior-session-footer:end -->

Co-authored-by: sentry-junior[bot] <264270552+sentry-junior[bot]@users.noreply.github.com>
Co-authored-by: David Cramer <[email protected]>
dcramer added a commit that referenced this pull request Nov 5, 2026
`search_profiles` now declares an `outputSchema` and returns
`structuredContent` on every success path, using the shared dataset
search payload from #1987. The model now sees pretty JSON instead of
markdown.

- Rows carry only the requested fields, plus derived `profileUrl`
(transaction or continuous-profile flamegraph, via the now-exported
`getProfileDetailUrl`) and `traceUrl` links.
- Notes say `transaction.duration` and `profile.duration` are in
nanoseconds; the markdown formatted them.
- Suggested actions open the first profile with `get_profile_details`
(`get_sentry_resource` in experimental mode, as the markdown advised)
and the first trace with `get_sentry_resource`.
- Tests snapshot `structuredContent` and assert that passthrough fields
don't leak.

**Stack and merge order:** #1987 (search_errors) → logs → traces →
metrics → profiles → replays (the replays PR isn't open yet). This PR
targets `feat/search-metrics-structured-output` and is 4th after #1987
in the stack. Merge in that order; GitHub retargets each PR as its base
merges.
- If #1987 or a parent PR is squash-merged, rebase this branch with `git
rebase --onto <new base> <old parent head> <this branch>` so the
parent's commits don't replay.
- `toolDefinitions.json` will conflict along the stack and with the
sibling structured-output PRs. Regenerate it on rebase with `pnpm run
--filter @sentry/mcp-core generate-definitions`.
- The shared `suggested-actions.ts` / `ai-conversation-actions.ts` come
from #1987 and are byte-identical to the canonical copies (blobs
`ee84917` / `63ff7bd`).

**Tokens**
- `measure-tokens` total is unchanged at 47,079: the description and
input schema are unchanged, and the script doesn't count `outputSchema`.
- `outputSchema` adds ~745 tokens to `tools/list`.
- Per call on a realistic fixture: markdown 2507 → JSON 3039 tokens
(1.21x).

**Checks:** package-scoped only, run with `SENTRY_AUTH_TOKEN` unset.
- `pnpm run --filter @sentry/mcp-core generate-definitions`, `pnpm
--filter @sentry/mcp-core run tsc`, `pnpm run lint`
- full mcp-core vitest on this branch: 146 files, 2096 passed, 6 skipped
- Root `pnpm run tsc` was not run because its cloudflare build uploads
source maps. Evals were skipped because they need API keys.

<!-- junior-request-attribution:start -->
via @dcramer.
<!-- junior-request-attribution:end -->

<!-- junior-session-footer:start -->
<!-- junior-conversation-id:agent%3A018aa877508ecba7895b5d9d7ca8674a -->

--

[View
Session](https://junior-prod.sentry.dev/conversations/agent%3A018aa877508ecba7895b5d9d7ca8674a)
[[Sentry]](https://sentry.sentry.io/explore/conversations/agent%3A018aa877508ecba7895b5d9d7ca8674a/?project=4510944073809921)

<!-- junior-session-footer:end -->

Co-authored-by: sentry-junior[bot] <264270552+sentry-junior[bot]@users.noreply.github.com>
Co-authored-by: David Cramer <[email protected]>
dcramer added a commit that referenced this pull request Nov 5, 2026
`search_replays` now declares an `outputSchema` and returns
`structuredContent` on every success path, following the Structured
Content policy in `docs/contributing/tool-responses.md`. The model now
sees pretty JSON instead of markdown.

**Payload**
- `searchReplaysOutputSchema` and `buildStructuredReplayResults` in
`replays.ts` map replay fields explicitly:
  - id, `replayUrl`, start time, duration
  - error/rage/dead click counts
  - environment and browser
  - `isArchived`
- **User.** Explicit `{id, username, email, ip}`, matching
get_replay_details, instead of the upstream-computed display name. The
tool returns the user data Sentry stored. Tags, SDK and other internal
fields stay out, and a no-leak test checks this. `user` is null for
archived replays, whose rows carry placeholder data ("Archived Replay"
as the id).
- **Lists.** URLs, trace IDs and releases are previewed at 3 each.
`urlCount`, `traceCount` and `releaseCount` give the totals.
- **Suggested actions.** `get_replay_details` for the first replay, plus
`get_sentry_resource` for its first trace.
- Adds a replay overload to `runSearchEvents` and exports
`timeRangeSchema` from `structured.ts`.

**Stack and merge order**
- Order: #1987 (search_errors) → #2006 logs → #2008 traces → #2010
metrics → #2012 profiles → this PR. It targets
`feat/search-profiles-structured-output`. Merge in that order; GitHub
retargets each PR as its base merges.
- **Merge after #2019, or keep the pinned-user test.** The mapping test
pins its own user instead of reading the shared `replay-details.json`
fixture. #2019 adds `username: "taylor"` to that fixture, which would
otherwise break this snapshot.
- If #1987 or a parent PR is squash-merged, rebase with `git rebase
--onto <new base> <old parent head>
feat/search-replays-structured-output`.
- `toolDefinitions.json` will conflict along the stack and with the
sibling structured-output PRs. Regenerate it on rebase with `pnpm run
--filter @sentry/mcp-core generate-definitions`.

**Tokens**
- `measure-tokens` total is unchanged at 47,079. The description and
input schema are unchanged, and the script doesn't count `outputSchema`.
- `outputSchema` adds ~629 tokens to `tools/list`.
- Per call on a realistic fixture: markdown 1930 → JSON 3191 tokens
(1.65x).

**Checks.** All package-scoped, with `SENTRY_AUTH_TOKEN` unset:
- `pnpm --filter @sentry/mcp-server-mocks run build`
- `pnpm run --filter @sentry/mcp-core generate-definitions`, then `git
status`; only the intended files changed
- `pnpm --filter @sentry/mcp-core run tsc`
- full mcp-core vitest: 147 files, 2101 passed, 6 skipped
- `pnpm run lint`

Root `pnpm run tsc` was not run because its cloudflare build uploads
source maps. Evals were skipped because they need API keys.

<!-- junior-request-attribution:start -->
via @dcramer.
<!-- junior-request-attribution:end -->

<!-- junior-session-footer:start -->
<!-- junior-conversation-id:agent%3A018aa877508ecba7895b5d9d7ca8674a -->

--

[View
Session](https://junior-prod.sentry.dev/conversations/agent%3A018aa877508ecba7895b5d9d7ca8674a)
[[Sentry]](https://sentry.sentry.io/explore/conversations/agent%3A018aa877508ecba7895b5d9d7ca8674a/?project=4510944073809921)

<!-- junior-session-footer:end -->

---------

Co-authored-by: sentry-junior[bot] <264270552+sentry-junior[bot]@users.noreply.github.com>
Co-authored-by: David Cramer <[email protected]>

This branch was previously deployed

2 inactive deployments
Actions — a4f24d23 Deployed Nov 5, 2026 by sentry-junior[bot] via eval #1600
Preview — a4f24d23 Deployed Nov 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.

1 participant