feat(cli): add MongoDB aggregate query surface (CLI + MCP)#346
Open
kevinmessiaen wants to merge 18 commits into
Open
feat(cli): add MongoDB aggregate query surface (CLI + MCP)#346kevinmessiaen wants to merge 18 commits into
kevinmessiaen wants to merge 18 commits into
Conversation
The wrong-driver test's fake createConnector ignored the requested id and always returned a mongodb connector, so the driver guard never ran; the rejection came incidentally from assertConnection deep in the connector. It also asserted KtxQueryError, but the guard throws KtxExpectedError. Dispatch the fake by id and assert the guard's own error type and message. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01BdUJSmjqGoksdc45ZZJiVY
Expose the mongoQuery port as a callable MCP tool so agents can run aggregation pipelines against MongoDB connections directly, since MongoDB collections are not queryable via sql_execution.
Closes a coverage gap for the mongo_query MCP tool and fixes Knip's default-mode unused-export flag on KtxMongoQueryMcpPort, which had no cross-file consumer before this test imported it. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01BdUJSmjqGoksdc45ZZJiVY
Move formatValue/printJson/printPlain/printPretty/printResultTable and the KtxResultTable interface out of sql.ts into io/result-table.ts so the upcoming mongo-query command can reuse them verbatim.
Adds the strict mongo_query_completed schema (driver, isDemoConnection, stageCount, durationMs, outcome, errorClass) for the upcoming ktx mongo-query command, registered in both the catalog object and the name/description/fields catalog list, and mirrors it to the Python daemon schema copy.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
Route the Mongo read path through one canonical request/result shape and remove the `as unknown as` narrowing flagged in review. - Add optional executeQuery to KtxScanConnector and narrow by capability in the runner, replacing the double cast with a driver + method guard. - Move KtxMongoQueryInput/KtxMongoQueryResult into context/scan/types.ts; delete the duplicate runner request type, the inline MCP-port input, and the KtxMongoQueryResponse alias. KtxMongoQueryArgs now extends the base. - Inline the pass-through executeMongoQuery wrapper. - Correct the --output default in the mongo-query and sql CLI docs: it is TTY/CI/KTX_OUTPUT-derived, not unconditionally pretty. - Add tests: database override, empty result, parseLimitOption bounds, bigint/plural-row/empty-header rendering, and mongo_query_completed telemetry fields on both outcomes. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Ga2tvQ2YCEphmY8HM5Guzq
Now that KtxMongoQueryArgs extends KtxMongoQueryInput and the runner takes
that type, pass the args/input object straight through instead of rebuilding
it field by field. assertSafeConnectionId returns its input verbatim, so the
`{ ...input, connectionId }` spread was re-asserting an equal value.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Ga2tvQ2YCEphmY8HM5Guzq
kevinmessiaen
marked this pull request as ready for review
July 11, 2026 14:32
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a MongoDB aggregate query surface to ktx, exposed through both the CLI (
ktx mongo-query) and the MCP context tool (mongo_query), mirroring the existing SQL query path.mongoQuerycontext port contract, builds the port over the shared connector factory, and registers themongo_querytool.runKtxMongoQueryrunner, registers thektx mongo-querycommand, and exportsrunKtxMongoQueryas a public API to matchrunKtxSql.sql.tsintoio/result-table.tsso SQL and Mongo share one rendering path.mongo_query_completedevent (Node ↔ Python schema kept in parity).ktx mongo-querycommand.Notes
$out/$mergeare rejected at the top level; MongoDB itself forbids them in$facet/$lookup/$unionWithsub-pipelines, so the top-level check is sufficient.runMongoQueryexecution seam, used by both the CLI runner and the MCP port.Review & cleanup pass
The last two commits apply a multi-agent review of the branch:
executeQuery?now lives onKtxScanConnectoralongside the siblingexecuteReadOnly?, andKtxMongoQueryInput/KtxMongoQueryResultlive incontext/scan/types.tsnext to the SQL query types. The runner narrows to the connector by capability instead of anas unknown ascast, and the duplicate request/response type shapes and a pass-through wrapper were removed.--outputdefault is TTY/CI/KTX_OUTPUT-derived, not unconditionallypretty; corrected in both thektx mongo-queryandktx sqlreferences.parseLimitOptionbounds, thedatabaseoverride path, empty result sets,bigint/plural-row/empty-header rendering, andmongo_query_completedtelemetry field correctness on both the ok and error outcomes.Verification
🤖 Generated with Claude Code
https://claude.ai/code/session_01Ga2tvQ2YCEphmY8HM5Guzq