0Pricing
MCP Academy · Lesson

Return Images & Binary Blobs

Send non-text content back through a tool.

Return Images & Binary Blobs is a free MCP Academy lesson on CoddyKit — lesson 4 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the MCP Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

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. ✅

Frequently asked questions

Is the “Return Images & Binary Blobs” lesson free?

Yes — the full text of “Return Images & Binary Blobs” is free to read here on the web, and the MCP Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the MCP Academy course, upgrade to CoddyKit PRO.

What will I learn in “Return Images & Binary Blobs”?

Send non-text content back through a tool. You practise MCP Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start MCP Academy?

No prior experience is required. MCP Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 4 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “Return Images & Binary Blobs” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this MCP Academy lesson?

Yes. Every MCP Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. Text vs Structured Content
  2. Return a Typed Result Object
  3. Output Schemas for Clients
  4. Return Images & Binary Blobs
← Back to MCP Academy