Skip to content

feat(mcp): expose chunkStrategy on the MCP query tool and HTTP /query - #1090

Open
rymalia wants to merge 2 commits into
tobi:mainfrom
rymalia:feat/mcp-chunk-strategy
Open

rymalia wants to merge 2 commits into
tobi:mainfrom
rymalia:feat/mcp-chunk-strategy

Conversation

@rymalia

@rymalia rymalia commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

The CLI has had AST-aware chunking for qmd query since #449 (--chunk-strategy auto), but the MCP query tool and the HTTP POST /query and /search endpoints had no way to ask for it. An agent searching an indexed code collection over MCP always got regex passage boundaries, even when the vectors had been embedded with qmd embed --chunk-strategy auto.

This PR adds an optional chunkStrategy: "auto" | "regex" to all three surfaces and forwards it to store.search(), which already supports the option.

Changes

  • MCP query tool: the schema gains chunkStrategy (z.enum(["auto", "regex"]).optional()), and the handler forwards it next to filter, intent and rerank. If it's omitted, behavior is unchanged (regex).
  • Server instructions: one line tells agents to pass chunkStrategy: 'auto' for indexed code.
  • HTTP POST /query and /search: accept the same field. Any value other than "auto" or "regex" gets a 400 {"error": "Invalid field: chunkStrategy (must be \"auto\" or \"regex\")"}, in the same style as the existing filter validation.
  • Docs: a README MCP-parameter row, a short note in skills/qmd/SKILL.md, and an [Unreleased] changelog entry.

Tests

test/mcp.test.ts adds a TypeScript fixture whose function boundaries put the query terms in different passages under each strategy. regex chunking selects the passage containing alpha, and auto (AST) selects the one containing beta/gamma. Each test checks which passage was selected, not just that the call succeeded:

  • MCP query tool: regex and auto return different lines and snippets.
  • REST /query and /search: the same comparison for valid values, plus a 400 with the exact error body for an invalid value.

I checked that the tests fail without the change: removing either forwarding line (MCP or REST) makes the matching test fail.

The fixture relies on the default chunk size and overlap (3,600 / 540 characters) and the 300-character snippet window, so a change to those constants would need the fixture adjusted.

Verification

The MCP query tool gained chunkStrategy in the previous commit, but the
REST handler that serves /query and /search built its store.search()
call without it, so HTTP callers could not opt into AST-aware passage
selection. Accept "auto" or "regex", forward it, and reject any other
value with a 400 in the same style as the filter validation.

Replace the schema-only assertion with tests that prove the strategy
reaches passage selection: a TypeScript fixture where regex chunking
picks the "alpha" passage and AST chunking picks "beta"/"gamma", run
through both the MCP tool and both REST paths. Removing either
forwarding line makes the matching test fail.
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