This repository was archived by the owner on Apr 11, 2026. It is now read-only.
Fix: Preserve McpError semantics when prompt methods are invoked via reflection#95
Open
vinsguru wants to merge 1 commit intospring-ai-community:mainfrom
Open
Fix: Preserve McpError semantics when prompt methods are invoked via reflection#95vinsguru wants to merge 1 commit intospring-ai-community:mainfrom
vinsguru wants to merge 1 commit intospring-ai-community:mainfrom
Conversation
Unwrap InvocationTargetException to correctly detect and propagate McpError thrown by prompt implementations. This preserves JSON-RPC error code, message, and data instead of overriding them with a generic error.
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Problem
Prompt methods are invoked using
Method.invoke, which wraps user-thrown exceptions inInvocationTargetException.Because of this,
McpErrorthrown by prompt implementations is never detected via instanceof checks and gets overridden by a generic error, losing its JSON-RPC code, message, and data.Root Cause
Reflection wraps the original exception. The existing catch block checks Exception instanceof McpError, which is guaranteed to fail when the error is thrown from the invoked method.
Solution
InvocationTargetExceptionto obtain the real cause.Behavioral Changes
Tests
This fixes #94