Skip to content

MCP resource URI templates incorrectly encode non-ASCII variable values #339843

Closed

Description

@dhairyajangir

Reproduced against main at 3d5764c14dea123b0fd50fb61788328c33c076b8 on Linux with Node.js 22.22.1, using the actual UriTemplate source. This is a source-level reproduction, without extensions or a live MCP server session.

UriTemplate percent-encodes UTF-16 code units instead of UTF-8 bytes. This affects non-ASCII values entered for an MCP resource template: mcpResourceQuickAccess.ts collects the variable text and calls resolveURI, and mcpServer.ts resolves it through this helper.

To reproduce in the existing UriTemplate unit suite:

const template = UriTemplate.parse('resource://docs/{name}');
template.resolve({ name: 'café' });
// Actual:   resource://docs/caf%E9
// Expected: resource://docs/caf%C3%A9

template.resolve({ name: '中文' });
// Actual:   resource://docs/%4E2D%6587
// Expected: resource://docs/%E4%B8%AD%E6%96%87

template.resolve({ name: '🚀' });
// Actual:   resource://docs/%D83D%DE80
// Expected: resource://docs/%F0%9F%9A%80

The accented and emoji results fail decodeURIComponent; the Chinese result decodes to different characters. Prefix expansion also counts UTF-16 units: {name:1} should retain the whole first emoji, rather than splitting its surrogate pair.

RFC 6570 specifies UTF-8 percent-encoding and Unicode-character prefix lengths. The previous low-control padding fix in #323012 does not address these non-ASCII values.

A focused correction and regression tests are prepared: UTF-8 encoding while preserving ASCII punctuation escaping, plus code-point prefix slicing. I plan to submit the linked fix. AI assistance was used for the investigation; the reported outputs were reproduced against the actual source.

Activity

  1. added a commit that references this issue on Oct 22, 2026
    070abe7
  2. added
    unreleased
    on Oct 22, 2026
  3. added this to the 1.144.0 milestone on Oct 22, 2026
  4. added
    insiders-released
    and removed
    unreleased
    on Oct 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

insiders-released

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions