Skip to content

Conversation

arcaputo3
Copy link
Collaborator

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

arcaputo3 and others added 5 commits June 16, 2025 17:01
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 <[email protected]>
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 <[email protected]>
- 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.
@arcaputo3
Copy link
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.

@arcaputo3 arcaputo3 merged commit 5e894d2 into main Sep 1, 2025
5 checks passed
@arcaputo3 arcaputo3 deleted the feat/resource-template-support branch September 26, 2025 16:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant