fix(mcp): preserve structured-only federated tool results - #6369
Open
feiiiiii5 wants to merge 1 commit into
Open
fix(mcp): preserve structured-only federated tool results#6369feiiiiii5 wants to merge 1 commit into
feiiiiii5 wants to merge 1 commit into
Conversation
MCP allows unstructured content to be empty when structuredContent is present. The streamable-HTTP transport treated an empty content array as an empty result and returned before reaching the structured-content handler, so every outputSchema tool backed by a structured-only upstream failed validation. Only return early when neither representation is present. Add regression coverage for structured-only success and the genuinely-empty fallback. Signed-off-by: fei <204683769+feiiiiii5@users.noreply.github.com>
feiiiiii5
requested review from
Lang-Akshay,
brian-hussey,
crivetimihai,
ja8zyjits and
msureshkumar88
as code owners
August 22, 2026 12:31
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.
🐛 Bug-fix PR
📌 Summary
A successful federated
tools/callresult may carry all of its data instructuredContentwhilecontentis empty. The MCP Tools specification makes unstructured content a SHOULD, not a MUST, when structured content is present. ContextForge's streamable-HTTP transport treated that valid shape as an empty result and returned before reaching the structured-content handler.For tools declaring an
outputSchema, the MCP SDK then substituted:The real structured payload never reached the client.
Closes #5472
🔁 Reproduction Steps
outputSchema.{ "content": [], "structuredContent": { ... } }from itstools/callresult./mcpstreamable-HTTP endpoint.The issue includes a standalone reproduction repository and before/after output.
🐞 Root Cause
After
invoke_tool()returned successfully, the early guard was:It ignored
result.structured_content. Structured-only results therefore returned[]before the later handler could assemble(unstructured, structured)for SDK validation.💡 Fix Description
Treat the result as empty only when both representations are absent:
Structured-only results now fall through to the existing handler and return
(unstructured, structured). Results with neither representation continue to return[].This is intentionally separate from #6182/#6274: those track preservation of an empty dict (
structuredContent: {}) in the service layer. This fix handles non-empty structured payloads whose unstructuredcontentarray is empty.📏 Reviewability
triage🧪 Verification
Pre-fix: the new structured-only test failed with
result == [].Post-fix on this branch:
Additional checks:
uvx ruff@0.16.1 check mcpgateway/transports/streamablehttp_transport.py # All checks passedFull project lint/test/coverage were not duplicated locally due to the large dependency set; CI will provide that result.
make lint/ CI📐 MCP Compliance (if relevant)
contentis a SHOULD whenstructuredContentis present[]✅ Checklist