Stackfable · MCP series, Part 5
Following our previous articles on direct tool calling, creating an MCP server, connecting Claude through an MCP client, and working with multiple MCP servers.
The core idea
So far, we've treated MCP as a standardized way to discover and call tools. That covers product searches and stock checks, but not the user who just wants to browse the catalog or start the same recommendation workflow again. Tools are only one of three primary capabilities a server can expose.
Tools → Operations the model can ask the host to execute
Resources → Data the application can select and read
Prompts → Reusable message templates the user or application can selectHere's the difference in the smallest possible pseudocode:
# Tool: Claude can request execution in its tool_use response.
result = await mcp_client.call_tool("search_products", args)
# Resource: the host explicitly chooses which URI to read.
resource = await mcp_client.read_resource("shop://catalog")
# Prompt: the host explicitly chooses a template and fills its arguments.
prompt = await mcp_client.get_prompt(
"recommend_keyboard", {"max_price": "100", "preference": "wireless"}
)MCP exposes all three. It does not automatically inject resources or prompts into Claude. Our host decides whether to display a resource, include it in the model's context, or send a rendered prompt through the Claude Messages API.
We will extend the same fictional shopping assistant, not replace it. The existing search_products() and check_inventory() tools remain unchanged.
1. What are we adding to the shopping server?
Our current scenario is familiar:
Find a wireless mechanical keyboard under $100 and check whether the best match is in stock.
Previously, Claude discovered two tools and selected them as needed. Now imagine two additional interactions:
- The user wants to browse the catalog without asking Claude to search for products.
- The user wants to launch a reusable recommendation workflow without typing the entire set of instructions each time.
We'll add these MCP capabilities:
| Capability | MCP address | What it returns |
|---|---|---|
| Tool | search_products | Matching products |
| Tool | check_inventory | Stock for one product |
| Static resource | shop://catalog | Snapshot of catalog products |
| Resource template | shop://products/{product_id} | Details for a selected product |
| Prompt | recommend_keyboard | A reusable shopping request with arguments |
The catalog and product resource intentionally omit stock quantities. Inventory still comes from the inventory tool. This keeps the teaching example consistent and demonstrates that a resource is not a substitute for every tool.
flowchart TB
accTitle: Shopping MCP server capabilities
accDescr: The Python host connects Claude to the shopping server, which exposes tools, resources, and a prompt. Tools and resources use the product catalog.
U[User] --> H[Python host / MCP client]
H <-->|Messages API| L[Claude]
H <-->|stdio and MCP| S[Shopping MCP server]
S --> T[Tools: search, inventory]
S --> R[Resources: catalog, product details]
S --> P[Prompt: recommend_keyboard]
T --> J[(products.json)]
R --> J2. First connection: a read-only resource
The course chapter introduced resources using a static URI and a URI template. We can use those two forms with our store.
A static resource
@mcp.resource("shop://catalog", mime_type="application/json")
def get_catalog() -> str:
"""Return a public snapshot of products (without stock)."""
return json.dumps([...])This isn't a tool schema. It exposes data at a URI. The host can address it by its URI instead of asking Claude to decide which function to run.
For example:
result = await mcp_client.read_resource("shop://catalog")At the MCP protocol layer, this sends resources/read with the URI shop://catalog. The server executes the resource handler and returns its content. No Anthropic API call is involved.
A parameterized resource
@mcp.resource("shop://products/{product_id}", mime_type="application/json")
def get_product(product_id: str) -> str:
"""Return details for one product ID."""
...The {product_id} placeholder means this is a resource template. It represents a family of addresses, for example:
shop://products/kb-101
shop://products/kb-102The client supplies a concrete URI when it reads one:
result = await mcp_client.read_resource("shop://products/kb-101")The SDK extracts the product_id from the URI and invokes the resource function with that argument.
Static resources and templates are discovered separately
This detail matters in the modern Python SDK:
static = await mcp_client.list_resources()
templates = await mcp_client.list_resource_templates()
print([str(r.uri) for r in static.resources])
# ['shop://catalog']
print([t.uri_template for t in templates.resource_templates])
# ['shop://products/{product_id}']Why two calls? shop://catalog is already a readable address. shop://products/{product_id} is only a pattern; it must be filled with an ID before reading.
sequenceDiagram
accTitle: Discovering and reading a product resource
accDescr: The host lists static resources and resource templates separately, then reads a concrete product URI from the shopping server.
participant H as Python host
participant C as MCP client
participant S as Shopping MCP server
H->>C: list_resources()
C->>S: resources/list
S-->>H: shop://catalog
H->>C: list_resource_templates()
C->>S: resources/templates/list
S-->>H: shop://products/{product_id}
H->>C: read_resource(shop://products/kb-101)
C->>S: resources/read (concrete URI)
S-->>H: Product JSON dataImportant: This result returns to our Python host. It is not sent to Claude automatically. We can print it as a direct lookup, or explicitly include it in a later Claude request.
3. Second connection: reusable prompts
The MCP server can also publish a prompt template. For our store, let's provide a workflow with a maximum price and a preference:
@mcp.prompt()
def recommend_keyboard(max_price: str = "100", preference: str = "wireless") -> str:
"""Prepare a shopping request with a budget and connection preference."""
return (
f"Find a {preference} mechanical keyboard for at most ${max_price} in our store. "
"Use search_products to find matches, then check_inventory for your best match. "
"Explain the recommendation briefly. Do not invent prices or inventory."
)The server registers this as a prompt named recommend_keyboard. It infers its argument definitions from the Python signature. Note the arguments are strings: MCP prompt arguments are string-valued, even for values like "100" that represent a number. When Claude later requests search_products, it supplies the tool's own numeric max_price argument.
The host first discovers prompts:
listed = await mcp_client.list_prompts()
print([p.name for p in listed.prompts])
# ['recommend_keyboard']Then it requests the rendered prompt:
rendered = await mcp_client.get_prompt(
"recommend_keyboard",
{"max_price": "100", "preference": "wireless"},
)This sends prompts/get to the MCP server. The server returns prompt messages, not the result of an LLM inference.
To make Claude act on the prompt, our host must explicitly send those messages using the Claude Messages API:
# Conceptual bridge: MCP prompt messages → Claude message history
messages = adapt_prompt_messages(rendered.messages)
response = await claude.messages.create(
model=MODEL,
max_tokens=1024,
tools=available_tools,
messages=messages,
)Now Claude sees the rendered request, can decide to use search_products(), and our existing tool loop takes over.
sequenceDiagram
accTitle: Using a shopping prompt with Claude
accDescr: The host gets a rendered prompt from the shopping server, adapts its messages for Claude, and continues the existing tool-calling loop.
actor U as User
participant H as Python host
participant C as MCP client
participant S as Shopping MCP server
participant L as Claude API
U->>H: /prompt recommend_keyboard max_price=100 preference=wireless
H->>C: get_prompt(name, string arguments)
C->>S: prompts/get
S-->>H: PromptMessage(s)
Note over H: Adapt MCP prompt messages for Claude
H->>L: messages.create(rendered prompt, tools)
L-->>H: tool_use search_products
Note over H: Existing MCP tool-calling loop continuesWhy a prompt isn't a tool
get_prompt(...) is a host-initiated MCP request, not a Claude tool_use request. Claude didn't choose to retrieve the prompt; the user or our application did. Only after we send the rendered prompt to Claude does its tool-selection behavior begin.
4. Putting the capabilities into our CLI
The course uses / commands for prompts and @ shortcuts for resources. Those are application UI conventions, not reserved MCP protocol syntax. We'll keep them because they make the distinction visible.
| User input | What Python does | Does Claude run? |
|---|---|---|
@catalog | read_resource("shop://catalog"), display content | No |
@product/kb-101 | Read shop://products/kb-101, display content | No |
/prompts | List prompt names and arguments | No |
/prompt recommend_keyboard max_price=100 preference=wireless | get_prompt, then send returned messages to Claude | Yes |
/askproduct kb-101 Is this under $100? | Read resource, then explicitly add its content to Claude's input | Yes |
| Ordinary user question | Claude decides whether to request tools | Yes |
Here's the important dispatch structure, as pseudocode:
if user_input == "@catalog":
resource = await mcp_client.read_resource("shop://catalog")
print(resource_content(resource))
elif user_input.startswith("/prompt "):
rendered = await mcp_client.get_prompt(name, arguments)
messages = adapt_prompt_messages(rendered.messages)
print(await run_claude(messages))
else:
print(await run_claude([{"role": "user", "content": user_input}]))Note that @product/... does not magically put product information into Claude's context. The added /askproduct command demonstrates the extra application step required to do that.
Tracing @product/kb-101 versus /askproduct kb-101 ...
flowchart TD
accTitle: Displaying a product versus asking Claude about it
accDescr: Both commands read a product resource, but only the askproduct path includes its text in a Claude request.
A[User requests product details] --> B{Which command?}
B -->|"@product/kb-101"| C["MCP resources/read"]
C --> D[Python displays resource]
B -->|"/askproduct kb-101 question"| E["MCP resources/read"]
E --> F[Python constructs a Claude user message with resource text]
F --> G[Claude Messages API]
G --> H[Answer or tool_use]This is the central distinction: MCP gives our host access to data, but the host controls when that data is actually supplied to the model.
5. What's different from our previous MCP client?
We aren't rewriting the Claude tool-calling loop. Its structure remains:
response = await claude.messages.create(...)
while response.stop_reason == "tool_use":
for block in response.content:
if block.type == "tool_use":
result = await mcp_client.call_tool(block.name, block.input)
# Append matching tool_result to conversation
response = await claude.messages.create(...updated_messages...)The new logic lives before or alongside that loop:
resources = await client.list_resources()
templates = await client.list_resource_templates()
prompts = await client.list_prompts()
# User-selected content:
resource = await client.read_resource("shop://catalog")
rendered_prompt = await client.get_prompt("recommend_keyboard", args)Our original tool schemas, dispatcher through call_tool(), messages.append(), and loop-exit logic do not fundamentally change.
For continuity with Part 4: we can extend the same multi-server host so each resource URI and prompt name maps to the client that owns it. Here we use the shopping server alone to isolate and understand the new two primitives before adding multi-server routing for resources and prompts. The official filesystem server from Part 4 is not needed to teach this chapter.
6. Companion project layout
stackfable_mcp_l7/
├── shopping_server.py # Same two tools + 2 resources + 1 prompt
├── mcp_client.py # CLI commands + Claude loop
├── inspect_features.py # MCP-only check, no Claude API key needed
├── products.json
└── requirements.txtInstall the current Python SDK v2 and Anthropic SDK using Python 3.11+:
python -m pip install -r requirements.txt
# First inspect resources and prompts without a Claude API call
python inspect_features.py
# Then run the full chatbot
export ANTHROPIC_API_KEY="your_api_key_here"
python mcp_client.pyThe companion project files are not linked yet. Here is the complete server, including both our preexisting tools and the new capabilities; the client methods below are excerpts rather than a complete runnable client.
shopping_server.py
"""Stackfable shopping MCP server: tools, resources and prompts (SDK v2)."""
import json
from pathlib import Path
from mcp.server import MCPServer
mcp = MCPServer("stackfable-shop")
CATALOG = Path(__file__).with_name("products.json")
def load_products() -> list[dict]:
return json.loads(CATALOG.read_text(encoding="utf-8"))
# TOOLS: Claude can request these. The host executes tool calls over MCP.
@mcp.tool()
def search_products(query: str, max_price: float) -> list[dict]:
"""Search products by keyword and USD maximum price; omit stock."""
words = query.lower().split()
matches = []
for p in load_products():
searchable = f"{p['name']} {p['category']} " + ("wireless" if p["wireless"] else "wired")
if p["price"] <= max_price and all(w in searchable.lower() for w in words):
matches.append({key: p[key] for key in ("id", "name", "price", "wireless")})
return matches
@mcp.tool()
def check_inventory(product_id: str) -> dict:
"""Look up stock for an exact catalog product ID."""
for p in load_products():
if p["id"] == product_id:
return {"product_id": product_id, "in_stock": p["stock"] > 0, "quantity": p["stock"]}
return {"product_id": product_id, "error": "Product not found"}
# RESOURCES: the host chooses when to read these; they are not tool calls.
@mcp.resource("shop://catalog", mime_type="application/json")
def get_catalog() -> str:
"""Read a current public snapshot of the fictional product catalog."""
return json.dumps([{
"id": p["id"], "name": p["name"], "price": p["price"], "wireless": p["wireless"]
} for p in load_products()], indent=2)
@mcp.resource("shop://products/{product_id}", mime_type="application/json")
def get_product(product_id: str) -> str:
"""Read one product's public details by product ID (resource template)."""
for p in load_products():
if p["id"] == product_id:
return json.dumps({k: p[k] for k in ("id", "name", "category", "price", "wireless")}, indent=2)
return json.dumps({"error": "Unknown product ID", "product_id": product_id})
# PROMPTS: selected by a user or host; they render reusable model messages.
@mcp.prompt()
def recommend_keyboard(max_price: str = "100", preference: str = "wireless") -> str:
"""Prepare a shopping request with an explicit budget and connection preference."""
return (
f"Find a {preference} mechanical keyboard for at most ${max_price} in our store. "
"Use search_products to find matching products, then check_inventory for your best match. "
"Explain the recommendation briefly. Do not invent prices or inventory."
)
if __name__ == "__main__":
mcp.run(transport="stdio")Client methods to focus on
When the companion project is available, these are the mcp_client.py methods worth reading first:
# Discovery at startup
await client.list_tools()
await client.list_resources()
await client.list_resource_templates()
await client.list_prompts()
# User-selected resource retrieval
await client.read_resource("shop://catalog")
await client.read_resource("shop://products/kb-101")
# User-selected prompt rendering
await client.get_prompt(
"recommend_keyboard", {"max_price": "100", "preference": "wireless"}
)
# Model-selected tool execution — unchanged from the previous article
await client.call_tool(block.name, block.input)The client uses TextResourceContents and TextContent checks rather than assuming every MCP content block contains .text. In a richer application you would handle binary and mixed content blocks appropriately.
7. End-to-end example
Run the chatbot, then try:
> @catalog
# Python displays catalog resource; Claude not called.
> @product/kb-101
# Python displays the selected product's data.
> /prompts
# Python displays recommend_keyboard and its arguments.
> /prompt recommend_keyboard max_price=100 preference=wireless
# MCP server renders the prompt; Python passes it to Claude.
# Claude can then request search_products and check_inventory.
> /askproduct kb-101 Is this keyboard below $100?
# Python reads the product resource, injects it into the question,
# and calls Claude explicitly.This is a planned interaction, not a captured execution log. The exact tool calls chosen by Claude are not guaranteed. The MCP SDK and model API dependencies must be installed to run the project.
8. What the latest MCP SDK changes—and what it doesn't
The Lesson 7 notebook uses FastMCP from SDK v1 and explicitly pins mcp>=1.2,<2. For this article we target the current Python SDK v2 and MCP 2026-07-28 specification.
The teaching concepts remain intact: @mcp.resource("uri"), resource templates, @mcp.prompt(), resources/read, and prompts/get. The modern high-level server is MCPServer rather than FastMCP; the modern client exposes methods directly through Client rather than requiring us to write a manual ClientSession initialization sequence. The latest protocol removes the old mandatory initialization handshake, but resources and prompts are still application-selected data and message templates. Those facts don't change with the transport or protocol revision.
One implementation detail to retain: the 2026-07-28 SDK exposes static resources via list_resources() and templates via list_resource_templates(). For prompts, get_prompt() returns messages that the host can choose to pass to Claude; it doesn't itself initiate LLM inference.
9. Tradeoffs and next steps
Tools, resources, and prompts are easy to conflate because all three are exposed by an MCP server. Use this decision rule:
- If the model should decide whether to execute an operation, expose a tool.
- If the host should select contextual data by URI, expose a resource.
- If a user or host should select reusable instructions, expose a prompt.
Resources are intended as data retrieval, not as unrestricted execution endpoints. In production, apply authorization even to read-only resources, validate URI parameters, avoid leaking sensitive records, and treat returned resource text as untrusted data rather than instructions. Likewise, treat prompt templates from an untrusted third-party server as untrusted instructions; a host should review and control which templates it presents or executes.
Mental model: A tool returns a result of work Claude requested. A resource returns data the application requested. A prompt returns messages the application can choose to send to Claude.
This completes the three basic MCP primitives on a familiar running example. A natural follow-up is combining prompts and resources from multiple MCP servers, reusing the multi-server routing hub from Part 4 without changing these primitives.
Knowledge check
References
- Official MCP Python SDK v2
- SDK v2: Client APIs
- SDK v2: Resources
- MCP 2026-07-28 specification
- MCP July 2026 specification announcement
Course reference: DeepLearning.AI, Lesson 7, “Adding Prompt & Resource Features” (supplied notebook). The approach to commands and the progression from tools to resources and prompts is informed by that lesson; the fictional shopping example and code are independently authored for Stackfable.