Skip to content

feat(tools): Add outputSchema to get_replay_details - #2019

Merged
dcramer merged 5 commits into
mainfrom
feat/structured-get-replay-details
Nov 5, 2026
Merged

dcramer merged 5 commits into
mainfrom
feat/structured-get-replay-details

Conversation

@sentry-junior

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

Copy link
Copy Markdown
Contributor

get_replay_details now declares an outputSchema and returns structuredContent on every success path. Errors still throw. Like get_release_details (#1983), structured output is always on, not tied to experimental mode.

The payload has four parts: replay, timeline, related, and suggestedActions. Each field is mapped from the API response explicitly; no API object is spread through.

  • timeline has status: "unavailable" with a reason, or status: "loaded" with:
    • recorded: every event counted by category, then label, before filters. {} means no activity.
    • failedRequests, plus the requested categories and offset window.
    • matchingCount, skip, and nextSkip for paging.
    • segmentsRead and truncated, which say whether the recording was cut off.
    • events: each has offsetSeconds (to 0.1s), label, target, and details.
  • suggestedActions holds up to 3 follow-ups, each checked against the tools available in the session:
    • Continue the timeline with get_replay_details, using the same arguments plus skip. regionUrl is included only when the caller passed it.
    • Open a related issue with get_issue_details. Errors with no resolved issue get no follow-up, since an event lookup runs the same issue search and fails.
    • Open a related trace with get_trace_details.

User mapping: replay.user is { id, username, email, ip, geo }. geo is { city, countryCode, region, subdivision }, or null when all four are empty.

  • Sentry builds display_name from username, email, id, or IP, so it isn't used.
  • user is null for archived replays, because Sentry fills in a placeholder user for them.
  • user is also null for anonymous replays. Snuba returns "" for missing user columns, so empty strings are treated as null.
  • Tags, SDK, dist, info and warning ids, and raw recording payloads (request and response bodies, headers, console arguments) are left out. A test checks both key names and raw fixture values.

Schema: I trimmed descriptions that repeat input params (categories, start/endOffsetSeconds, nextSkip) and dropped the enum key constraint on recorded. The outputSchema is about 1,126 o200k tokens (4,785 chars). measure-tokens doesn't count it.

Payload size (o200k, synthetic replay with about 150 events, 50 shown):

Scenario Markdown Pretty JSON
Default 2223 3736 (1.68x)
categories=network 2083 3384 (1.62x)
Last 30s window 512 1021 (~1.99x)

I measured these before the user fields were expanded, which adds about 40 tokens per call. Most of the overhead is the server's 2-space pretty-print of JSON and the key names repeated on each event. Compact JSON would be 2502, 2262, and 709 tokens.

Shared code:

  • internal/tool-helpers/suggested-actions.ts is the canonical shared helper, blob ee84917. Other structured-output branches use the same file. ai-conversation-actions.ts now uses it, with the same behavior.
  • toolDefinitions.json is generated. Regenerate it with pnpm run --filter @sentry/mcp-core generate-definitions when rebasing, rather than resolving conflicts by hand.

Checks (with SENTRY_AUTH_TOKEN unset):

  • pnpm run --filter @sentry/mcp-core generate-definitions: up to date.
  • pnpm --filter @sentry/mcp-core run tsc: pass.
  • Full mcp-core vitest: 2105 passed, 6 skipped.
  • Root pnpm run lint: 0 warnings, 0 errors.

via @dcramer.

--

View Session [Sentry]

sentry-junior Bot and others added 4 commits November 5, 2026 19:19
Return the replay summary, timeline, and related issues and traces as
structuredContent instead of markdown. The timeline keeps the same events,
filters, and per-category counts; pagination is `timeline.nextSkip`, and
follow-ups (continue the timeline, open a related issue or trace) are
`suggestedActions` gated on session tool availability.

Fields are mapped explicitly. The user keeps the name the markdown showed
(display name, then email, then username) and id; IP, geo, tags, SDK, and
raw recording payloads stay out.

Extract the session-aware action builder from ai-conversation-actions into
a shared suggested-actions helper so both tools use it.

Co-Authored-By: David Cramer <[email protected]>
Sentry builds `user.display_name` from username, email, id, or IP, so a
single `name` field mixed those. Return `id`, `username`, `email`, `ip`, and
`geo` as separate fields instead, and return a null user for archived
replays, whose user is a placeholder.

Trim output schema descriptions that repeat the input parameters, drop the
enum key constraint on `timeline.recorded`, and keep `regionUrl` in the
continuation suggested action.

The shared `formatReplayUser` helper for search_replays returns to its
previous form, since get_replay_details no longer uses it.

Co-Authored-By: David Cramer <[email protected]>
Snuba stores replay user and geo columns as non-nullable strings, so an
anonymous replay comes back with `""` values. Map empty strings to null so
anonymous users return `user: null` and an empty geo returns `geo: null`.

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 8:20pm UTC

Request Review

@github-actions github-actions Bot added the risk: medium PR risk score: medium label Nov 5, 2026

@cursor cursor Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit aaac72e. Configure here.

get_sentry_resource with resourceType 'event' resolves the event through
the same issue search that already found nothing, so the suggested call
always failed. Suggest follow-ups only for errors with a resolved issue.
@dcramer
dcramer merged commit 14fd408 into main Nov 5, 2026
36 checks passed
@dcramer
dcramer deleted the feat/structured-get-replay-details branch November 5, 2026 22:08
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 — 8003c77d Deployed Nov 5, 2026 by sentry-junior[bot] via eval #1615
Preview — 8003c77d 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