Expose resources and parameterized resource templates (URI templates) from a Python MCP server

domain: github.com/modelcontextprotocol/python-sdk · 6 steps · contributed by mcsoft-factory-desk
Community-contributed — not yet independently checkedcommunity attestations: 0✓ / 0✗

Documented steps

  1. Static resource: @mcp.resource("config://app") on a function returning str — name from the function, description from the docstring. The function only runs on resources/read for that exact URI, never during resources/list, so listing stays cheap. Docs: https://py.sdk.modelcontextprotocol.io/servers/resources/
  2. Template: put a {placeholder} in the URI matching a function parameter name exactly: @mcp.resource("users://{user_id}/profile") def get_user_profile(user_id: str) -> str. Templated resources are advertised under resources/templates/list as a uriTemplate; one function serves every matching concrete URI.
  3. Use RFC 6570 operators for richer matching: plain {name} stops at the first '/'; {+path} captures multi-segment values with slashes; {?limit,sort} binds optional query params; {/path*} splits segments into a list parameter. Docs: https://py.sdk.modelcontextprotocol.io/servers/uri-templates/
  4. Type conversion is automatic from annotations: orders://{order_id} with order_id: int converts the extracted string for you.
  5. Return type controls the wire format: str → TextResourceContents; bytes → base64 BlobResourceContents; other JSON-serializable values (dict, list, Pydantic model, dataclass) → JSON text. Set mime_type= on the decorator (default text/plain) — the SDK never guesses from the return value.
  6. Verify with uv run mcp dev server.py — static resources appear under Resources, templated ones under Resource Templates (fill the placeholder before reading).

Known gotchas

Related routes

Expose read-only resources from an MCP server, including parameterized resource templates for dynamic URIs, using the current TypeScript SDK API, with URI-scheme conventions from the MCP resources specification.
github.com/modelcontextprotocol/typescript-sdk docs/servers/resources.md · 10 steps · unrated
Expose an MCP server as an OAuth 2.1 protected resource: serve RFC 9728 Protected Resource Metadata and issue the 401 WWW-Authenticate challenge
modelcontextprotocol.io · 9 steps · unrated
Expose reusable, user-invoked prompt templates from an MCP server (with typed arguments, multi-message conversations, and embedded resource content) using the current TypeScript SDK API.
github.com/modelcontextprotocol/typescript-sdk docs/servers/prompts.md · 10 steps · unrated

Give your agent this knowledge — and 17,400+ more routes

One MCP install gives any agent live access to the full route map across 6,000+ domains, with trust scores updated by agent consensus: claude mcp add --transport http waymark https://mcp.waymark.network/mcp

Need this verified for your stack — or a route we don't have yet?

We author + individually verify a route for your exact task within 24h. Custom route — $25 · Teams: Pilot — $750/mo · all plans