Skip to content

fix: match optional URI template query params - #2429

Open
vivekjm wants to merge 4 commits into
modelcontextprotocol:mainfrom
vivekjm:fix-uri-template-query-matching
Open

vivekjm wants to merge 4 commits into
modelcontextprotocol:mainfrom
vivekjm:fix-uri-template-query-matching

Conversation

@vivekjm

@vivekjm vivekjm commented Jul 3, 2026

Copy link
Copy Markdown

Summary

  • updates UriTemplate.match() so {?a,b} query operators match when query params are omitted, partial, or supplied out of declaration order
  • prevents simple path variables from consuming query delimiters before optional query matching runs
  • adds regression coverage for omitted, partial, out-of-order, and dom://{pageId}{?...} matching

Fixes #1079

Validation

Note: local git push was run with --no-verify because the repo pre-push hook invokes the system Corepack installation, which fails before running checks with Cannot find matching keyid for pnpm. The same package checks above were run explicitly with [email protected] via npx and passed.

@vivekjm
vivekjm requested a review from a team as a code owner July 3, 2026 06:39
@changeset-bot

changeset-bot Bot commented Jul 3, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 5632f56

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

This PR includes changesets to release 6 packages
Name Type
@modelcontextprotocol/core Patch
@modelcontextprotocol/core-internal Patch
@modelcontextprotocol/client Patch
@modelcontextprotocol/server-legacy Patch
@modelcontextprotocol/server Patch
@modelcontextprotocol/codemod 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 Jul 3, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

@modelcontextprotocol/client

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

@modelcontextprotocol/codemod

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

@modelcontextprotocol/core

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

@modelcontextprotocol/server

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

@modelcontextprotocol/server-legacy

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

@modelcontextprotocol/express

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

@modelcontextprotocol/fastify

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

@modelcontextprotocol/hono

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

@modelcontextprotocol/node

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

commit: 5632f56

@vivekjm
vivekjm force-pushed the fix-uri-template-query-matching branch from 094ffba to ef21c1f Compare July 19, 2026 18:06
@claude claude Bot added the v2 Ideas, requests and plans for v2 of the SDK which will incorporate major changes and fixes label Aug 18, 2026

@ychampion ychampion left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Assisted by AI for SDK testing and review drafting.

I built 313abe6 and its upstream parent 919bb8e and ran both through the real SDK Client.listResourceTemplates() and Client.readResource() with an in-memory transport. The omitted, partial, and reordered query cases all work on this PR.

I found a routing regression with two resource templates registered on the same path:

mem://library/document/{id}{?summary}
mem://library/document/{id}{?revision}

On the parent, ?summary=compact and ?revision=42 each reach the callback that declares that key. On this head, both reads go to the first registered callback. For example, with the summary template registered first, a read with ?revision=42 returns summary content and the callback only receives id. Reversing registration order reverses which read goes to the wrong callback.

Could we preserve that distinction while allowing callers to omit or reorder the declared keys? A paired resources/read test would cover the difference that the single-template unit tests miss.

@vivekjm

vivekjm commented Nov 22, 2026

Copy link
Copy Markdown
Author

@ychampion Thanks for testing both registration orders. The query matcher now checks each key against the ones declared by its template, so reads with ?lang=en and ?version=1 route to their respective callbacks. I added a resources/read regression test that registers the templates in both orders. The full core-internal and server test suites passed on 5632f564.

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

2 participants