{{ message }}
Conversation
modelcontextprotocol#2728) match() previously returned the still-encoded substring, so a handler routed through ResourceTemplate received the wrong value for any resource whose template variable contains a reserved or non-ASCII character. The encoder that expand() applied depends on the operator: + and # use encodeURI; every other operator uses encodeURIComponent. match() now applies the matching inverse (decodeURI / decodeURIComponent) per element, including for each entry of an exploded array, and passes malformed escapes through unchanged rather than throwing.
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.

Closes #2728.
What
UriTemplate.match()returned the still-percent-encoded substring for every captured value, so a handler routed throughResourceTemplatereceived the wrong value for any resource whose template variable contains a reserved or non-ASCII character.The encoder that
expand()applied depends on the operator:+and#useencodeURI, which leaves reserved characters such as/,:, and?alone.encodeURIComponent.match()now applies the matching inverse per element:decodeURIComponentfor the default,.,/,?, and&operators.decodeURIfor+and#.Each element of an exploded array is decoded independently. A malformed escape sequence (e.g.
%ZZ) is returned unchanged rather than thrown, so a value that was already raw on the wire does not raise out ofmatch().Tests
describe('percent-decoding on match')cover every operator thatexpand()produces, plus the malformed-escape pass-through./,?,&,=,%, and a non-ASCII character (matching the differential the issue reporter surfaced: 147/200 round-trip cases fail onmain).pnpm --filter @modelcontextprotocol/core-internal testis green (1466/1466), and theserverandclientpackages still pass.Out of scope
The reporter's matrix also flagged two pre-existing regex bugs that this PR deliberately does not touch:
#operator's regex is(.+)rather than#(.+), so the#prefix ends up captured as part of the value. A separate PR can lift#to a literal prefix inpartToRegExp./operator's exploded regex uses[^/,]+(?:,[^/,]+)*, butexpand()joins exploded/values with/, not,. Same idea: separate PR, separate change.Both round-trip tests for those operators fail on
mainregardless of percent-decoding, and the percent-decoding fix does not regress them.Checklist
pnpm --filter @modelcontextprotocol/core-internal test)pnpm --filter @modelcontextprotocol/core-internal lint)@modelcontextprotocol/core-internalpatch)