MCP · Lesson 34 of 120
Reading Resources
From the client.
A host can read resources and attach them to the chat, so the model sees them as context. Let's do that by hand. Read the returns policy, and put it into the prompt.

- Read a resource
- Attach to the chat
- Model sees it
Resource as context
We read the returns policy from the Northwind server. Then we build a prompt with the policy as context, and ask the model a question. Run it. The model answers from the policy it was given.
resource_context.pypython
import asyncio
from mcp import Client
from langchain.chat_models import init_chat_model
from northwind import mcp
llm = init_chat_model("google_genai:gemini-flash-lite-latest", temperature=0)
async def main():
async with Client(mcp) as client:
policy = (await client.read_resource("policy://returns")).contents[0].text
question = "Can I return a helmet after three weeks? One sentence."
print(llm.invoke(f"Policy: {policy}\n\nQuestion: {question}").text)
asyncio.run(main())Output
Yes, you can return the helmet because three weeks is within the 30-day return policy, provided it is unused.
Also uses northwind.py
from mcp.server.mcpserver import MCPServer
from mcp.server.mcpserver.exceptions import ToolError
mcp = MCPServer("northwind")
ORDERS = {1042: "shipped", 1043: "packing", 1044: "delivered"}
@mcp.tool()
def order_status(order_id: int) -> str:
"""Look up the status of a Northwind order by its number."""
if order_id not in ORDERS:
raise ToolError(f"Order {order_id} not found")
return ORDERS[order_id]
@mcp.tool()
def delivery_cost(order_total: float) -> str:
"""UK delivery cost for an order total in pounds."""
return "free" if order_total >= 50 else "£4.99"
@mcp.resource("policy://returns")
def returns_policy() -> str:
"""Northwind's returns policy."""
return "You can return any unused item within 30 days of delivery."
@mcp.prompt()
def support_reply(question: str) -> str:
"""Draft a polite reply to a customer."""
return f"Write a short, polite reply to this Northwind customer: {question}"
if __name__ == "__main__":
mcp.run()Who reads resources
In most hosts, the user or the app picks resources, for example from an attach menu. Some hosts let the model ask for them too. Either way, the content ends up in the model's context.
| key | value |
|---|---|
| User | attach menu |
| App | automatic context |
| Model | in some hosts |
| Result | content in context |
Summary
Clients read resources and add them to the model's context. Next, files as resources.
Key takeaways- read_resource
- Into the prompt
- Grounded answers
Next up: Files as Resources — a docs folder