Skip to content

fix(mcp): preserve structured-only federated tool results - #6456

Open
Ricky-7-Yan wants to merge 1 commit into
IBM:mainfrom
Ricky-7-Yan:fix/structured-only-tool-results
Open

fix(mcp): preserve structured-only federated tool results#6456
Ricky-7-Yan wants to merge 1 commit into
IBM:mainfrom
Ricky-7-Yan:fix/structured-only-tool-results

Conversation

@Ricky-7-Yan

Copy link
Copy Markdown

🐛 Bug-fix PR

📌 Summary

A successful federated tools/call result may carry all data in structuredContent while content is empty. The streamable-HTTP transport treated that valid shape as empty and returned before its existing structured-content handler.

The guard now returns early only when both representations are absent. Structured-only results reach the existing tuple response path, while genuinely empty results keep returning [].

Closes #5472

🔁 Reproduction

  1. Federate an upstream tool that declares an outputSchema.
  2. Have it return { "content": [], "structuredContent": { ... } }.
  3. Invoke it through the /mcp streamable-HTTP endpoint.
  4. Before this change the structured payload is discarded and the SDK reports an output-validation error.

📏 Reviewability

  • This PR has one clear purpose
  • The linked issue is not labeled triage
  • Unrelated bugs or improvements are tracked separately
  • Tests are included with the code they validate

🏷️ Type of Change

  • Bug fix

🧪 Verification

The new regression test was run before the source change and failed with result == [].

After the fix:

python -m pytest -q tests/unit/mcpgateway/transports/test_streamablehttp_transport.py -k "call_tool_success or with_structured_content or structured_only_result or neither_representation_exists or preserves_is_error_for_egress"
5 passed

Ruff 0.15.20 passes for the changed source and the changed test while excluding two unrelated violations already present elsewhere in the 17k-line test module (E303 at line 9639 and PLC2801 at line 17055). The source file passes formatting; the test module has two pre-existing formatting differences outside this change.

✅ Checklist

  • Tests added for structured-only and genuinely empty results
  • No secrets or credentials committed
  • Commit includes the required DCO sign-off

Signed-off-by: Ricky-7-Yan <2314530442@qq.com>
@felixandersen

Copy link
Copy Markdown

FWIW I have been running this patch successfully in my environment. Fixed the issue for me.

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.

Federated tool results with structuredContent + empty content are dropped (Output validation error for every outputSchema tool)

2 participants