Skip to content

fix(core): exclude fragment delimiter from URI template matches - #3010

Open
sravan-v wants to merge 1 commit into
modelcontextprotocol:mainfrom
sravan-v:fix/uri-template-fragment-delimiter
Open

sravan-v wants to merge 1 commit into
modelcontextprotocol:mainfrom
sravan-v:fix/uri-template-fragment-delimiter

Conversation

@sravan-v

Copy link
Copy Markdown

Problem

On current main (43c45f4), UriTemplate.match() treats fragment expressions like reserved expansions. This includes the fragment delimiter in the captured variable and accepts a value without the delimiter.

const template = new UriTemplate('file:///doc{#section}');
template.match(template.expand({ section: 'intro' }));
// Before: { section: '#intro' }
// After:  { section: 'intro' }

template.match('file:///docintro');
// Before: { section: 'intro' }
// After: null

Resource template routing passes these captured variables to resource handlers, so a handler receives the wrong section identifier.

Change

Give the fragment operator its own pattern, with # outside the capture group. Allow an empty fragment value, matching the existing expansion of an empty string to #. Keep reserved expansion matching unchanged.

Includes five test cases and a patch changeset. This is a small bug fix under the contribution guide's straightforward-fix exception.

Validation

  • Four regression checks fail against unchanged main and pass with the fix.
  • Core-internal suite: 71 files, 1,530 tests passed.
  • Core-internal type checking, ESLint and Prettier passed.
  • git diff --check passed.
  • Repository snippet sync passed via node --import tsx scripts/sync-snippets.ts --check; the normal tsx CLI launcher cannot open its IPC pipe in this environment.
  • Repository-wide tests and package lint are still running; results will be added here.

Fragment expansion behavior is documented in RFC 6570 §3.2.4. This change only fixes the matching of the delimiter; it does not change expansion or general decoding behavior.

AI-assisted implementation and test execution.

@sravan-v
sravan-v requested a review from a team as a code owner October 13, 2026 04:28
@changeset-bot

changeset-bot Bot commented Oct 13, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: ac4d4df

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/client Patch
@modelcontextprotocol/core-internal 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 Oct 13, 2026

Copy link
Copy Markdown

Open in StackBlitz

@modelcontextprotocol/client

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

@modelcontextprotocol/codemod

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

@modelcontextprotocol/core

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

@modelcontextprotocol/server

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

@modelcontextprotocol/server-legacy

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

@modelcontextprotocol/express

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

@modelcontextprotocol/fastify

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

@modelcontextprotocol/hono

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

@modelcontextprotocol/node

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

commit: ac4d4df

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

0xamlab commented Oct 13, 2026

Copy link
Copy Markdown

Confirmed the bug and the fix. On main, the four new fragment-expansion tests fail (4 failed | 39 passed in uriTemplate.test.ts) because the old regex at uriTemplate.ts:233 captured the # delimiter inside the variable group. With this branch, the same file runs 43 passed. The change splitting + and # handling so # uses #(.*) at uriTemplate.ts:238 keeps the delimiter out of the captured value, including empty fragments. Looks good to me.

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.

2 participants