Skip to content

Commit db9fa81

Browse files
Slachaider-chat-bot
andcommitted
feat: append custom description to ClickHouse type in parameter details
Co-authored-by: aider (gemini/gemini-3-pro-preview) <[email protected]>
1 parent d0c9e7a commit db9fa81

File tree

3 files changed

+53
-2
lines changed

3 files changed

+53
-2
lines changed

docs/dynamic_tools.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,8 @@ COMMENT '{"analytics.user_sessions:description": "Get user session data", "user_
112112

113113
If the comment is not valid JSON, it is treated as a plain string description for the tool.
114114

115+
When a parameter description is provided via JSON, it is appended to the ClickHouse type in the tool's parameter description (e.g., "UInt64, The user ID to filter by").
116+
115117
## Type Mapping
116118

117119
ClickHouse types are automatically mapped to JSON Schema types for the MCP tool interface:

pkg/server/server.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -549,7 +549,7 @@ func (s *ClickHouseJWEServer) EnsureDynamicTools(ctx context.Context) error {
549549
for _, p := range meta.Params {
550550
desc := p.CHType
551551
if p.Description != "" {
552-
desc = p.Description
552+
desc = fmt.Sprintf("%s, %s", p.CHType, p.Description)
553553
}
554554
switch p.JSONType {
555555
case "boolean":
@@ -1033,7 +1033,7 @@ func (s *ClickHouseJWEServer) ServeOpenAPISchema(w http.ResponseWriter, r *http.
10331033
prop["format"] = p.JSONFormat
10341034
}
10351035
if p.Description != "" {
1036-
prop["description"] = p.Description
1036+
prop["description"] = fmt.Sprintf("%s, %s", p.CHType, p.Description)
10371037
} else {
10381038
prop["description"] = p.CHType
10391039
}

pkg/server/server_test.go

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1661,3 +1661,52 @@ func TestLazyLoading_MCPTools(t *testing.T) {
16611661
require.True(t, ok)
16621662
s.dynamicToolsMu.RUnlock()
16631663
}
1664+
1665+
func TestDynamicTool_ParamDescriptionFormat(t *testing.T) {
1666+
ctx := context.Background()
1667+
chConfig := setupClickHouseContainer(t)
1668+
1669+
// Create view with JSON comment
1670+
client, err := clickhouse.NewClient(ctx, *chConfig)
1671+
require.NoError(t, err)
1672+
defer func() { require.NoError(t, client.Close()) }()
1673+
_, _ = client.ExecuteQuery(ctx, "DROP VIEW IF EXISTS default.v_desc")
1674+
comment := `{"id": "The ID"}`
1675+
query := fmt.Sprintf("CREATE VIEW default.v_desc AS SELECT * FROM default.test WHERE id={id:UInt64} COMMENT '%s'", comment)
1676+
_, err = client.ExecuteQuery(ctx, query)
1677+
require.NoError(t, err)
1678+
1679+
cfg := config.Config{
1680+
ClickHouse: *chConfig,
1681+
Server: config.ServerConfig{
1682+
JWE: config.JWEConfig{Enabled: false},
1683+
DynamicTools: []config.DynamicToolRule{
1684+
{Regexp: "default\\.v_desc"},
1685+
},
1686+
},
1687+
}
1688+
1689+
s := NewClickHouseMCPServer(cfg, "test")
1690+
err = s.EnsureDynamicTools(ctx)
1691+
require.NoError(t, err)
1692+
1693+
// Verify OpenAPI schema description
1694+
rr := httptest.NewRecorder()
1695+
req := httptest.NewRequest("GET", "/openapi", nil)
1696+
s.ServeOpenAPISchema(rr, req)
1697+
1698+
var schema map[string]interface{}
1699+
require.NoError(t, json.Unmarshal(rr.Body.Bytes(), &schema))
1700+
paths := schema["paths"].(map[string]interface{})
1701+
path := paths["/{jwe_token}/openapi/default_v_desc"].(map[string]interface{})
1702+
post := path["post"].(map[string]interface{})
1703+
reqBody := post["requestBody"].(map[string]interface{})
1704+
content := reqBody["content"].(map[string]interface{})
1705+
jsonContent := content["application/json"].(map[string]interface{})
1706+
schemaObj := jsonContent["schema"].(map[string]interface{})
1707+
props := schemaObj["properties"].(map[string]interface{})
1708+
idProp := props["id"].(map[string]interface{})
1709+
1710+
// Check that description contains both type and custom description
1711+
require.Equal(t, "UInt64, The ID", idProp["description"])
1712+
}

0 commit comments

Comments
 (0)