PathSegmentTemplateMatcher accepts conflicting captures for repeated variable names
Maintainers usually reply within 3 days
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 64/100
Research direction
Start in PathSegmentTemplateMatcher (io.modelcontextprotocol.kotlin.sdk.utils): find the one-pass match loop that writes each capture into the variables map, and the surrounding percent-decoding and scoring logic. Reproduce with the snippet in the issue, then add unit tests for differing captures, equal captures, decoded equality and independent names, and run the core JVM test suite plus ServerResourceTemplateTest. Done means a repeated name with differing decoded values returns no match while 42/42 still matches and distinct names, scoring and depth limits are unchanged. Note a local candidate fix already exists on the reporter's side, so coordinate before duplicating it.
Written by the indexing model from the issue text.
Description
PathSegmentTemplateMatcher accepts conflicting values for a repeated variable name and retains only the last capture. A resource request can therefore match a template whose repeated variable cannot explain the request consistently.
This was identified by @chrikrah in the review of #1175. This issue tracks the matching behavior separately from #1084's depth-check allocation fix.
Reproduction
import io.modelcontextprotocol.kotlin.sdk.types.ResourceTemplate
import io.modelcontextprotocol.kotlin.sdk.utils.PathSegmentTemplateMatcher
fun main() {
val matcher = PathSegmentTemplateMatcher(
ResourceTemplate("test://items/{id}/{id}", "Repeated ID"),
)
println(matcher.match("test://items/42/43"))
check(matcher.match("test://items/42/43") == null)
}
Actual: the URI matches with variables = {id=43}; the first capture is overwritten and the check fails. The same template with 42/42 matches consistently and should keep doing so.
Expected: reject a match when a repeated name captures different values, using the matcher's existing one-pass percent-decoding semantics. Keep consistent repeated captures, distinct names, scoring, URI normalization and depth limits unchanged.
Version check
The same six tests against the latest release tag 0.16.0 (4c55826) have three failures and three passing controls. The inconsistent repeated captures are accepted there too.
Candidate and local validation
A local candidate checks an existing capture before overwriting it. Six tests cover differing captures, equal captures and their score, decoded equality, a differing third occurrence, independent names and one-pass decoding.
On reviewed head 0f6a84c, three of those six cases fail without the candidate. With it, all 278 core JVM tests and nine ServerResourceTemplateTest integration tests pass. Core ktlint, Kotlin ABI and diff checks pass. These are local results on macOS arm64 with Temurin 21; JS, Native and Wasm runtime tests and detekt were not run for this candidate.
The existing #1175 branch remains unchanged. This candidate intentionally rejects some previously accepted URIs, so a separate follow-up keeps that behavior change reviewable without expanding the allocation PR. No production impact or full multiplatform validation is claimed.
- Dominant language
- Kotlin
- Stars
- 1.5k
- Forks
- 270
- Avg merge
- 3d 7h
- Merged PRs (30d)
- 59
Getting set up
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from modelcontextprotocol/kotlin-sdk
-
enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
modelcontextprotocol/kotlin-sdk#1088 · 2 comments · 1 reaction ·
Maintainers usually reply within 3 days
-
An empty URI matches a single-variable resource templatePossibly taken @liyifan9642-creator claimed this 43 days ago. Openbug P3
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
modelcontextprotocol/kotlin-sdk#1085 ·
Maintainers usually reply within 3 days
-
AbstractClientTransport.checkState builds a broken error messagePossibly taken @mvanhorn claimed this 36 days ago. Openapi bug P3
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
modelcontextprotocol/kotlin-sdk#1083 · 1 comment ·
Maintainers usually reply within 3 days
-
ModelPreferences reports an invalid speedPriority as costPriorityPossibly taken @sarankumar1325 claimed this 25 days ago. Openbug P3
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
modelcontextprotocol/kotlin-sdk#1081 ·
Maintainers usually reply within 3 days
-
Document elicitationOpendocumentation P2
Difficulty 2/5 1-2 days Newbie friendliness 74/100
modelcontextprotocol/kotlin-sdk#1074 ·
Maintainers usually reply within 3 days
All issues in modelcontextprotocol/kotlin-sdk
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
krelltunez/dayGLANCE#2445 ·
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
-
EANs strippenOpengood first issue prio:P3
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
-
enhancement good first issue
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
haritpanchal/WakeGuard#16 ·
-
After turning shuffle on while paused, a different song is the current one when the app is reopenedOpenbug
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
RetroMusicPlayer/RetroMusicPlayer#2085 ·
Maintainers usually reply within 1 day