fix(transport): skip outputSchema validation for isError tool responses#4136
Open
kimsehwan96 wants to merge 1 commit intoIBM:mainfrom
Open
fix(transport): skip outputSchema validation for isError tool responses#4136kimsehwan96 wants to merge 1 commit intoIBM:mainfrom
kimsehwan96 wants to merge 1 commit intoIBM:mainfrom
Conversation
When an upstream MCP tool returns an error (isError: true) without structuredContent, the MCP Python SDK's server-side outputSchema validation replaces the original error message with a generic "outputSchema defined but no structured output returned" error. This bypasses the SDK validation by returning a CallToolResult directly when is_error is True, using the same pattern already established in the codebase (lines 1451, 1468). Closes IBM#4135 Signed-off-by: kimsehwan96 <sktpghks138@gmail.com>
bfb154d to
5482207
Compare
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.
🔗 Related Issue
Closes #4135
📝 Summary
When an upstream MCP tool with outputSchema defined returns an error (isError: true) without structuredContent, the MCP Python SDK's server-side validation replaces the original error message with a generic "outputSchema defined but no structured output returned".
This hides the actual error cause from the user.
This PR bypasses the SDK validation by returning a CallToolResult(isError=True) directly when is_error is True, which triggers the SDK's early-return path and skips outputSchema validation. This uses the same pattern already established in the codebase (lines 1451, 1468).
The root cause is in the MCP Python SDK v1.x (mcp/server/lowlevel/server.py), where outputSchema validation runs unconditionally regardless of isError.
🏷️ Type of Change
🧪 Verification
make lintmake testmake coverage✅ Checklist
make black isort pre-commit)📓 Notes (optional)
Implementation detail
The fix is placed after the structuredContent check in streamablehttp_transport.py:call_tool():
This ordering is intentional: if an error response does include structuredContent, the existing validation path is preserved. We have not observed any MCP server returning both isError: true and structuredContent simultaneously, and the MCP spec does not define this combination. If it does occur, validating the structured content is arguably the correct behavior — the server explicitly provided it, so schema conformance should be checked.
is_error is True (strict identity check)
We use getattr(result, "is_error", None) with is True rather than a truthy check. This prevents false positives when result is a MagicMock in unit tests (where unset attributes return truthy MagicMock objects).
Manual E2E verification
To validate this fix end-to-end, we added a lookup_calculation tool to the existing output_schema_test_server that raises ToolError for unknown IDs (producing isError: true with outputSchema defined). Using the docker-compose stack:
The test server change is not included in this PR — unit tests provide sufficient coverage for the transport-layer logic. The E2E setup can be formalized in a follow-up if needed.