What are resource URIs and resource templates?

4 minintermediatemcpresourcesuri-templates

Quick Answer

Every resource is addressed by a URI — either a fixed one (file:///a.txt) for a specific, known piece of data, or a resource template (file:///{path} or postgres://db/{table}/{id}) using RFC 6570 URI Template syntax for a parameterized family of resources the client can construct addresses for dynamically. Templates are discovered via resources/templates/list, which returns the template pattern plus a description of each variable, letting a client (or the model, via the host) build a concrete URI like postgres://db/orders/42 without the server needing to enumerate every possible order ID up front through resources/list.

Detailed Answer

A fixed resource list works fine for a handful of files. It breaks down for anything with an unbounded or huge set of addressable items — every row in a database table, for instance.

Fixed resources vs. templates

// resources/list — fixed, enumerable resources
{"resources": [
  {"uri": "config://app/settings", "name": "App Settings"}
]}

// resources/templates/list — a parameterized family
{"resourceTemplates": [
  {
    "uriTemplate": "postgres://db/{table}/{id}",
    "name": "Database Row",
    "description": "Fetch a single row by table and primary key",
    "mimeType": "application/json"
  }
]}

RFC 6570 syntax basics

{var} is a simple placeholder substitution. A URI template file:///{path} with path=notes/todo.md expands to file:///notes/todo.md. More advanced RFC 6570 operators exist too, like {?query} for query-string expansion, but most MCP servers stick to simple path substitution for readability.

Why templates matter

Without them, a server backing a database with millions of rows has two bad options: enumerate every row through resources/list (impossible at scale), or give up on modeling rows as resources at all. A template lets the server instead say "here's the shape of a valid resource URI for this data source." The client constructs a specific URI on demand. Often the model has seen a row ID mentioned elsewhere — a tool result, a resource, the conversation — and asks the host to read postgres://db/orders/42 directly.

Practical use

Templates are typically combined with tools. A search_orders tool returns a list of order IDs, and the host (or model) then reads each one as a resource via the template. The search tool never has to inline every order's full content in its own result.

Related Resources