fix: filter template resources from standard resource listing #528
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.
Fix: Filter template resources from standard resource listing
🤖 Generated with Claude Code
This PR fixes the resource listing behavior to properly separate regular resources from resource templates according to the MCP specification. Resources containing template parameters (identified by
{}
in their URIs) are now filtered out of the standardresources/list
response.Motivation and Context
Fixes #319
The MCP specification requires that:
resources/list
{}
parameters) should only appear inresources/templates/list
Previously, the Java SDK was returning all resources in both endpoints, which violated the protocol specification. This could cause issues for MCP clients that expect proper separation between static resources and parameterized resource templates.
How Has This Been Tested?
ResourceTemplateListingTest.java
that verify:{}
) are filtered from regular resource listings./mvnw test -pl mcp
Breaking Changes
No breaking changes. This is a bug fix that brings the implementation in line with the MCP specification. Users who were incorrectly relying on template resources appearing in
resources/list
should update their code to useresources/templates/list
instead.Types of changes
Checklist
Additional context
Implementation Details:
McpAsyncServer.java
line 597 that excludes any resource with{
in its URI from the standard listingTest Coverage:
testTemplateResourcesFilteredFromRegularListing()
- Verifies basic filtering logictestResourceListingWithMixedResources()
- Tests filtering with both regular and template resourcestestResourceTemplatesListedSeparately()
- Ensures proper separation between the two resource typesThis fix ensures the Java SDK properly implements the MCP specification for resource discovery, improving compatibility with MCP clients that rely on correct protocol behavior.