Reserved URI-template expansion throws for supplementary Unicode characters
メンテナーはふだん 9 日以内に返信
まだ誰も着手していません。
評価
調査の方向性
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
環境構築
このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
modelcontextprotocol/csharp-sdk のほかの issue
-
ClaimsPrincipal parameter injection sample request対応中かも @utsavjain2809 が 8 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 74/100
modelcontextprotocol/csharp-sdk#1899 ·
メンテナーはふだん 9 日以内に返信
-
Document ClientOAuthOptions.ScopeSelector usage対応中かも @z0rimo が 32 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
modelcontextprotocol/csharp-sdk#1867 · コメント 1 件 ·
メンテナーはふだん 9 日以内に返信
-
HTTP+SSE client: POST responses are never disposed, leaking one connection per sent message対応中かも @yalcinfu22 が 46 日前に担当しました。 オープン
難易度 1/5 1時間未満 初心者へのやさしさ 88/100
modelcontextprotocol/csharp-sdk#1840 · コメント 1 件 ·
メンテナーはふだん 9 日以内に返信
-
stdio client never closes the server's stdin, so every client dispose burns the full ShutdownTimeout (5s by default)対応中かも @luisangelrod が 47 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 84/100
modelcontextprotocol/csharp-sdk#1836 · コメント 1 件 ·
メンテナーはふだん 9 日以内に返信
-
enhancement needs confirmation
難易度 2/5 1〜3時間 初心者へのやさしさ 64/100
modelcontextprotocol/csharp-sdk#678 · コメント 1 件 ·
メンテナーはふだん 9 日以内に返信
modelcontextprotocol/csharp-sdk の issue をすべて見る
似ている issue
-
needs-area-label
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
Fallout-build/Fallout#708 ·
メンテナーはふだん 5 日以内に返信
-
bug next version
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
Rem0o/FanControl.Releases#4220 · コメント 1 件 ·
-
area:repo audit:approved audit:auto priority:P3
難易度 2/5 1〜3時間 初心者へのやさしさ 66/100
elsa-workflows/elsa-core#8771 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
nkdAgility/azure-devops-migration-tools#3217 ·
メンテナーはふだん 1 日以内に返信