feat(mcp): expose connectionId for Postgres/DuckDB direct queries#56720
Merged
georgemunyoro merged 2 commits intomasterfrom Apr 29, 2026
Merged
feat(mcp): expose connectionId for Postgres/DuckDB direct queries#56720georgemunyoro merged 2 commits intomasterfrom
georgemunyoro merged 2 commits intomasterfrom
Conversation
Contributor
Prompt To Fix All With AIThis is a comment left during a code review.
Path: services/mcp/src/schema/tool-inputs.ts
Line: 368-387
Comment:
**`sendRawQuery` not forwarded to validate**
`query-run` now accepts `sendRawQuery: true` (on `HogQLQuerySchema`) to pass native SQL straight through to the external source without HogQL translation. `query-validate`, however, has no equivalent flag, so an agent writing native Postgres/DuckDB SQL cannot validate it before executing — it would be parsed as HogQL and likely return misleading errors.
If the backend `HogQLMetadata` endpoint supports `sendRawQuery`, adding the field to `QueryValidateInputSchema` and forwarding it in `client.ts`'s `validate()` would close that workflow gap.
How can I resolve this? If you propose a fix, please make it concise.Reviews (1): Last reviewed commit: "feat(mcp): pass connectionId to query-ru..." | Re-trigger Greptile |
3468b9d to
688b6fa
Compare
mariusandra
approved these changes
Apr 29, 2026
688b6fa to
1cfd0bf
Compare
…irect connections Postgres / DuckDB direct-query connections are fully supported on the backend (HogQLQuery, HogQLMetadata, and DatabaseSchemaQuery all accept connectionId), but the MCP-side zod schemas didn't include the field — so any agent attempt to target a direct source got silently downgraded to ClickHouse. Add connectionId to: - HogQLQuerySchema (flows through query-run automatically since the field is part of QueryRunInputSchema's discriminated union). - QueryValidateInputSchema and the typed validate() client method. - HogQLSchemaInputSchema and the hogql-schema handler, which calls DatabaseSchemaQuery with the id. Tool descriptions point agents at external-data-sources-list for discovering connection ids.
1cfd0bf to
f439e41
Compare
Contributor
There was a problem hiding this comment.
Pull request overview
This PR exposes connectionId in the MCP-side Zod schemas (and forwards it through handlers) so MCP clients can target Postgres/DuckDB direct-query external data sources instead of being silently downgraded to ClickHouse.
Changes:
- Added optional
connectionIdto the HogQL-shaped MCP input schemas (HogQLQuery,query-validate,hogql-schema). - Forwarded
connectionIdthrough the MCP handlers into the API client request bodies for validate/schema flows. - Updated tool descriptions and regenerated JSON schema artifacts/snapshots to reflect the new field.
Reviewed changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| services/mcp/src/schema/query.ts | Adds connectionId to HogQLQuerySchema. |
| services/mcp/src/schema/tool-inputs.ts | Adds connectionId to HogQLSchemaInputSchema and QueryValidateInputSchema. |
| services/mcp/src/tools/query/validate.ts | Plumbs connectionId from tool params into api.insights().validate(...). |
| services/mcp/src/tools/query/schema.ts | Adds params typing and forwards connectionId into DatabaseSchemaQuery request body. |
| services/mcp/src/api/client.ts | Adds optional connectionId to validate() and conditionally includes it in the HogQLMetadata body. |
| services/mcp/schema/tool-inputs.json | Regenerated schema JSON to include connectionId in relevant inputs. |
| services/mcp/schema/tool-definitions.json | Updates tool descriptions to document connectionId usage and discovery. |
| services/mcp/schema/tool-definitions-all.json | Same description updates in the “all” bundle. |
| services/mcp/tests/unit/snapshots/tool-schemas/v1/query-run.json | Snapshot updated to include connectionId in the HogQLQuery shape(s). |
| services/mcp/tests/unit/snapshots/tool-schemas/v1/query-validate.json | Snapshot updated to include connectionId. |
| services/mcp/tests/unit/snapshots/tool-schemas/v1/hogql-schema.json | Snapshot updated to include connectionId. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
inkeep Bot
added a commit
to PostHog/posthog.com
that referenced
this pull request
Apr 29, 2026
…ces via MCP Reflects PostHog/posthog#56720 which exposes connectionId on query-run, query-validate, and hogql-schema MCP tools for Postgres/DuckDB direct queries.
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.
Problem
Postgres and DuckDB direct-query data warehouse connections are fully supported on the backend (
HogQLQuery,HogQLMetadata, andDatabaseSchemaQueryall acceptconnectionId), but the MCP-side zod schemas didn't include the field. zod strips unknown keys by default, so any agent attempt to target a direct source got silently downgraded to ClickHouse — making the entire direct-query feature invisible from MCP clients.Changes
Pass
connectionIdthrough the three HogQL-shaped MCP tools:query-run— addedconnectionIdtoHogQLQuerySchema. Flows through automatically since the schema is part ofQueryRunInputSchema's discriminated union.query-validate— addedconnectionIdtoQueryValidateInputSchemaand forwarded through the typedvalidate()client method.hogql-schema— addedconnectionIdtoHogQLSchemaInputSchemaand forwarded into theDatabaseSchemaQuerybody.Tool descriptions now point agents at
external-data-sources-listto discover available connection ids.sendRawQuery(native-SQL passthrough onHogQLQuery) was considered but deliberately deferred: the backendHogQLMetadataschema isextra="forbid"with no equivalent field, so exposingsendRawQueryonquery-runwithout a matching path onquery-validatewould break the validate-first pattern this work is built around. Add to both at once when the backend metadata path supports raw-query validation.How did you test this code?
Automated tests only — I'm an agent, no manual MCP Inspector / Claude Desktop runs.
pnpm --filter=@posthog/mcp typecheckis clean.Publish to changelog?
Yes.
🤖 LLM context
Co-authored with Claude Code in the same session as #56185. The bug was discovered while listing follow-up MCP work — the backend already accepted
connectionIdend-to-end, but no MCP tool exposed it.