Skip to content

fix: accept singular query in ctx_search input schema - #1207

Open
rubenmarcus wants to merge 1 commit into
mksglu:mainfrom
rubenmarcus:fix/ctx-search-singular-query
Open

rubenmarcus wants to merge 1 commit into
mksglu:mainfrom
rubenmarcus:fix/ctx-search-singular-query

Conversation

@rubenmarcus

Copy link
Copy Markdown

ctx_search answers { query: "some search" } with Error: provide query or queries. even though the handler normalizes the singular form. The field never made it into the Zod input schema, so the MCP SDK's argument validation strips it before the handler runs: the TS SDK validates tool arguments with safeParseAsync and a Zod object parse drops unknown keys. The normalize block at src/server.ts:2617-2623 (added in 43667c0, "accept both query (string) and queries (array)") is dead code on every schema-conforming host.

Fixes #1200.

Changes:

  • src/search/ctx-search-schema.ts: declare the optional query string alias next to queries, so the payload that survives validation matches the contract the handler already implements. Both DB modes get the field; sanitizeSchemaForStrictClients picks it up automatically.
  • tests/core/search-singular-query.test.ts: pins the schema layer. query is declared in both shared-DB modes and survives parse; the plural form, the [Bug]: ctx_search parameters incorrectly stringified by OpenCode adapter — Zod validation fails #627 bare-string lift, coercions, and defaults are unchanged.

Verification (RED to GREEN):

$ npx vitest run tests/core/search-singular-query.test.ts   # before the schema change
Tests  2 failed | 1 passed (3)

$ npx vitest run tests/core/search-singular-query.test.ts   # after
Tests  3 passed (3)

The neighboring suites are identical with and without this change on my machine: search-project-filter 6 passed / 13 failed both ways, and the server/search batch 501 passed / 175 failed both ways. Those failures are local-environment (they spawn build/server.js, which needs npm run build, and reproduce on pristine main at the same counts).

Prepared with AI assistance (GLM via Oh My Pi); reviewed before submission.

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.

[Bug]: ctx_search rejects singular 'query' param despite schema declaring it valid

1 participant