Skip to content

feat(core): Implement RFC-6570 URI template matching and expansion utils (#502)#603

Draft
kpavlov wants to merge 1 commit intomainfrom
kpavlov/502-rfc6570
Draft

feat(core): Implement RFC-6570 URI template matching and expansion utils (#502)#603
kpavlov wants to merge 1 commit intomainfrom
kpavlov/502-rfc6570

Conversation

@kpavlov
Copy link
Contributor

@kpavlov kpavlov commented Mar 13, 2026

Implements RFC-6570 URI Templates (UriTemplate, UriTemplateMatcher, UriTemplateParser) in kotlin-sdk-core with full Level 1–4 expansion and regex-based reverse matching.

  • Expansion — all 8 operators ({var}, {+var}, {#var}, {.var}, {/var}, {;var}, {?var}, {&var}), prefix modifiers ({var:3}), and explode modifiers ({var*}) for string, list, and associative-array values.
  • MatchingUriTemplate.match(uri) extracts all variables from every expression (including multi-variable {?x,y}) and returns a specificity score (literal character count) for disambiguating overlapping templates.
  • Performance — template parsed eagerly on construction; compiled Regex cached lazily via matcher() (only when matching is needed); pre-allocated OpInfo singletons for all 8 operators; literal-only templates skip variable extraction entirely.

Motivation and Context

Prerequisite for #502, see resource-templates

How Has This Been Tested?

Implemented unit tests for conformance with all expansion levels and path operators.

Breaking Changes

No

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update

Checklist

  • I have read the MCP Documentation
  • 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

@kpavlov kpavlov added the enhancement New feature or request label Mar 13, 2026
@kpavlov kpavlov changed the title feat(core): Implement RFC 6570 URI template matching and expansion utils (#502) feat(core): Implement RFC-6570 URI template matching and expansion utils (#502) Mar 13, 2026
@kpavlov kpavlov force-pushed the kpavlov/502-rfc6570 branch from 6da72e7 to b34b700 Compare March 13, 2026 11:42
@codecov-commenter
Copy link

Codecov Report

❌ Patch coverage is 90.21277% with 23 lines in your changes missing coverage. Please review.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
...textprotocol/kotlin/sdk/utils/UriTemplateParser.kt 87.00% 0 Missing and 13 partials ⚠️
...extprotocol/kotlin/sdk/utils/UriTemplateMatcher.kt 80.95% 0 Missing and 8 partials ⚠️
...delcontextprotocol/kotlin/sdk/utils/UriTemplate.kt 97.84% 0 Missing and 2 partials ⚠️

📢 Thoughts on this report? Let us know!

…ilities

Add `UriTemplate`, `UriTemplateMatcher`, and `MatchResult` classes to support [RFC-6570](https://www.rfc-editor.org/rfc/rfc6570.txt) URI template matching and expansion. Implemented unit tests for conformance with all expansion levels and path operators.
@kpavlov kpavlov force-pushed the kpavlov/502-rfc6570 branch from b34b700 to 66944e1 Compare March 13, 2026 12:08
@kpavlov kpavlov marked this pull request as ready for review March 13, 2026 12:34
@kpavlov kpavlov requested review from devcrocod and e5l March 13, 2026 12:34
@kpavlov kpavlov marked this pull request as draft March 16, 2026 13:58
@kpavlov kpavlov marked this pull request as draft March 16, 2026 13:58
@e5l e5l removed request for devcrocod and e5l March 17, 2026 15:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants