Skip to content

Fix URI template optional query matching - #2909

Open
gauravch-code wants to merge 2 commits into
modelcontextprotocol:mainfrom
gauravch-code:fix-uri-template-optional-query-match
Open

gauravch-code wants to merge 2 commits into
modelcontextprotocol:mainfrom
gauravch-code:fix-uri-template-optional-query-match

Conversation

@gauravch-code

Copy link
Copy Markdown

Summary

Fix UriTemplate.match() for query templates whose query parameters are optional or appear in a different order than the template declaration.

Before this change, a template like:

dom://{pageId}{?selector,includeAttributes,includeText,includeChildren}

could fail to match a URI with no query string, or a URI where only some query parameters are present. The path variable could also consume ? because simple/path match groups did not stop at query or fragment delimiters.

This change:

  • stops simple and path captures at ?, ,, #, and / as appropriate;
  • captures query strings separately from path variables;
  • matches declared query variables by key instead of by positional regex order;
  • preserves the existing behavior of returning raw encoded query values.

Fixes #1079.

Validation

Ran the focused URI template test file:

vitest run test/shared/uriTemplate.test.ts

Result: 41 passed.

Ran package typecheck:

pnpm --filter @modelcontextprotocol/core-internal typecheck

Result: passed.

Ran ESLint on the touched source file and Prettier check on the touched files:

eslint src/shared/uriTemplate.ts
prettier --check src/shared/uriTemplate.ts test/shared/uriTemplate.test.ts

Result: passed.

@gauravch-code
gauravch-code requested a review from a team as a code owner September 30, 2026 19:32
@changeset-bot

changeset-bot Bot commented Sep 30, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 471d036

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-internal 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

pkg-pr-new Bot commented Sep 30, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

@modelcontextprotocol/client

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

@modelcontextprotocol/codemod

npm i https://pkg.pr.new/@modelcontextprotocol/codemod@2909

@modelcontextprotocol/core

npm i https://pkg.pr.new/@modelcontextprotocol/core@2909

@modelcontextprotocol/server

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

@modelcontextprotocol/server-legacy

npm i https://pkg.pr.new/@modelcontextprotocol/server-legacy@2909

@modelcontextprotocol/express

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

@modelcontextprotocol/fastify

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

@modelcontextprotocol/hono

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

@modelcontextprotocol/node

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

commit: 471d036

@claude claude Bot added the v2 Ideas, requests and plans for v2 of the SDK which will incorporate major changes and fixes label Oct 1, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

v2 Ideas, requests and plans for v2 of the SDK which will incorporate major changes and fixes

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