画像とバイナリデータを返す
ツールを通じてテキスト以外のコンテンツを返します。
「画像とバイナリデータを返す」はCoddyKit上の無料MCP Academyレッスンです。 これはレッスン4/4です。 下記で完全なレッスンを無料で読むことができます。その後、ブラウザ内の組み込みコードエディタと24時間対応のAIチューターでハンズオン演習できます。 これはMCP Academy学習パスの一部であり、ウェブとCoddyKitアプリ全体で進捗が同期されます。 MCP Academyコースには全4レッスンが含まれています。
このレッスンの一部はまだ翻訳されておらず、英語で表示されています。
Beyond Text and JSON
Some tools produce pictures or files, not words. MCP can return binary content like images and other blobs, not just text.
The Image Content Type
MCP defines an image content type carrying the raw bytes plus a media type. Clients that support it can render the picture directly. 🖼️
Bytes Travel as Base64
Binary data is encoded as base64 text so it survives the JSON message. The client decodes it back into real bytes on arrival.
The Image Helper
The Python SDK offers an Image helper so you do not hand-encode anything. You point it at bytes or a path and return it.
from mcp.server.fastmcp import Image
return Image(data=png_bytes, format="png")Set the Media Type
Always state the format, like png or jpeg, so the client knows how to decode and display the image correctly.
Returning a File on Disk
Read the file into bytes, then wrap it for return. The tool turns a saved chart into a viewable result for the model and user.
data = open("chart.png", "rb").read()
return Image(data=data, format="png")Not Only Images
Beyond pictures, MCP supports generic blob content for other binary data, like a PDF or audio, with its own media type.
Client Support Varies
Not every client can show every type. A host that cannot render an image may fall back to a reference or a download link.
Watch the Size
Base64 inflates data by about a third, and large blobs eat tokens and bandwidth. Keep returned media small when you can.
Prefer Resources for Big Files
For very large or shared files, expose a resource by URI instead of inlining bytes in a tool result. The client fetches on demand.
Combine With Text
You can pair an image with a short text caption in the same result, giving the model both a picture and words to reason about.
Quick Check
How does binary data ride inside an MCP message?
Recap: Images & Blobs
You can return images and binary blobs via base64 with a media type, set the format, mind size, and prefer resources for big files. ✅
よくある質問
「画像とバイナリデータを返す」レッスンは無料ですか?
はい。「画像とバイナリデータを返す」の完全なテキストはこのウェブで無料で読めます。インタラクティブに演習し(組み込みコードエディタと24時間対応のAIチューター)、MCP Academyコースの残りをアンロックするには、CoddyKit PROにアップグレードしてください。 MCP Academyコースには全4レッスンが含まれています。
「画像とバイナリデータを返す」で何を学びますか?
ツールを通じてテキスト以外のコンテンツを返します。 ブラウザで直接実行するハンズオンコードでMCP Academyを演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。
MCP Academyを始めるのに経験は必要ですか?
事前経験は必要ありません。CoddyKitのMCP Academyは初級者から上級者向けに構成されているため、ここから始めるか最初から始めて、自分のペースで進むことができます。 これはレッスン4/4です。
「画像とバイナリデータを返す」レッスンにはどのくらい時間がかかりますか?
ほとんどのCoddyKitレッスンは約5~10分かかります。各レッスンはコンパクトでインタラクティブなので、着実に進歩し、ウェブとアプリ全体で正確に前回の場所から再開できます。
このMCP Academyレッスンでコードを書いて実行できますか?
はい。すべてのMCP Academyレッスンに組み込みコードエディタが含まれているため、ブラウザでリアルコードを書いて実行し、即座のAIフィードバックを取得できます。ローカル設定は不要です。
このコースのすべてのレッスン
- テキストと構造化コンテンツ
- 型付きの結果オブジェクトを返す
- クライアント向け出力スキーマ
- 画像とバイナリデータを返す