Skip to content

Conversation

@twishabansal
Copy link
Contributor

@twishabansal twishabansal commented Jan 16, 2026

Context

When an MCP tool returns multiple JSON objects (e.g., database rows) as separate text chunks, tool_invoke
was concatenating them directly (e.g., {}{}), resulting in invalid JSON.

Changes

  • Updated tool_invoke in all MCP protocol versions (v20241105, v20250326, v20250618).
  • Added a heuristic: if multiple chunks all look like complete JSON objects (start/end with {}), they are now merged into a JSON list [{},{}].
  • Added regression tests to cover this case while maintaining existing behavior for standard text streams.

Fixes #503

@twishabansal twishabansal changed the title fix fix(toolbox-core): merge multiple JSON objects in MCP tool output Jan 16, 2026
@twishabansal twishabansal marked this pull request as ready for review January 16, 2026 04:25
@twishabansal twishabansal requested review from a team as code owners January 16, 2026 04:25
@twishabansal twishabansal changed the title fix(toolbox-core): merge multiple JSON objects in MCP tool output fix(mcp): merge multiple JSON objects in MCP tool output Jan 16, 2026
anubhav756
anubhav756 previously approved these changes Jan 19, 2026
@twishabansal twishabansal merged commit 1131664 into main Jan 19, 2026
26 checks passed
@twishabansal twishabansal deleted the mcp-concat-fix branch January 19, 2026 07:41
@release-please release-please bot mentioned this pull request Jan 16, 2026
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.

MCP transport produces invalid JSONs from the MCP Toolbox for Database ToolCalls

2 participants