Repository navigation
return json strings from query results instead of dicts - #154
Conversation
mcp protocol requires tool results to be strings but execute_query and run_query were returning raw dicts, causing validation errors on every successful response. also fixes large UInt64 values getting corrupted since json.dumps with default=str serializes them properly fixes ClickHouse#141, helps with ClickHouse#111
There was a problem hiding this comment.
Pull request overview
This PR aims to make MCP tool outputs conform to the MCP protocol’s expectation of string (TextContent) results by JSON-encoding query outputs to avoid output validation errors.
Changes:
- JSON-encode
execute_querysuccessful results viajson.dumps(..., default=str). - JSON-encode the (currently unreachable) error-structure return path in
run_query.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
execute_query now returns a json string on success and raises ToolError on failure, so the dict error check never matched. the branch and its comment are misleading, drop them
|
thanks for the review removed the dead `isinstance(result, dict)` branch and the misleading comment about structured responses in 92a8eda for list_tables and run_chdb_select_query returning dicts - same root issue but feels beyond this PR's scope since it touches other tools and their tests. happy to follow up in a separate PR if maintainers want that fair catch on default=str, you're right it doesn't help UInt64 precision since python ints are already json-serializable. output_format_json_quote_64bit_integers=1 would be the proper fix but it changes the wire format for every int column, so i'd prefer to keep it a separate PR as well |
|
Hi @knQzx thanks for the work so far! A few comments from my end:
|
…ect_query unify tool return contract across all four MCP tools so responses are consistent JSON strings serialized with json.dumps(..., default=str). also drops the dead to_json helper.
|
@joe-clickhouse addressed your points
ready for another look |
|
Looks good! I think we're pretty much there. The only thing I forgot to ask is that you update the CHANGELOG as well, please. Thanks! |
omg, yes, did it! |
There was a problem hiding this comment.
Thanks for the contribution!
list_tables,execute_query, andrun_chdb_select_queryreturn dicts/lists but the MCP protocol expects strings, so every successful call triggers a validation error. Wrap all tool responses (including the already-correctlist_databases) injson.dumps(..., default=str). Thedefault=strhandles non-serializable types ClickHouse returns (e.g.datetime,UUID,Decimal, etc.). Also drop an unreachable error-dict branch inrun_queryand the unusedto_jsonhelper.fixes #141