Skip to content

fix: make UriTemplate query params optional and order-independent#1929

Open
Christian-Sidak wants to merge 2 commits intomodelcontextprotocol:mainfrom
Christian-Sidak:fix/issue-1079
Open

fix: make UriTemplate query params optional and order-independent#1929
Christian-Sidak wants to merge 2 commits intomodelcontextprotocol:mainfrom
Christian-Sidak:fix/issue-1079

Conversation

@Christian-Sidak
Copy link
Copy Markdown

Per RFC 6570, {?param1,param2} query parameter templates should match URIs with no query params, a subset of params, or params in a different order than declared in the template.

Changes

  • partToRegExp(): removed the strict per-param pattern generation for ?/& operators; query params are now handled in match() directly
  • partToRegExp(): changed the default ('') operator pattern from [^/,]+ to [^/?#,]+ so path variables don't greedily consume ? and # delimiters
  • match(): added optional (?:\?[^#]*)? regex group for the query string, then parses query params from the URI independently (order-agnostic, all optional)

Before

const template = new UriTemplate("dom://{pageId}{?selector,includeAttributes}");
template.match("dom://test-id");                        // null (wrong)
template.match("dom://test-id?selector=body");          // null (wrong)
template.match("dom://test-id?includeAttributes=true"); // null (wrong)

After

template.match("dom://test-id");                        // { pageId: "test-id" }
template.match("dom://test-id?selector=body");          // { pageId: "test-id", selector: "body" }
template.match("dom://test-id?includeAttributes=true"); // { pageId: "test-id", includeAttributes: "true" }

Fixes #1079

Per RFC 6570, {?param1,param2} templates should match URIs with missing
or reordered query parameters. Update partToRegExp() and match() to
parse query params separately, making them optional and order-agnostic.

Fixes modelcontextprotocol#1079
@Christian-Sidak Christian-Sidak requested a review from a team as a code owner April 19, 2026 06:41
@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Apr 19, 2026

🦋 Changeset detected

Latest commit: 6e01958

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@modelcontextprotocol/core Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new bot commented Apr 19, 2026

Open in StackBlitz

@modelcontextprotocol/client

npm i https://pkg.pr.new/@modelcontextprotocol/client@1929

@modelcontextprotocol/server

npm i https://pkg.pr.new/@modelcontextprotocol/server@1929

@modelcontextprotocol/express

npm i https://pkg.pr.new/@modelcontextprotocol/express@1929

@modelcontextprotocol/fastify

npm i https://pkg.pr.new/@modelcontextprotocol/fastify@1929

@modelcontextprotocol/hono

npm i https://pkg.pr.new/@modelcontextprotocol/hono@1929

@modelcontextprotocol/node

npm i https://pkg.pr.new/@modelcontextprotocol/node@1929

commit: 6e01958

One test line exceeded the configured printWidth of 140 characters;
wrapped it with Prettier to fix the CI lint/format check.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

# MCP SDK ResourceTemplate URI Validation Issue: RFC 6570 Template Matching Behavior

1 participant