improvement(search): run Search MCP calls whose arguments have one reading, and log rejected ones
Merged
WA
1d ago+312+312+012345678901234567890123456789-1-1-0123456789
Summary
- The MCP SDK rejects a tool call whose arguments fail the input schema before the tool runs: the client gets
MCP error -32602, spends another round, and nothing is logged on our side. The Search MCP route now rewrites search arguments that fail the schema but have exactly one reading, before the SDK validates them:nativeQueries: []ā omitted- a
nulloptional native query field (e.g.kind: null) ā omitted - a top-level
providerthat names a provider ā thesourcefilter (whensourceis absent or the same); any other value is still rejected - a search filter (
startDate,endDate,modifiedAfter,modifiedBefore,sortBy,topK) that every native query carries with the same value ā the search's own filter
- Native queries that disagree on a filter (or where only some carry it) are still rejected, rather than guessing
- Arguments the schema already accepts reach the SDK unchanged, and tools/list is untouched (no schema or description change, so clients are not asked to re-approve the tools)
- Logs
Knowledge MCP tool input repaired(which repairs) andKnowledge MCP tool input rejected(field paths and issue codes, no values), so rejected calls become visible
Type of Change
- Improvement
Testing
- MCP client bench (Sonnet 5.5, 83 cases): 1.5% of attempts (30 of 1,992) hit a schema rejection on the current code; 13 of the 30 have one reading and are repaired by this change. Paired run against staging: results to follow in a comment
- New
lib/knowledge/mcp/route-handler.protocol.test.tssends JSON-RPC through the real route, SDK transport and Search MCP server: each repair fails on the base and passes here (each guard reverted and watched go red), both ambiguous-filter cases and a provider value that names no provider stay rejected, and calls to inherited-name tools (constructor,toString,__proto__) get an MCP error, not a 500 bunx vitest run lib/knowledge/mcp(60 passed), biome on changed files; type-check and audits in CI
Checklist
- Code follows project style guidelines
- Self-reviewed my changes
- Tests added/updated and passing (new tests pass the
test-auditauthoring gate) - No new warnings introduced
- I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)
š¤ Generated with Claude Code