fix: serialize tool outputs as JSON strings for MCP protocol compliance#140
Open
gsttg wants to merge 1 commit intoClickHouse:mainfrom
Open
fix: serialize tool outputs as JSON strings for MCP protocol compliance#140gsttg wants to merge 1 commit intoClickHouse:mainfrom
gsttg wants to merge 1 commit intoClickHouse:mainfrom
Conversation
The MCP protocol requires tool results to be returned as strings (wrapped
in TextContent), but `run_query`, `list_tables`, and `run_chdb_select_query`
were returning Python dicts/lists directly, causing output validation errors
like: `Output validation error: {...} is not of type 'string'`.
`list_databases` already correctly used `json.dumps()` — this commit makes
all tool functions consistent by wrapping their return values with
`json.dumps(..., default=str)`.
Also removes dead error-check code in `run_query` that could never trigger
since `execute_query` raises `ToolError` on failure rather than returning
an error dict.
Co-Authored-By: Claude Opus 4.6 <[email protected]>
|
|
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.
Summary
run_queryandlist_tablesreturn Python dicts instead of JSON strings, causing MCP output validation errors on every successful call:Output validation error: {...} is not of type 'string'json.dumps(..., default=str)to match the pattern already used bylist_databasesexecute_query,list_tables(2 return paths), andrun_chdb_select_query(all return paths)run_query(errors already raiseToolError)list_tablesreturn type annotation fromDict[str, Any]tostrSee linked issue for full details and reproduction steps.
Test plan
json.loads(result.content[0].text)assertions pass (confirms output is valid JSON string)test_run_select_query_syntax_errorpasses (error handling unaffected)🤖 Generated with Claude Code