fix(mcp): forward Symfony HTTP exception messages as JSON-RPC errors - #8505
Open
alexisLefebvre wants to merge 1 commit into
Open
fix(mcp): forward Symfony HTTP exception messages as JSON-RPC errors#8505alexisLefebvre wants to merge 1 commit into
alexisLefebvre wants to merge 1 commit into
Conversation
A state provider or processor signalling a caller-facing failure through HttpKernel's HTTP exception contract has its message forwarded to the client, the same as one using the metadata component's contract. Both qualify at the two conversion sites; every other throwable still reaches the SDK's generic handler, so unexpected exception text stays hidden. Signalling a missing resource relies on the HttpKernel contract, since the metadata component ships no equivalent for that status, and the SDK replaces the message of anything it handles itself with a fixed constant. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
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.
What
The MCP handler converts a caller-facing HTTP exception from a state provider or processor into a JSON-RPC error carrying its message — but only API Platform's
HttpExceptionInterfacequalified. Symfony'sHttpKernel\Exception\HttpExceptionInterfacedeclares the same methods and is a distinct interface, so it fell through to the SDK's generic handler, which substitutesInternal server error..Both interfaces now qualify. Every other throwable still reaches the generic handler, so arbitrary exception text is not leaked.
Why
Throwing
NotFoundHttpExceptionfrom a provider is the documented way to signal a missing resource.api-platform/metadataships no 404 exception implementing its own interface —AccessDeniedExceptionis the only class that does. So two caller-facing failures in one provider behaved differently by package of origin.#[ApiResource( mcp: [ 'set_order_delivery_info' => new McpTool( provider: SetOrderDeliveryInfoProvider::class, processor: SetOrderDeliveryInfoProcessor::class, ), ], )] final class Order { /* ... */ }A
tools/callwith an unknownorderId:Otherwise an application must declare an exception extending Symfony's and implementing API Platform's interface, purely to get the message through. Only observable with mcp/sdk 0.8, which sanitises what its generic handler catches.
🤖 Generated with Claude Code