AI Hints
Home›MCP Tutorial›More Resources
MCP · Lesson 38 of 120

Binary Resources

Images and PDFs.

⏱ 2 min read▶ Video at 34:32🎓 Free
Watch this lesson in the MCP courseWatch on YouTube ↗Full MCP course

Some resources are files, like the Volt Pro manual PDF, or a size chart image. Binary resources send raw bytes, encoded as base sixty four, with a mime type.

Binary Resources
From the video: Binary Resources
  • Files and images
  • Raw bytes
  • Base64 + mime type

Serving the manual PDF

The function returns bytes, so the SDK sends a blob. The client decodes the base sixty four, and checks the start of the file. Run it. The mime type is PDF, and the bytes start with the PDF marker.

binary.pypython
import asyncio, base64
from pathlib import Path
from mcp import Client
from mcp.server.mcpserver import MCPServer

mcp = MCPServer("manuals")

@mcp.resource("manual://volt-pro", mime_type="application/pdf")
def volt_pro_manual() -> bytes:
    """The Volt Pro owner's manual."""
    return Path("data/rag/volt_pro_manual.pdf").read_bytes()

async def main():
    async with Client(mcp) as client:
        content = (await client.read_resource("manual://volt-pro")).contents[0]
        data = base64.b64decode(content.blob)
        print(content.mime_type, len(data), "bytes, starts with", data[:5])

asyncio.run(main())
Output
application/pdf 29771 bytes, starts with b'%PDF-'

Binary tips

Return bytes, and set the right mime type. Keep files small, because they travel inside messages. For big files, share a link instead. And remember, not every model can read every file type.

keyvalue
Returnbytes
Mime typealways set
Big filesshare a link
Modelscheck support

Summary

Return bytes with a mime type, and the SDK sends a base sixty four blob. Next, practice with a policy library.

Key takeaways
  • bytes
  • blob
  • mime type
Next up: Practice: A Policy Library — resources only