Support non-String URI variable parameters for @McpResource methods#6639
Open
OneZero-Y wants to merge 1 commit into
Open
Support non-String URI variable parameters for @McpResource methods#6639OneZero-Y wants to merge 1 commit into
OneZero-Y wants to merge 1 commit into
Conversation
@McpResource methods with URI template variables previously required String parameters. Non-String types such as int failed at startup, forcing manual parsing inconsistent with Spring MVC path variables. Add conversion from URI variable strings to the declared parameter type using DefaultConversionService. Invalid values are reported as McpError(INVALID_PARAMS) through existing callback error handling. Closes spring-projects#6617 Signed-off-by: Bishen Yu <aukovyps@163.com>
Contributor
Author
|
Hey @dimitarproynov — would you mind taking a look when you get a chance? This lets @McpResource URI variables bind to non-String parameter types (e.g. int) via DefaultConversionService, instead of failing at startup. Invalid values surface as McpError(INVALID_PARAMS). |
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.
Fixes #6617
Summary
@McpResourcemethods with URI template variables currently require those parameters to beString. Declaring a primitive or wrapper type (e.g.int id) fails at startup with:This forces users to manually parse URI variables, which is inconsistent with Spring MVC-style path variable handling.
This PR removes the
String-only restriction and converts URI variable values to the declared parameter type using Spring'sDefaultConversionService. Invalid values are surfaced asMcpError(INVALID_PARAMS)via the existing resource callback error handling.Changes
McpUriVariableValueConverterto convert URI variable strings to the declared parameter typeString-only validation inAbstractMcpResourceMethodCallbackbuildArgsWithUriVariablesintconversion and invalid value handlingUsage
Before (manual parsing required):
After:
Test plan