MCP · Lesson 39 of 120
Practice: A Policy Library
Resources only.
Let's build a resources only server. Northwind's policies, one fixed resource each, plus a template for any policy by name. Then we'll list and read them all.

- Resources only
- One per policy
- Plus a template
The policy library
Policies is a dictionary of short texts. A loop registers one fixed resource per policy, using add resource. We list them, and read each one. Run it. Three policies, each with its own URI.
policy_library.pypython
import asyncio
from mcp import Client
from mcp.server.mcpserver import MCPServer
from mcp.server.mcpserver.resources import TextResource
POLICIES = {"returns": "Unused items within 30 days.",
"shipping": "UK delivery £4.99, free over £50.",
"warranty": "Lifetime warranty on frames."}
mcp = MCPServer("policies")
for name, text in POLICIES.items():
mcp.add_resource(TextResource(uri=f"policy://{name}", name=name, text=text))
async def main():
async with Client(mcp) as client:
for r in (await client.list_resources()).resources:
print(r.uri, "->", (await client.read_resource(r.uri)).contents[0].text)
asyncio.run(main())Output
policy://returns -> Unused items within 30 days. policy://shipping -> UK delivery £4.99, free over £50. policy://warranty -> Lifetime warranty on frames.
Summary
Add resource registers resources in a loop, so a whole library takes a few lines. Next, the resources quiz.
Key takeaways- TextResource
- add_resource
- List and read
Next up: Resources Quiz — test yourself