Skip to content

Conversation

beaterblank
Copy link

Feature Added:
Enhanced ResourceTemplate URI matching and type handling logic.

Motivation and Context

This change introduces a typed-aware URI parsing mechanism similar to FastAPI’s path parameter system.
It resolves issue #220 by adding a more flexible and self-contained approach for handling resource URIs with type annotations.

How Has This Been Tested?

  • Verified functionality through new and existing unit tests for:

    • Typed placeholders ({name:str}, {id:int}, {value:float}, {uuid:UUID}, {path:path})
    • Automatic type conversion and validation
  • Confirmed correct parameter extraction and type enforcement in all matching scenarios.

Breaking Changes

  • None expected, but users relying on untyped string-only behaviour may observe typed conversions.

Types of changes

  • New feature (non-breaking change which adds functionality)

Checklist

  • I have read the [MCP Documentation](https://modelcontextprotocol.io)
  • My code follows the repository's style guidelines
  • New and existing tests pass locally
  • I have added appropriate error handling
  • I have added or updated documentation as needed

Additional context

The implementation assumes URI templates follow a strict pattern and defaults to str when no type is provided.
Optional parameters and wildcard matching beyond {path: path} are not supported / cannot be supported.

Improve ResourceTemplate URI matching and type handling

Fixes issue modelcontextprotocol#220

- Implemented typed-aware URI matching logic within ResourceTemplate.matches()
  supporting {name:str}, {id:int}, {value:float},{uuid:UUID}, and {path:path} placeholders.
  similar to what FastAPI supports
- Added automatic type conversion and validation for URI parameters.
- Updated unit tests to cover typed placeholders, numeric and float parameters,
  and path-based URIs.

Limitations and notes:
- Current implementation assumes URI templates follow a strict pattern or default
  to str and do not support optional parameters or wildcards beyond {path:path}.
@felixweinberger felixweinberger self-assigned this Oct 7, 2025
@felixweinberger felixweinberger added needs more eyes Needs alignment among maintainers whether this is something we want to add needs maintainer action Potentially serious issue - needs proactive fix and maintainer attention labels Oct 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs maintainer action Potentially serious issue - needs proactive fix and maintainer attention needs more eyes Needs alignment among maintainers whether this is something we want to add
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants