Skip to content

feat(tool/clickhouse-execute-sql): bind query parameters on the server - #4354

Merged
anubhav756 merged 4 commits into
googleapis:mainfrom
Mordris:feat/clickhouse-execute-sql-params
Nov 16, 2026
Merged

anubhav756 merged 4 commits into
googleapis:mainfrom
Mordris:feat/clickhouse-execute-sql-params

Conversation

@Mordris

@Mordris Mordris commented Oct 28, 2026

Copy link
Copy Markdown
Contributor

Description

clickhouse-execute-sql runs its statement with no parameters, so a {name:Type} placeholder can
never be satisfied and the query fails with Substitution `name` is not set
(UNKNOWN_QUERY_PARAMETER). Because the tool declares only sql, a params argument an agent
sends is silently dropped and the same error comes back, with no signal that the values went
nowhere. That leaves building the value into the SQL text as the only option. clickhouse-sql is
not a substitute: it binds ? placeholders client-side from a configured statement, so it cannot
bind an identifier and is not aimed at agent-written SQL.

Solution. An optional params object, as arcadedb-execute-sql already has, maps placeholder
names to values in ClickHouse's text format. Each is sent as param_<name> through
clickhouse-go's WithParameters, so the server parses it as the placeholder's declared type.
Identifier parameters ({t:Identifier}) work the same way. The parameters are attached to the
context, so the source's RunSQL(ctx, statement, nil) signature is untouched and no other source
or tool is affected.

{
  "sql": "SELECT count() FROM {table:Identifier} WHERE created_at >= {since:Date} AND status = {status:String}",
  "params": { "table": "events", "since": "2024-01-31", "status": "open" }
}

Impact. Without params nothing changes: toQueryParameters returns nil, the context is left
alone, and the statement runs exactly as it does today.

Security. Flagging this explicitly, since the change touches a tool implementation. It exists
to remove a query-injection pattern rather than introduce one: no tool parameter is concatenated or
fmt.Sprintf-ed into the statement, and each value is bound by the server, which parses it as its
declared type and never as SQL. Measured against ClickHouse 26.9.19.9:

  • {v:String} given 1'); DROP TABLE t; -- comes back as that string.
  • {t:Identifier} given events; DROP TABLE other is quoted as a single identifier and fails with
    UNKNOWN_TABLE, with both tables still present afterwards.
  • A wrong type gives a clear server error:
    Value abc cannot be parsed as UInt32 for query parameter 'n'.

This also gives a structural alternative to the approach #3219 needed for identifiers, which
validates a database name against ^[A-Za-z_][A-Za-z0-9_]*$ before interpolating it. No
credentials or secrets are read, logged or echoed back, and no auth getters are overridden.

One open design question, carried over from #4289, that I'd still value your call on.

params is an object of strings, each in ClickHouse's text format for its declared type
("42", "2024-01-31", "['a','b']"). Strings keep it unambiguous and let every ClickHouse type
work, but they push formatting onto the caller. The alternative is accepting native JSON types and
converting, which is friendlier for scalars but needs a mapping for arrays, tuples and maps. I went
with strings to avoid owning that conversion table — if you'd rather have native types, say so and
I'll change it; the conversion is contained to toQueryParameters.

PR Checklist

  • Make sure you reviewed
    CONTRIBUTING.md
  • Make sure to open an issue as a
    bug/issue
    before writing your code! — clickhouse-execute-sql: no way to bind {name:Type} query parameters #4289
  • Ensure you have manually reviewed the entire diff before requesting a
    review
  • Ensure the tests and linter pass — go build ./..., go vet,
    goimports -l ., go mod tidy, golangci-lint run (0 issues) and
    go test -race ./cmd/... ./internal/... all pass locally (417 packages, no races). The
    integration test needs a live ClickHouse.
  • Code coverage does not decrease (if any source code was changed) —
    toQueryParameters is covered by unit tests including both error paths, and a manifest test
    asserts params is declared and optional
  • Appropriate docs were updated (if necessary) — the clickhouse-execute-sql page gains the
    params row and a note on binding identifiers
  • Make sure to add ! if this involve a breaking change — not a breaking change: params is
    optional and absent by default, and behaviour without it is unchanged

🛠️ Fixes #4289

clickhouse-execute-sql ran its statement without parameters, so a value
had to be spliced into the SQL text, and a {name:Type} placeholder
failed with "Substitution `name` is not set". clickhouse-sql binds ?
placeholders on the client, which cannot bind identifiers.

An optional params object, as arcadedb-execute-sql has, now binds
ClickHouse query parameters: each value, in ClickHouse's text format,
is sent as param_<name> through clickhouse-go's WithParameters, and the
server parses it as the placeholder's type, never as SQL. Identifier
parameters ({t:Identifier}) work the same way. Without params the tool
behaves as before.
@Mordris
Mordris requested a review from a team as a code owner October 28, 2026 06:59

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request adds support for optional query parameters (params) to the clickhouse-execute-sql tool, updating the documentation, implementation, and tests accordingly. Feedback on the changes suggests preserving the original error context when handling parsing errors in toQueryParameters, and replacing t.Context() with context.Background() in tests to maintain compatibility with Go 1.23 as specified in the style guide.

…parse

util.NewAgentError stores its second argument as Cause, which Error()
appends and Unwrap() returns, so passing nil dropped the unwrap chain
without making the message any clearer. The message is now a fixed
prefix and the cause carries the detail, which Error() still renders in
full, so errors.Is and errors.As reach the parse failure.
@anubhav756

Copy link
Copy Markdown
Contributor

/gcbrun

@anubhav756

Copy link
Copy Markdown
Contributor

/gcbrun

@anubhav756
anubhav756 merged commit ef822ce into googleapis:main Nov 16, 2026
31 of 32 checks passed
AlexTalreja added a commit that referenced this pull request Nov 20, 2026
🤖 I have created a release *beep* *boop*
---


##
[1.18.0](v1.17.0...v1.18.0)
(2026-11-20)


### Features

