Skip to content

feat(tools): Return structured output from search_docs - #2040

Merged
dcramer merged 7 commits into
mainfrom
feat/search-docs-structured-output
Nov 6, 2026
Merged

dcramer merged 7 commits into
mainfrom
feat/search-docs-structured-output

Conversation

@sentry-junior

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

Copy link
Copy Markdown
Contributor

search_docs now has an outputSchema and returns structuredContent instead of markdown. It returns a list of search hits, so it belongs with the structured tools. get_doc (full page markdown) stays markdown on purpose and is unchanged.

Payload

{
  query: string,
  guide: string | null,           // null when omitted
  results: Array<{
    path: string,                 // pass to get_doc as `path`
    url: string,
    relevance: number,            // 0–1 match score
    snippet: string | null,       // null after the first 3 results
  }>,
  suggestedActions: SuggestedToolAction[],
}
  • Fields are mapped one at a time from the /api/search response, with no spreads. A test checks both the top-level keys and the result keys.
  • The "these are just snippets, use get_doc" note is now a suggestedActions entry. It's built with buildSuggestedToolAction and calls get_doc for the first result that has a path. The search route sends "" when a hit has no filename, so those hits are skipped. The entry is left out when get_doc can't be called in the session.
  • No matches return results: [] with no follow-up action.

Snippets: only the first 3

The first-3 rule from the markdown version stays. Snippets are search chunks of about 250 tokens each. Keeping them for every result would add about 1.75k tokens at maxResults=10, and results past the third are mostly useful for their path. maxResults defaults to 3, so most calls aren't affected.

Tokens

Measured with tiktoken (gpt-4o) on a realistic fixture: 1000-char chunks of the real docs.sentry.io markdown for Django, sampling, and Next.js sourcemaps. The old markdown handler is compared with the pretty JSON the server generates:

maxResults markdown pretty JSON compact JSON
3 1040 1089 (+5%) 1012
5 1130 1210 (+7%) 1103

Errors

  • Non-2xx responses: these now throw createApiError(message, status, undefined, body) instead of the base ApiError. A 5xx becomes ApiServerError and gets logged to Sentry. A 429 becomes ApiRateLimitError. Before, every status got the generic "address the concern" text and nothing was logged.
  • Error inside a 2xx body: this used to come back as success text. It now throws createApiError(data.error, 502), which is an ApiServerError, so it shows up as a tool error. The route only reports errors with non-2xx statuses, so this path is defensive.

#788 stays fixed

When guide is omitted, the request body has no guide key. A test asserts that the parsed request body has no guide property, because the route rejects guide: null.

Tests

  • An inline snapshot of structuredContent, plus a schema parse.
  • Cases: guide passthrough, the first-3 snippet rule, top-level and result field allowlists, an empty path being skipped for the action, empty results, get_doc unavailable, the in-body error, a 500 (ApiServerError), a 429 (ApiRateLimitError), and a timeout.
  • toolDefinitions.json is regenerated, and docs/contributing/tool-responses.md has a new "Documentation Search" section.

Checks run with SENTRY_AUTH_TOKEN unset: mocks build, generate-definitions, mcp-core tsc, full mcp-core vitest, and root pnpm run lint. Full vitest ran before a final test-only lint fix, a cast in the #788 assertion. After that fix, the search_docs tests, tsc, and lint were rerun and passed. I did not run stdio MCP QA.

An independent reviewer passed this change with no must-fix items. Its should-fix item (typed HTTP errors) and two nits (the empty-path action, the top-level key check) are applied here.

Whichever of this and #2039 merges second removes the search_docs entry from OUTPUT_SCHEMA_EXEMPT.

via @dcramer.

--

View Session [Sentry]

sentry-junior Bot and others added 3 commits November 5, 2026 23:58
Add a vitest linter for the initialize and tools/list surface in
mcp-core, a structured-output guard for the mcp-core suite, and
server.json checks in @sentry/mcp-server, so the MCP metadata we just
added does not drift back.

The guard mirrors the SDK's tools/call validation: a tool with an
outputSchema must return structuredContent that matches it. Tools whose
outputSchema PR is still open are listed as pending, and their entry
fails once the schema lands, so the PR that lands it deletes the entry.

Co-Authored-By: David Cramer <[email protected]>
The metadata linter only sees listed tools, so deprecated aliases and
the DSN-gated feedback tool lost their title-uniqueness check when it
moved out of tools.test.ts. Check those definitions directly.

Co-Authored-By: David Cramer <[email protected]>
Drop the pending entries whose outputSchema PRs have merged, move the
search_metrics, search_profiles and search_replays tests to structured
search stubs, and mark the guard probe's deliberately invalid result as
a type error now that handler results are typed from outputSchema.
@vercel

vercel Bot commented Nov 6, 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 6, 2026 12:39am UTC

Request Review

sentry-junior Bot and others added 3 commits November 6, 2026 00:29
search_docs returns a list of search hits, so give it an outputSchema
and return structuredContent instead of markdown. Each result carries
its get_doc path, docs URL, relevance score, and snippet (first three
results only, as before). The get_doc follow-up for the top result
becomes a suggestedActions entry, and empty searches return results: [].

An error inside a 2xx search response used to be returned as success
text. It now throws ApiServerError so it surfaces as a tool error and
is reported to Sentry.

Co-Authored-By: David Cramer <[email protected]>
Throw createApiError for non-2xx search responses so 5xx errors reach
Sentry and 429s become ApiRateLimitError, and use it for the in-body
error too. Suggest get_doc for the first result with a non-empty path,
since the search route sends an empty path when a hit has no filename.

Co-Authored-By: David Cramer <[email protected]>
search_docs now declares an outputSchema, so the metadata lint fails
while it stays on the exempt list.
Resolve server.metadata.test.ts add/add conflict after #2039 squash-merged:
keep this branch's removal of search_docs from OUTPUT_SCHEMA_EXEMPT.
@dcramer
dcramer merged commit 715a296 into main Nov 6, 2026
34 checks passed
@dcramer
dcramer deleted the feat/search-docs-structured-output branch November 6, 2026 00:54

This branch was previously deployed

2 inactive deployments
Actions — 7ca35f30 Deployed Nov 6, 2026 by sentry-junior[bot] via eval #1688
Preview — 7ca35f30 Deployed Nov 6, 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