Image/audio content in SamplingMessage and CreateMessageResult is base64-encoded twice
メンテナーはふだん 1 日以内に返信
評価
調査の方向性
issue のスニペットで再現する: 単独の ImageContentBlock と、SamplingMessage 内の同じブロックをシリアル化し、data フィールドを比較する。原因は SingleItemOrListConverter<T>.Write にあり、これは options.GetTypeInfo(typeof(object)) を解決し、ContentBlock.Converter ではなく派生した既定のコントラクトを選択する。SamplingMessage.Content と CreateMessageResult.Content に対して宣言されたコンバーターを尊重するようにする。完了とは、両方が iVBORw0KGgo= を出力し、sampling 経由の画像ブロックと音声ブロックに対する回帰テストがあることを意味する。
索引モデルが issue の本文から書いたものです。
説明
Describe the bug
Image (and audio) content in sampling messages is base64-encoded twice on the wire.
SingleItemOrListConverter<T>.Write serializes each item with options.GetTypeInfo(typeof(object)). For a ContentBlock list this resolves the derived type's default contract (e.g. ImageContentBlock) instead of ContentBlock.Converter. The default contract serializes ReadOnlyMemory<byte> Data (which already holds base64 UTF-8 bytes) as base64 again.
Affected: SamplingMessage.Content and CreateMessageResult.Content. In practice, McpServer.SampleAsync / AsSamplingChatClient() with a DataContent image sends an image the client cannot use: after decoding, the client gets the base64 text instead of the image bytes, and model providers reject it (e.g. OpenAI-compatible APIs return 400 invalid image data).
To Reproduce
byte[] png = [0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A];
var block = ImageContentBlock.FromBytes(png, "image/png");
JsonSerializer.Serialize<ContentBlock>(block, McpJsonUtilities.DefaultOptions);
// "data":"iVBORw0KGgo=" <- correct
JsonSerializer.Serialize(new SamplingMessage { Role = Role.User, Content = [block] }, McpJsonUtilities.DefaultOptions);
// "data":"aVZCT1J3MEtHZ289" <- base64 of the base64
Expected behavior
Content blocks inside SamplingMessage / CreateMessageResult serialize the same way as a standalone ContentBlock (data encoded once).
Version
ModelContextProtocol.Core 2.4.0 (also reproduces on main).
- 主要言語
- C#
- スター
- 4.7k
- フォーク
- 863
- 平均マージ
- 15時間 29分
- マージ済み PR(30日)
- 8
環境構築
このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
modelcontextprotocol/csharp-sdk のほかの issue
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 74/100
modelcontextprotocol/csharp-sdk#2061 ·
メンテナーはふだん 1 日以内に返信
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 67/100
modelcontextprotocol/csharp-sdk#2060 ·
メンテナーはふだん 1 日以内に返信
-
Docs: stateless.md says the stateful task store is "scoped per session", but Tasks are unavailable in strict Stateful mode対応中かも @FOWEPJF255 が 7 日前に担当しました。 オープン
難易度 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 が 18 日前に担当しました。 オープン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 が 18 日前に担当しました。 オープンbug
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
modelcontextprotocol/csharp-sdk#1966 · コメント 5 件 · 担当者 1 名 ·
メンテナーはふだん 1 日以内に返信
modelcontextprotocol/csharp-sdk の issue をすべて見る
似ている issue
-
kronos:develop:queued priority:P0
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
nopSolutions/nopCommerce#8512 ·
メンテナーはふだん 4 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
メンテナーはふだん 1 日以内に返信
-
bug effort:S P3
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
nightscout/nocturne#4767 ·
メンテナーはふだん 1 日以内に返信