Fix middleware error responses failing outputSchema validation#446
Merged
QuentinAmbard merged 1 commit intomainfrom Apr 9, 2026
Merged
Conversation
QuentinAmbard
approved these changes
Apr 9, 2026
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.
Summary
outputSchemavalidationToolErrorinstead of returningToolResultfor error cases so the MCP SDK setsisError=True, bypassingoutputSchemavalidationToolErroris raised and fix incorrectCancelledErrortestContext
PR #411 expanded the middleware to catch all exceptions and return them as
ToolResult. SinceToolResultis a success-path object, the MCP SDK treats these as successful responses missingstructuredContentand rejects them with:Before #411, general exceptions propagated to the MCP SDK which handled them correctly with
isError=True. #411 attempted to setstructured_contenton error responses but reverted it because error dicts don't match tool-specific output schemas.The fix raises
ToolError(fromfastmcp.exceptions) which propagates to the MCP SDK's exception handler →_make_error_result(str(e))→CallToolResult(isError=True), bypassing validation entirely while preserving the structured JSON error payloads.Test plan
manage_jobswithaction="bogus") and verify the actual error JSON is returned instead of the outputSchema validation error