Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

Reserved URI-template expansion throws for supplementary Unicode characters

オープン 初心者向け
#1,913 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 9 日以内に返信

まだ誰も着手していません。

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
74/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
csharp
領域
api

調査の方向性

src/ModelContextProtocol.Core/UriTemplate.cs の予約済み展開エンコーダから始めてください。Encode と AppendHex 関数(467〜487行目付近)の周辺で、サロゲートペアに対して new Rune(char) の呼び出しが失敗しています。McpClient.Methods.cs の ReadResourceAsync が FormatUri に到達する経路をたどってください。{+name} と {#name} に U+1F600 のような補助文字を与えたときに UTF-8 のパーセントエンコードされた出力が得られ、読み取りが成功し、McpClientResourceTemplateTests に回帰テストが追加されれば完了です。

索引モデルが issue の本文から書いたものです。

説明

Description

McpClient.ReadResourceAsync(uriTemplate, arguments) throws ArgumentOutOfRangeException when a reserved ({+var}) or fragment ({#var}) URI-template expansion contains a supplementary Unicode character, such as an emoji. This prevents a client from reading resources whose template arguments include those characters, before a resources/read request is sent.

Reproduction

On main at 3338e88e15c42cfc27465143c140d7d10f1a2707, with a connected client and a resource handler that echoes the requested URI:

var result = await client.ReadResourceAsync(
    "test://resource/{+name}",
    new Dictionary<string, object?> { ["name"] = "hello\U0001F600" });

Expected: The request URI is test://resource/hello%F0%9F%98%80, with U+1F600 percent-encoded as UTF-8, and the resource can be read.

Actual: System.ArgumentOutOfRangeException: Specified argument was out of the range of valid values. (Parameter 'ch'). The focused regression test fails on net10.0 with this stack:

at System.Text.Rune..ctor(Char ch)
at ModelContextProtocol.UriTemplate.<Encode>g__AppendHex|6_0(...) in UriTemplate.cs:487
at ModelContextProtocol.UriTemplate.Encode(String value, Boolean allowReserved) in UriTemplate.cs:467
at ModelContextProtocol.UriTemplate.FormatUri(...) in UriTemplate.cs:392
at ModelContextProtocol.Client.McpClient.ReadResourceAsync(...) in McpClient.Methods.cs:596

I reproduced this by adding a [Fact] to McpClientResourceTemplateTests using its in-memory client/server fixture, then running:

dotnet test tests/ModelContextProtocol.Tests/ModelContextProtocol.Tests.csproj -f net10.0 --filter "FullyQualifiedName~ReservedExpansion_EncodesSupplementaryUnicodeScalar"

Result: 1 failed, 0 passed. The client/server connection completed; expansion failed before the read request.

Cause and possible fix

The reserved-expansion encoder loops over UTF-16 char values and calls new Rune(c) for each non-ASCII character. A supplementary Unicode scalar is a surrogate pair, so constructing a Rune from its first char throws. Decode the scalar from the input span (and advance past both UTF-16 code units) before writing its UTF-8 percent-encoded bytes. A regression test could cover {+name} and {#name} with supplementary Unicode characters.

Relevant code: UriTemplate.cs:487, McpClient.Methods.cs:596. RFC 6570 specifies UTF-8 percent encoding for characters outside the allowed URI set.

主要言語
C#
スター
4.6k
フォーク
821
平均マージ
4日 23時間
マージ済み PR(30日)
2

環境構築

Codespaces で開く

このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

modelcontextprotocol/csharp-sdk のほかの issue

modelcontextprotocol/csharp-sdk の issue をすべて見る

似ている issue

C# の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。