Repository navigation
feat: expose the whole catalog filter surface over MCP - #1429
Conversation
📦 Package PreviewYour package is ready to test! bun install -g nemar-cli@PR1429Version: 🤖 Updated on each push. |
Review folded inTwo reviewers. One would have blocked the merge, correctly, and the other found a test I wrote that could not fail. Both are fixed. The block: generated descriptions misstated the syntax for 9 of 20 facetsMy generator had three branches for five
That is this pull request's own bug class one layer up: a filter that was applied correctly, to something other than what the caller meant. Worse, it was a re-regression. Fixed by lifting A test of mine that could not fail
Replaced with the collision and count check the other reviewer asked for, which is the gap all three declaration tests shared: a future facet whose Also fixed
CorrectedThere are 20 facets, not 21 as the description above said. I had counted the Not in this pull requestBoth reviewers independently found that no test invokes |
The prompt said the filters are exactly query, modality, task, has_hed, has_zarr and limit, that there is NO participant-count filter, and to pass only those six names. nemarOrg/nemar-cli#1429 takes the surface to 33 parameters and is in the release now being promoted to production, so all three statements become false the moment it ships. The third is the damaging one: it tells the model not to use filters that work, so a question about channel counts or participant numbers takes a worse route or gets refused, and nothing looks broken. Rather than swapping one list for a longer list that goes stale the same way, the prompt now points at the tool schema, which the server generates from its facet definitions. The warning that matters is kept and is not a function of how many filters exist: an undeclared argument is accepted and silently ignored, so an invented name returns unfiltered results that look filtered. Partial: #370 asks for a whole-config rewrite and raises open questions about how much belongs in the prompt at all. This is the correctness fix the nemar-cli promotion forces, not that rewrite.
search_datasetsadvertised six parameters. The catalog can filter on far more, and the gap is what let the OSA assistant's prompt drift onto a parameter name that never existed.Why
The MCP tool already calls
buildDatasetFilterClauses, which understands eleven bespoke filters plus the twenty declared facets. It was passing four of them:modality,task,has_hed,has_zarr. Everything else the catalog can do was unreachable from an agent: author, license tier, DOI presence, fidelity-verified Zarr, data completeness, recency, and every facet inshared/facets.ts(subject and channel counts, sampling rate, duration, electrode system, BIDS and HED version, and the rest).The tool's input schema was hand-written, which is the real defect. ADR 0032 makes
shared/facets.tsthe single source of truth for which columns are filterable and has a test asserting both directions between it anddataset-facets.ts. The MCP schema was the one consumer that opted out, and it went stale: OSA's system prompt told the model to callnemar_search_datasets(modality_filter="EEG"). Because the schema is.passthrough(), the server accepted the undeclared argument and dropped it. Measured against production before this change:A researcher asking for MEG datasets got 92 mostly-EEG results presented as filtered, with nothing marking it. That prompt is fixed separately in OpenScience-Collective/osa#367; this is the half that stops the class of bug rather than the instance.
What
FACETS, so a newly declared facet reaches MCP callers the day it lands and cannot be forgotten.include_unknownso a caller can see what a partly-populated facet is excluding (ADR 0032's stated reason for that flag).parseFacetFilters, so range and enum syntax is validated once, in the same place as the HTTP route. A rejected value returns a tool error naming what it received and the accepted forms, rather than a bare validation failure.Wire surface goes from 6 parameters to 33, each carrying a description built from the facet's own
label,unitandenumValues.The trap this hit, worth knowing
searchDatasetsInputSchema4inbackend/src/mcp/schemas.tsis a hand-written zod 4 mirror, and it is whatregisterTooladvertises, so it is what the model actually reads. Widening only the zod 3 contract would have changed nothing on the wire.The existing parity tests could not catch that: they feed sample objects to both schemas, and both are
.passthrough(), so a key missing from one side is simply passed through rather than rejected. The new test compares the two declared shapes directly, which is the only form that bites.Test
Three mutation checks, because the tests that should have caught this drift could not fail:
channelsfrom the generated facet shape fails the facet-coverage test, namingchannels....facetInputShape4from the zod 4 mirror fails the new shape-parity test.DatasetFilterOptionswithout exposing it here is visible.MCP cluster: 321 pass, 0 fail.
bun run typecheckandbiomeclean.backend/scripts/mcp-smoke.shunder real workerd: all required checks passed, tool list and calls still 200. Wire schema confirmed to carry the new parameters with generated descriptions, for examplechannelsreads "Channel count. Range:10..20,64..(at least), or..128(at most), in channels."Note for whoever touches
backend/src/next:bun run lintisbiome check src/and does not coverbackend/src/, so the pre-commit hook catches things the lint script does not. That is issue #936.