* **tool/clickhouse-execute-sql:** Bind query parameters on the server
([#4354](#4354))
([ef822ce](ef822ce))


### Bug Fixes

* **auth/google:** Require clientId when mcpEnabled is false
([#3676](#3676))
([a5dc5d4](a5dc5d4))
* **cmd:** Run telemetry shutdown with an uncanceled bounded context
([#4148](#4148))
([dcdbbae](dcdbbae))
* **config:** Reject multiple mcpEnabled auth services of any type
([#4542](#4542))
([db52312](db52312))
* **parameters:** Copy valueFromParam from the resolved source value
([#4541](#4541))
([5a36ba0](5a36ba0))
* **parameters:** Enforce full-input matching in MatchStringOrRegex
([#4522](#4522))
([7f366ff](7f366ff))
* **parameters:** Reject delimiters and backslashes in applyEscape
([#4523](#4523))
([a3d013f](a3d013f))
* **prebuilt/sqlite:** Bind query parameters in list_tables
([#4535](#4535))
([9a8a4f0](9a8a4f0))
* **resource/file:** Enforce URI template prefix, suffix, and directory
boundary
([#4538](#4538))
([5e894e4](5e894e4))
* **server,tool/conversational-analytics:** Resolve CodeQL dynamic call
and allocation alerts
([#4489](#4489))
([3bb1e24](3bb1e24))
* **server/mcp:** Preserve integer argument precision
([#4435](#4435))
([a09d12d](a09d12d))
* **skills:** Run npx without cmd.exe in generated Windows scripts
([#4543](#4543))
([ae8f790](ae8f790))
* **source/cloudmonitoring:** Validate projectId before building the
query URL
([#4544](#4544))
([6b3d6b4](6b3d6b4))
* **source/databaseinsights:** Validate parent resource name before
building endpoint
([#4532](#4532))
([0e9fc2f](0e9fc2f))
* **source/mssql,source/cloudsqlmssql:** Include the server's messages
in severe errors
([#4445](#4445))
([d6b2bd7](d6b2bd7))
* **sqlite:** Preserve JSON number precision in tool results
([#4431](#4431))
([ff59dce](ff59dce))
* **tool/bigquery-analyze-contribution:** Apply maximumBytesBilled to
CREATE TEMP MODEL job
([#4531](#4531))
([d7fd6c5](d7fd6c5))
* **tool/postgres-database-overview:** Count only client backends as
connections
([#4463](#4463))
([9a17f8b](9a17f8b))
* **tool/postgres-get-column-cardinality:** Return one row per column
for tables with inheritance children
([#4413](#4413))
([1cb1952](1cb1952))
* **tool/postgres-list-indexes:** Include indexes on materialized views
([#4504](#4504))
([2253fe7](2253fe7))
* **tool/postgres-list-roles:** Escape underscore in system role filters
([#4380](#4380))
([05f20fe](05f20fe))
* **tool/postgres-replication-stats:** Support running replication_stats
and list_replication_slots on a standby
([#4471](#4471))
([2b6d51f](2b6d51f))
* **tool/redis,tool/valkey:** Send integer, float and boolean parameters
as their value
([#4378](#4378))
([6fe3da9](6fe3da9))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

---------

Co-authored-by: release-please[bot] <55107282+release-please[bot]@users.noreply.github.com>
Co-authored-by: Juexin Wang <[email protected]>
Co-authored-by: alextalreja <[email protected]>
Co-authored-by: Alex Talreja <[email protected]>
github-actions Bot pushed a commit that referenced this pull request Nov 20, 2026
🤖 I have created a release *beep* *boop*
---

##
[1.18.0](v1.17.0...v1.18.0)
(2026-11-20)

### Features

* **tool/clickhouse-execute-sql:** Bind query parameters on the server
([#4354](#4354))
([ef822ce](ef822ce))

### Bug Fixes

* **auth/google:** Require clientId when mcpEnabled is false
([#3676](#3676))
([a5dc5d4](a5dc5d4))
* **cmd:** Run telemetry shutdown with an uncanceled bounded context
([#4148](#4148))
([dcdbbae](dcdbbae))
* **config:** Reject multiple mcpEnabled auth services of any type
([#4542](#4542))
([db52312](db52312))
* **parameters:** Copy valueFromParam from the resolved source value
([#4541](#4541))
([5a36ba0](5a36ba0))
* **parameters:** Enforce full-input matching in MatchStringOrRegex
([#4522](#4522))
([7f366ff](7f366ff))
* **parameters:** Reject delimiters and backslashes in applyEscape
([#4523](#4523))
([a3d013f](a3d013f))
* **prebuilt/sqlite:** Bind query parameters in list_tables
([#4535](#4535))
([9a8a4f0](9a8a4f0))
* **resource/file:** Enforce URI template prefix, suffix, and directory
boundary
([#4538](#4538))
([5e894e4](5e894e4))
* **server,tool/conversational-analytics:** Resolve CodeQL dynamic call
and allocation alerts
([#4489](#4489))
([3bb1e24](3bb1e24))
* **server/mcp:** Preserve integer argument precision
([#4435](#4435))
([a09d12d](a09d12d))
* **skills:** Run npx without cmd.exe in generated Windows scripts
([#4543](#4543))
([ae8f790](ae8f790))
* **source/cloudmonitoring:** Validate projectId before building the
query URL
([#4544](#4544))
([6b3d6b4](6b3d6b4))
* **source/databaseinsights:** Validate parent resource name before
building endpoint
([#4532](#4532))
([0e9fc2f](0e9fc2f))
* **source/mssql,source/cloudsqlmssql:** Include the server's messages
in severe errors
([#4445](#4445))
([d6b2bd7](d6b2bd7))
* **sqlite:** Preserve JSON number precision in tool results
([#4431](#4431))
([ff59dce](ff59dce))
* **tool/bigquery-analyze-contribution:** Apply maximumBytesBilled to
CREATE TEMP MODEL job
([#4531](#4531))
([d7fd6c5](d7fd6c5))
* **tool/postgres-database-overview:** Count only client backends as
connections
([#4463](#4463))
([9a17f8b](9a17f8b))
* **tool/postgres-get-column-cardinality:** Return one row per column
for tables with inheritance children
([#4413](#4413))
([1cb1952](1cb1952))
* **tool/postgres-list-indexes:** Include indexes on materialized views
([#4504](#4504))
([2253fe7](2253fe7))
* **tool/postgres-list-roles:** Escape underscore in system role filters
([#4380](#4380))
([05f20fe](05f20fe))
* **tool/postgres-replication-stats:** Support running replication_stats
and list_replication_slots on a standby
([#4471](#4471))
([2b6d51f](2b6d51f))
* **tool/redis,tool/valkey:** Send integer, float and boolean parameters
as their value
([#4378](#4378))
([6fe3da9](6fe3da9))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

---------

Co-authored-by: release-please[bot] <55107282+release-please[bot]@users.noreply.github.com>
Co-authored-by: Juexin Wang <[email protected]>
Co-authored-by: alextalreja <[email protected]>
Co-authored-by: Alex Talreja <[email protected]>
github-actions Bot pushed a commit to renovate-bot/googleapis-_-genai-toolbox that referenced this pull request Nov 21, 2026
🤖 I have created a release *beep* *boop*
---

##
[1.18.0](googleapis/mcp-toolbox@v1.17.0...v1.18.0)
(2026-11-20)

### Features

* **tool/clickhouse-execute-sql:** Bind query parameters on the server
([googleapis#4354](googleapis#4354))
([ef822ce](googleapis@ef822ce))

### Bug Fixes

* **auth/google:** Require clientId when mcpEnabled is false
([googleapis#3676](googleapis#3676))
([a5dc5d4](googleapis@a5dc5d4))
* **cmd:** Run telemetry shutdown with an uncanceled bounded context
([googleapis#4148](googleapis#4148))
([dcdbbae](googleapis@dcdbbae))
* **config:** Reject multiple mcpEnabled auth services of any type
([googleapis#4542](googleapis#4542))
([db52312](googleapis@db52312))
* **parameters:** Copy valueFromParam from the resolved source value
([googleapis#4541](googleapis#4541))
([5a36ba0](googleapis@5a36ba0))
* **parameters:** Enforce full-input matching in MatchStringOrRegex
([googleapis#4522](googleapis#4522))
([7f366ff](googleapis@7f366ff))
* **parameters:** Reject delimiters and backslashes in applyEscape
([googleapis#4523](googleapis#4523))
([a3d013f](googleapis@a3d013f))
* **prebuilt/sqlite:** Bind query parameters in list_tables
([googleapis#4535](googleapis#4535))
([9a8a4f0](googleapis@9a8a4f0))
* **resource/file:** Enforce URI template prefix, suffix, and directory
boundary
([googleapis#4538](googleapis#4538))
([5e894e4](googleapis@5e894e4))
* **server,tool/conversational-analytics:** Resolve CodeQL dynamic call
and allocation alerts
([googleapis#4489](googleapis#4489))
([3bb1e24](googleapis@3bb1e24))
* **server/mcp:** Preserve integer argument precision
([googleapis#4435](googleapis#4435))
([a09d12d](googleapis@a09d12d))
* **skills:** Run npx without cmd.exe in generated Windows scripts
([googleapis#4543](googleapis#4543))
([ae8f790](googleapis@ae8f790))
* **source/cloudmonitoring:** Validate projectId before building the
query URL
([googleapis#4544](googleapis#4544))
([6b3d6b4](googleapis@6b3d6b4))
* **source/databaseinsights:** Validate parent resource name before
building endpoint
([googleapis#4532](googleapis#4532))
([0e9fc2f](googleapis@0e9fc2f))
* **source/mssql,source/cloudsqlmssql:** Include the server's messages
in severe errors
([googleapis#4445](googleapis#4445))
([d6b2bd7](googleapis@d6b2bd7))
* **sqlite:** Preserve JSON number precision in tool results
([googleapis#4431](googleapis#4431))
([ff59dce](googleapis@ff59dce))
* **tool/bigquery-analyze-contribution:** Apply maximumBytesBilled to
CREATE TEMP MODEL job
([googleapis#4531](googleapis#4531))
([d7fd6c5](googleapis@d7fd6c5))
* **tool/postgres-database-overview:** Count only client backends as
connections
([googleapis#4463](googleapis#4463))
([9a17f8b](googleapis@9a17f8b))
* **tool/postgres-get-column-cardinality:** Return one row per column
for tables with inheritance children
([googleapis#4413](googleapis#4413))
([1cb1952](googleapis@1cb1952))
* **tool/postgres-list-indexes:** Include indexes on materialized views
([googleapis#4504](googleapis#4504))
([2253fe7](googleapis@2253fe7))
* **tool/postgres-list-roles:** Escape underscore in system role filters
([googleapis#4380](googleapis#4380))
([05f20fe](googleapis@05f20fe))
* **tool/postgres-replication-stats:** Support running replication_stats
and list_replication_slots on a standby
([googleapis#4471](googleapis#4471))
([2b6d51f](googleapis@2b6d51f))
* **tool/redis,tool/valkey:** Send integer, float and boolean parameters
as their value
([googleapis#4378](googleapis#4378))
([6fe3da9](googleapis@6fe3da9))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

---------

Co-authored-by: release-please[bot] <55107282+release-please[bot]@users.noreply.github.com>
Co-authored-by: Juexin Wang <[email protected]>
Co-authored-by: alextalreja <[email protected]>
Co-authored-by: Alex Talreja <[email protected]>
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.

clickhouse-execute-sql: no way to bind {name:Type} query parameters

3 participants