feat: Add first-class resource template support#12
Merged
Conversation
This commit implements comprehensive resource template support in fast-mcp-scala,
enabling URI templates with parameters like "users://{userId}" to work seamlessly.
Key changes:
- Add ResourceArgument and template validation to ResourceManager
- Implement getTemplateHandler() and listTemplateDefinitions() methods
- Add javaTemplateResourceReadHandler using Java SDK's DefaultMcpUriTemplateManager
- Update ResourceDefinition with isTemplate flag and toJava union type
- Enhance ResourceProcessor macro to detect and handle URI placeholders
- Add @ResourceParam annotation support for template parameters
- Update examples to demonstrate template usage (user://{userId})
- Fix resource/template separation in listResources() vs listResourceTemplates()
- Register templates as resources for handler routing while maintaining separate discovery
Technical improvements:
- Leverage Java SDK's built-in URI template matching instead of reimplementing
- Avoid duplicate template registration in discovery endpoints
- Properly validate template placeholders match method parameters
- Update to mcp-sdk 0.10.0 for enhanced template support
This enables MCP clients to discover and use templated resources with proper
parameter extraction and validation.
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
The MCP SDK 0.10.0 changed the JsonSchema constructor to require 6 parameters instead of 4. Updated test expectations to match the SDK's behavior when parsing JSON schema strings (sets additionalProperties to null rather than false). 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
- FastMcpServer: add type ascription for McpServer.AsyncSpecification to satisfy Scala 3 inference - Tests: add NoopLoggableSession and update MockServerExchange to pass a McpLoggableSession - Tests: include ClientCapabilities.Elicitation per new SDK constructor - TypesConversionTest: allow null or empty arguments per SDK normalization - Enable local maven repo in quickstart and sbt; bump mcpSdk to 0.11.3 - ToolDefinition.toJava: use Tool.Builder() API (SDK change)
- Do not register templates under resources(); use resourceTemplates() only
- Add robust classification: treat any URI containing '{' or '}' as a template
- Keep static resources strictly separate from templates
- Prepares for SDK upgrade to new template+handler API
- Register template read handlers via resources(...) so readResource works - Do not advertise templates by default; add settings.exposeTemplatesEndpoint to opt in - On unresolved template URIs (with braces), return clear error instead of placeholder text - Add meta hints to template resources (fastmcp_is_template, fastmcp_template_params) - Modernize builders: use Annotations for Content and Resource.builder for static resources - Switch tool registration to toolCall(...) with CallToolRequest handler This balances correctness (template reads work) with cleaner discovery until SDK adds a template+handler API.
Collaborator
Author
|
Once modelcontextprotocol/java-sdk#528 is merged, resource templates will no longer also be listed as resources. This is a known issue with the java MCP SDK. |
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.
This commit implements comprehensive resource template support in fast-mcp-scala, enabling URI templates with parameters like "users://{userId}" to work seamlessly.
Key changes:
Technical improvements:
This enables MCP clients to discover and use templated resources with proper parameter extraction and validation.
🤖 Generated with Claude Code