Repository navigation
Conversation
Templates using an RFC 6570 operator compiled to null, so they were
registered and listed in resources/templates/list but resources/read
never routed to them. Template matching was also first-registered-wins,
so x://{a}/{b} shadowed a later x://files/{name}.
Template matching moves to src/uri-template.ts and now supports {+var}
(may contain '/'), {/a,b} optional path segments and trailing {?a,b}{&c}
query parameters (order-tolerant, optional, unknown or repeated
parameters do not match). Any other template (#, ., ; operators,
multi-variable {a,b}, * and :n modifiers) throws at registration with
the template in the message. Level-1 {name} matching and decoding are
unchanged.
When several templates match, the one with the most literal characters
wins, ties going to registration order.
Fixes #303
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UF4S3w7iA83V9DVsasLJzM
This branch has not been deployed
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.
Problem
resources/readroutes a concrete URI to a registered template (#245), butcompileUriTemplateonly handled level-1{name}placeholders. Any template that used an operator ({+path},{?q},{/seg}, ...) compiled tonull. It was still registered and listed inresources/templates/list, but reads always returned "Resource not found". Matching was also first-registered-wins, sox://{a}/{b}shadowed a laterx://files/{name}forx://files/a.Fix
Template compiling and matching now live in
src/uri-template.ts.Supported expressions
{name}: unchanged. One non-empty segment without/, percent-decoded the same way as before (decodeURIComponent, falling back to the raw value).{+name}: a non-empty value that may contain/but not?or#.{/a,b}: optional/valuesegments. Each segment is non-empty and contains no/.{?a,b}{&c}: optional query parameters, accepted in any order. These expressions must come last in the template. A query that has an undeclared or repeated parameter does not match, because it is not an expansion of the template. A template without query expressions keeps its old behaviour for URIs that contain?.Everything else throws at registration. That covers the
#,.,;and reserved operators, multi-variable{a,b}/{+a,b}, the*and:nmodifiers, query expressions that are not at the end, and{&x}with no{?...}before it. The error message includes the template. I chose to reject these instead of matching them loosely or warning:#,.and;are rarely used in MCP resource URIs, and matching them correctly (fragment handling,;name=valuepairs,.suffix ambiguity) would add a lot of code for little benefit;{a,b}joins values with,, which a value can also contain.Specificity: when several templates match, the one with the most literal characters wins, and ties go to registration order. An exact
uriregistration still takes precedence over any template.README: the resource-template section now documents the supported expressions, rejection at registration, the precedence rules, and a note that
{+path}values are not sanitized.Breaking change
Registering a template with an unsupported expression (for example
x://doc{#section},x://{a,b}orx://{list*}) now throws frommcpAddResource. Before, these registered without any error but could never be read.Fixes #303
🤖 Generated with Claude Code
https://claude.ai/code/session_01UF4S3w7iA83V9DVsasLJzM