Reserved URI-template expansion throws for supplementary Unicode characters
维护者通常 9 天内回复
还没有人认领这个 Issue。
评估
调研方向
从 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
- 派生
- 819
- 平均合并
- 4 天 23 小时
- 30 天内合并 PR
- 2
环境准备
在浏览器里用你自己的 GitHub 账号启动这个项目的开发容器。
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
modelcontextprotocol/csharp-sdk 的其他 Issue
-
ClaimsPrincipal parameter injection sample request可能已有人在做 @utsavjain2809 于 7 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 74/100
modelcontextprotocol/csharp-sdk#1899 ·
维护者通常 9 天内回复
-
Document ClientOAuthOptions.ScopeSelector usage可能已有人在做 @z0rimo 于 30 天前认领。 未关闭
难度 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 于 45 天前认领。 未关闭
难度 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 于 46 天前认领。 未关闭
难度 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
-
Bug: Hidden loading rings keep the compositor running, so Files uses 7-94% of a CPU core while idle未关闭
难度 2/5 1-3 小时 新手友好度 72/100
files-community/Files#19026 · 1 条评论 ·
维护者通常 1 天内回复
-
Physgun SFX Spam未关闭
难度 2/5 1-3 小时 新手友好度 62/100
-
难度 1/5 1 小时以内 新手友好度 80/100
SubtitleEdit/subtitleedit#15946 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 68/100
BHoM/Civil3D_Toolkit#118 ·
-
Reason-phrase table has misspelled entries (`Unathorized`, `Switching Protcols`, `Multiple Choises`)未关闭bug severity:low
难度 2/5 1-3 小时 新手友好度 65/100