Repository navigation
Add opt-in Agents Schema context to run_query results - #231
felipempleite wants to merge 7 commits into
Conversation
6367c54 to
e85ad0e
Compare
653e100 to
6eeba99
Compare
6eeba99 to
974f41b
Compare
|
Hi @joe-clickhouse! Would you or someone else on the team be able to review this? It adds opt-in Agents Schema context to query results, with existing behavior unchanged by default. Local tests are passing; validation and limitations are in the description. Could you also approve the CI runs? Thanks! |
|
Hi @felipempleite yes thanks. I'll take a look today. |
|
Hey @felipempleite thanks for the work and thorough tests. I really appreciate the work here. However, I'm going to pass on this PR because I think the approach isn't quite right, even if the remaining bugs were fixed. I think context should be exposed through discovery or semantic tools. That's how this server works and almost every one one as well. Agents Schema's own consumer starts at Also, this implementation specifically, I did some testing on a live ClickHouse server and as it stand its showed a few limitations:
I think our first attempt here should be much smaller in scope and complexity. Let's start with a sentence in the server instructions telling agents to read Help to discuss further if you want to create an issue for it or even open up another PR trying the simple approach first. Thanks! |
Summary
Adds opt-in reference context to successful
run_queryresults: governed model descriptions from canonicalAGENTS.DBT_MODEL, anAGENTS.ROOTdiscovery hint, and conditional engine guidance for ReplacingMergeTree and CollapsingMergeTree families, including Shared and Replicated variants.Enable with
CLICKHOUSE_MCP_AGENTS_SCHEMA_DISCOVERY=truebefore startup. Disabled servers retain the upstream response shape and tool description; server-wide MCP instructions are unchanged.ClickHouse publishing is merged in dbt-labs/agents_schema#40. This consumer uses the standard's case-sensitive uppercase
AGENTS.*names.Why
A successful query can still produce misleading analysis if an agent misses the model's business definitions.
Returning relevant Agents Schema descriptions and engine warnings alongside query results helps agents interpret the data and recognize when a query needs refinement, without relying on them to discover metadata separately. The feature is opt-in, preserving existing behavior for deployments that do not need it.
Behavior and compatibility
(database, table)pairs; bare names require a known current database. Clients with a stateful HTTP session skip all enrichment, including qualified references, so an optional lookup cannot occupy the session after the caller's wait ends and break a subsequent query. This also avoids temporary-table shadowing. Sessions are never removed or replaced to obtain metadata.AGENTSreferences are not enriched; 8000 system metadata references are excluded from matching. Engine advice is conditional, so a query already accounting for row versions, deletion markers, or collapsed rows is not told unconditionally to addFINAL. Explicit deduplication for ReplacingMergeTree withis_deletedmust exclude deleted rows after selecting the latest version.Limitations
WITH, nested comments, more than 65,536 characters, or more than 32 distinct references are skipped, as are table functions and unsupported references. Ambiguous keyword expressions or references (such asON join BETWEEN ...) skip enrichment entirely; quoting or qualifying keyword-named columns avoids that ambiguity, and operator-like table names should be quoted or qualified.schema_name.name; physical aliases remain an upstream limitation tracked in agents_schema#41.Validation
EXPLAIN ASTcovered 614 parser-accepted SQL cases, with no spurious table references from the scanner.readonly=1accounts before the fixes, then passed afterward.FINAL..env-enabled discovery with modern and legacy MCP clients.GitHub Actions may still require maintainer approval for this fork; the results above are local validation.