Back to course

Binary vs Text Resources

Model Context Protocol (MCP) Server Engineering

Binary vs Text

Resources can return two types of content:

  1. Text: For code, logs, and prose.
  2. Blob: For images, PDFs, or binary files. These must be base64 encoded.

Encoding a Blob

typescript return { contents: [{ uri: "...", blob: Buffer.from("image_data").toString("base64"), mimeType: "image/png" }] };

Assignment: Implement a resource that returns a small base64-encoded image string.