Skip to content

feat(mcp): expose explain parameter for retrieval score traces - #730

Open
fxstein wants to merge 1 commit into
tobi:mainfrom
fxstein:feat/mcp-explain-param
Open

feat(mcp): expose explain parameter for retrieval score traces#730
fxstein wants to merge 1 commit into
tobi:mainfrom
fxstein:feat/mcp-explain-param

Conversation

@fxstein

@fxstein fxstein commented Jun 13, 2026

Copy link
Copy Markdown
Contributor

What

Adds an optional explain boolean to the MCP query tool and the REST /query (alias /search) endpoint. When set, each result carries the retrieval score trace the SDK already computes — per-list FTS and vector scores, the RRF fusion breakdown, and rerank blend weights.

Why

SearchOptions.explain and HybridQueryResult.explain already exist in the SDK (hybridQuery() / structuredSearch() build the trace via buildRrfTrace), but there is no way to request it from an MCP client — you have to drop down to the SDK. This plumbs the existing flag through the two MCP-facing surfaces so query quality and ranking can be inspected in place.

Details

  • New explain param (default false) on the query tool schema, forwarded to store.search.
  • explain accepted on the REST /query body and forwarded likewise.
  • Each result spreads ...(r.explain ? { explain: r.explain } : {}), typed against the exported HybridQueryExplain — no output change when explain is unset.
  • tsc --noEmit clean.

History

Fresh, focused resubmission of #433, which was closed on 2026-05-20 during a stale-backlog purge with the note to "open a fresh focused issue if it still reproduces on v2.5.1+". No explain parameter exists on current main, so the gap remains. Rebased onto current main (the rerank-aware query signature); the change is smaller now because main already exports HybridQueryExplain.

Add an optional "explain" boolean to the MCP query tool and the REST
/query (alias /search) endpoint. When enabled, each result carries the
retrieval score trace the SDK already computes: per-list FTS and vector
scores, the RRF fusion breakdown, and rerank blend weights.

SearchOptions.explain and HybridQueryResult.explain already exist in the
SDK (hybridQuery/structuredSearch compute the trace) — this only plumbs the
flag through the two MCP-facing surfaces and forwards the trace into each
result when present, reusing the exported HybridQueryExplain type. Default
is false, so output is unchanged for existing callers.

Useful for debugging query quality and tuning search ranking from MCP
clients without dropping down to the SDK.
@fxstein
fxstein force-pushed the feat/mcp-explain-param branch from a7df74e to 3fa91ac Compare June 29, 2026 09:03
@fxstein

fxstein commented Jun 29, 2026

Copy link
Copy Markdown
Contributor Author

Rebased onto current main (v2.6.3) to clear the merge conflict — the overlap was purely positional with #731 (plain query param), which landed in the same search tool block. The explain param slots in alongside query; the two are orthogonal. tsc --noEmit (test:types) passes clean. Ready for review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant