MCP · Lesson 33 of 120
JSON Resources
Mime types.
Resources aren't only text. A store's details fit better as JSON. The mime type tells the client what kind of content it's getting, so it can handle it properly.

- Not only text
- JSON data
- Mime type
Returning JSON
We set the mime type to application slash JSON, and return a dictionary. The SDK turns it into JSON text. The client reads it, and parses it back. Run it. We get the mime type, and a real dictionary.
json_resource.pypython
import asyncio, json
from mcp import Client
from mcp.server.mcpserver import MCPServer
mcp = MCPServer("northwind")
@mcp.resource("store://{city}/info", mime_type="application/json")
def store_info(city: str) -> dict:
"""Address and hours for one store, as JSON."""
return {"city": city, "address": "22 Micklegate", "open": "9am", "close": "5:30pm"}
async def main():
async with Client(mcp) as client:
content = (await client.read_resource("store://York/info")).contents[0]
print(content.mime_type)
print(json.loads(content.text))
asyncio.run(main())Output
application/json
{'city': 'York', 'address': '22 Micklegate', 'open': '9am', 'close': '5:30pm'}Common mime types
Use text slash plain for plain text, and text slash markdown for formatted pages. Application slash JSON for data. And image types, like image slash PNG, for pictures.
| key | value |
|---|---|
| text/plain | plain text |
| text/markdown | formatted pages |
| application/json | data |
| image/png | pictures |
Summary
Set a mime type, and return a dictionary for JSON resources. Next, reading resources from the client.
Key takeaways- mime_type
- dict to JSON
- json.loads
Next up: Reading Resources — from the client