Fix: Wrap tool results in TextContent format for MCP protocol compliance

The MCP protocol requires tool call results to be wrapped in content items
with type and text fields. This matches what other MCP servers do.

Before: {"result": [{"name": "testdb", ...}]}
After:  {"result": [{"type": "text", "text": "[{\"name\": \"testdb\", ...}]"}]}

This should fix the issue where Claude Code was timing out waiting for responses.
pull/5310/head
Rene Cannao 4 months ago
parent 55dd5ba574
commit 2b5134632c

@ -471,17 +471,22 @@ class StdioMCPServer:
debug_log(f"[tools/call] Unwrapped result:")
debug_log(f" {json.dumps(actual_result, indent=4)}")
log_separator("-")
# Wrap in TextContent for MCP protocol compliance
wrapped_result = [{"type": "text", "text": json.dumps(actual_result, indent=2)}]
debug_log(f"[tools/call] Wrapped in TextContent: {json.dumps(wrapped_result, indent=4)}")
return {
"jsonrpc": "2.0",
"result": actual_result,
"result": wrapped_result,
"id": req_id
}
# Fallback: return result as-is
debug_log(f"[tools/call] No wrapping detected, returning result as-is")
# Fallback: return result as-is, wrapped in TextContent
debug_log(f"[tools/call] No wrapping detected, wrapping result in TextContent")
wrapped_result = [{"type": "text", "text": json.dumps(proxysql_result, indent=2)}]
debug_log(f"[tools/call] Wrapped result: {json.dumps(wrapped_result, indent=4)}")
return {
"jsonrpc": "2.0",
"result": proxysql_result,
"result": wrapped_result,
"id": req_id
}

Loading…
Cancel
Save