Support C# union return values in tools, prompts, and resources
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 初心者へのやさしさ
- 55/100
- issue の種類
- バグ
- 明瞭さ
- 明確に書かれている
- 活発さ
- 活発
- 技術スタック
- csharp
調査の方向性
Read the result switches in AIFunctionMcpServerTool.cs, AIFunctionMcpServerPrompt.cs, and AIFunctionMcpServerResource.cs, then trace how their current cases handle direct return values. Check how compiler generated unions expose their active case and account for older target frameworks and Native AOT. Done means union cases behave like their directly returned values across tools, prompts, and resources while preserving output schemas and older protocol compatibility.
索引モデルが issue の本文から書いたものです。
説明
Description
When a tool, prompt, or resource method returns a C# union, its active case is not handled like the same value returned directly. The SDK's result conversion sees the boxed union rather than the active value.
Reproduction
Run this with the .NET 11 SDK, targeting net11.0 with LangVersion set to preview:
using System;
using System.IO;
using ModelContextProtocol.Protocol;
using ModelContextProtocol.Server;
await using var server = McpServer.Create(
new StreamServerTransport(Stream.Null, Stream.Null),
new McpServerOptions());
var tool = McpServerTool.Create(
() => (TextOrImage)"hello",
new() { Name = "example" });
var request = new RequestContext<CallToolRequestParams>(
server,
new JsonRpcRequest { Method = "tools/call" },
new CallToolRequestParams { Name = "example" });
var result = await tool.InvokeAsync(request);
Console.WriteLine(((TextContentBlock)result.Content[0]).Text);
public union TextOrImage(string, ImageContentBlock);
The text contains "hello", including the quote characters. Returning "hello" directly produces hello without those characters. An ImageContentBlock case is similarly serialized into a text block instead of being returned as image content. A CallToolResult case is serialized into text rather than passed through, so properties such as IsError are not propagated as result properties.
Prompts and resources have the same underlying issue, but throw instead of falling back to JSON serialization. For example, a prompt returning the string case of union TextOrPrompt(string, PromptMessage) throws InvalidOperationException: Unknown result type 'TextOrPrompt' returned from prompt function. A resource returning the string case of union TextOrResource(string, ResourceContents) throws InvalidOperationException: Unsupported result type 'TextOrResource' returned from resource function.
Expected behavior
Handle a union's active case as the corresponding directly returned value for tools, prompts, and resources. Preserve the existing handling of ordinary return values, structured content and output schemas, including compatibility with older protocol versions.
Investigation
The result switches in AIFunctionMcpServerTool, AIFunctionMcpServerPrompt, and AIFunctionMcpServerResource match the boxed union rather than its active case. Compiler-generated unions implement System.Runtime.CompilerServices.IUnion on .NET 11; the SDK also targets older frameworks, so compatibility and Native AOT need consideration.
Reproduced against the SDK at commit 64cfd66b147553d8cf953f9e2a374aae96014968, using its net10.0 Core build in a .NET 11 application.
[!NOTE]
This issue was drafted with GitHub Copilot.
- 主要言語
- C#
- スター
- 4.6k
- フォーク
- 849
- 平均マージ
- 1日 16時間
- マージ済み PR(30日)
- 24
環境構築
このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
modelcontextprotocol/csharp-sdk のほかの issue
-
難易度 1/5 1時間未満 初心者へのやさしさ 88/100
modelcontextprotocol/csharp-sdk#2031 ·
メンテナーはふだん 1 日以内に返信
-
Static resources whose URIs differ only in the fragment or user info collapse into one対応中かも @halter73 が 9 日前に担当しました。 オープンP2
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
modelcontextprotocol/csharp-sdk#1970 · コメント 4 件 · 担当者 1 名 ·
メンテナーはふだん 1 日以内に返信
-
POST /mcp with a missing or unparseable Content-Type returns HTTP 500 instead of a 4xx対応中かも @halter73 が 9 日前に担当しました。 オープンbug
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
modelcontextprotocol/csharp-sdk#1966 · コメント 5 件 · 担当者 1 名 ·
メンテナーはふだん 1 日以内に返信
-
Reserved URI-template expansion throws for supplementary Unicode characters対応中かも @tarekgh が 2 日前に担当しました。 オープンP3
難易度 2/5 1〜3時間 初心者へのやさしさ 74/100
modelcontextprotocol/csharp-sdk#1913 · コメント 1 件 · 担当者 1 名 ·
メンテナーはふだん 1 日以内に返信
-
ClaimsPrincipal parameter injection sample request対応中かも @utsavjain2809 が 48 日前に担当しました。 オープンhelp wanted P3
難易度 2/5 1〜3時間 初心者へのやさしさ 74/100
modelcontextprotocol/csharp-sdk#1899 ·
メンテナーはふだん 1 日以内に返信
modelcontextprotocol/csharp-sdk の issue をすべて見る
似ている issue
-
account bug effort:S P2
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
nightscout/nocturne#3745 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
grate-devs/grate#969 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
jsboige/CoursIA#27768 · コメント 2 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 63/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
martin-stromberg/FinanceManager#562 ·
メンテナーはふだん 1 日以内に返信