0Pricing
MCP Academy · Lesson

Set the Right MIME Type

Tell clients whether content is text, JSON, or more.

Set the Right MIME Type 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.

What a MIME Type Is

A MIME type is a short label that tells a client what kind of content a resource holds, such as plain text, JSON, or an image.

Why It Matters

The label lets the client render and parse content correctly. Without it, a client might show raw JSON as text or mishandle a binary blob. 🏷️

The Text Default

If you say nothing, MCP assumes text/plain. That suits notes and docs, but structured data deserves a more precise type.

Common Types

You will reach for a few often: text/plain for prose, application/json for data, and text/markdown for formatted documents the model can parse.

Declare It in FastMCP

Set the type with the mime_type argument on the resource decorator so clients know exactly how to read the body.

@mcp.resource("data://stats", mime_type="application/json")
def stats():
    return '{"users": 42}'

JSON the Right Way

For JSON, label it application/json and return a valid JSON string. Build it with the json library so quoting and escaping are always correct.

import json

@mcp.resource("data://stats", mime_type="application/json")
def stats():
    return json.dumps({"users": 42})

Markdown for Docs

Serving a README or guide? Use text/markdown so capable clients render headings and lists instead of showing raw symbols.

@mcp.resource("docs://readme", mime_type="text/markdown")
def readme():
    return "# Welcome\nGetting started..."

Match Type to Content

The type must honestly describe the body. Labeling plain text as JSON makes clients try to parse it and fail, so always keep them in sync.

Binary Needs Care

For images or PDFs you set a binary MIME type like image/png, and the bytes travel base64-encoded so they survive a text protocol.

Detect from Extension

When serving files, Python can guess a type from the filename. The mimetypes library maps an extension to its standard MIME type for you.

import mimetypes
mt, _ = mimetypes.guess_type("report.json")
# mt == "application/json"

A Small Contract

Think of the MIME type as a tiny contract: it promises the client what shape the bytes take so both sides agree before parsing.

Quick Check

Pick the correct type for structured data.

Recap

The MIME type tells clients how to read a resource. Use mime_type to set text, JSON, markdown, or binary, and keep it honest. 🏷️

Frequently asked questions

Is the “Set the Right MIME Type” lesson free?

Yes — the full text of “Set the Right MIME Type” 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 “Set the Right MIME Type”?

Tell clients whether content is text, JSON, or more. 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 “Set the Right MIME Type” 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. Resource URIs Explained
  2. Serve a Static Text Resource
  3. Read a File from Disk
  4. Set the Right MIME Type
← Back to MCP Academy