mcp-qsql-suggester
An MCP server that wraps a fine-tuned qSQL specialist (qwen) behind a
self-consistency pipeline — draw several independent candidates per call
(growing rounds, e.g. 4 -> 8 -> 16), gate each on raw q parse + KX
qlint C9, execute valid candidates against a dummy table built from the
caller's supplied table_schemas across multiple seeds, cluster by
cross-seed execution-equivalence, and return the shortest-code candidate
from the largest cluster. Designed for clients (e.g. Claude Code) that
want to delegate q/kdb+ qSQL drafting to a specialist model while still
catching structural errors — and reducing (not eliminating) the odds of
a single unlucky sample — before returning code to the user.
Self-consistency is the decoding method of Wang et al., ICLR
2023, which majority-votes over final
answers; here the vote is over cross-seed execution results instead.
The server exposes a single tool, generate_qsql. See
mcp_server/README.md for tool semantics, the
self-consistency clustering pipeline, environment variables, and
customer-UX guidance.
What the self-consistency pipeline buys you
Measured on a held-out set of 1078 qSQL tasks, holding the model fixed and
varying only the decoding strategy. A pass means the generated q executed against
dummy tables built from the task's declared schemas and its result matched the
task's reference implementation over the same tables, on all three seeded table
draws; anything that failed to parse, raised, timed out or returned a degenerate
result counts as a failure. On 9 tasks the reference itself raises on the dummy
tables; those count as failures for every row, so the denominator is 1078
throughout.
| decoding | pass | rate |
|---|
| single sample, greedy (temperature 0) | 554/1078 | 51.4% |
| single sample, temperature 0.8 | 509/1078 | 47.2% |
| self-consistency (this server), temperature 0.8 | 619/1078 | 57.4% |
| pass@16 ceiling — any of 16 samples passes | 791/1078 | 73.4% |
The comparison is paired — every row ran on the same tasks — and the margin
against either single-sample baseline is far outside sampling noise. The
significance tests, what the table implies beyond the headline rate, the caveats
behind it and where the tasks came from are in
How the benchmark was run below.
What it does not show is semantic correctness. passed=true means "ran
without raising, and independent samples agreed", never "matches what you asked
for" — see mcp_server/README.md for why closing that
gap is the caller's job, and why the generate_qsql tool is opt-in rather
than auto-routed. The two /qsql-coder skills are the opposite — they carry
that caller-side step, so Claude reaches for them on its own; see
Using the skills.
What is and is not in this release
In: the MCP server, the shared gate helpers, the client-side
/qsql-coder skills, the test suite, and tools/prepare_release.py.
Not in, and not planned:
- The training data and the fine-tuning pipeline. Neither is part of
this release and there are no plans to publish them, so please do not
open an issue asking for them — an issue asking for training data will
be closed with a link to this section.
- The model weights themselves, which are distributed separately —
see Prerequisites and
KxSystems/qsql-qwen35-9b
on Hugging Face. The server is not tied to them though —
SELF_HOSTING.md § "Using a different model" covers
pointing it at any OpenAI-compatible endpoint, and what you give up by
doing so.
- kdb+/q, pykx and KX's
qlint.q_, which are licensed separately.
Supply your own copies.
Prerequisites
Which file owns which requirement — there are no version numbers repeated
here on purpose, so there is only ever one place to change them:
This project assumes you are self-hosting. There is no public endpoint to
point a client at; the only client-side setup that matters is the one you hand
to colleagues once your own server is up (see
"Point your client at your server").
If you are hosting the server