MCP · Lesson 32 of 120
Resource Templates
One pattern, many URIs.
Northwind has three stores. Instead of three resources, we write one template, store colon slash slash, then a city in curly braces. Any city fills the pattern.

- Three stores
- One template
- {city} fills it
A store template
The URI has a city parameter in braces. The function takes the same parameter. The client lists the templates, then reads two stores. Run it. One template serves both York and Leeds.
template.pypython
import asyncio
from mcp import Client
from mcp.server.mcpserver import MCPServer
mcp = MCPServer("northwind")
HOURS = {"York": "Mon to Sat, 9am to 5:30pm", "Leeds": "Mon to Sun, 9am to 6pm"}
@mcp.resource("store://{city}")
def store(city: str) -> str:
"""Opening hours for one Northwind store."""
return f"{city}: {HOURS.get(city, 'no store here')}"
async def main():
async with Client(mcp) as client:
print([t.uri_template for t in (await client.list_resource_templates()).resource_templates])
for city in ["York", "Leeds"]:
print((await client.read_resource(f"store://{city}")).contents[0].text)
asyncio.run(main())Output
['store://{city}']
York: Mon to Sat, 9am to 5:30pm
Leeds: Mon to Sun, 9am to 6pmTemplates
Templates use URI patterns with parameters in braces. They're listed separately from fixed resources. The client fills in the parameters, often helped by completions, which we'll see later.
| key | value |
|---|---|
| Pattern | store://{city} |
| Function | takes city |
| Listed by | list_resource_templates |
| Filled by | the client |
Summary
A resource template is one pattern that serves many URIs. Next, JSON resources.
Key takeaways- {param}
- One function
- Many URIs
Next up: JSON Resources — mime types