MCP · Lesson 51 of 120
Listing Everything
Discovery.
Before using a server, a host asks what it offers. Tools, resources, templates, and prompts. This is called discovery, and it's how hosts build their menus.

- Ask what it offers
- Discovery
- Build the menus
Discovering a server
We call all four list methods, and print the names. Run it. The Northwind server offers two tools, one resource, and one prompt.
discover.pypython
import asyncio
from mcp import Client
from northwind import mcp
async def main():
async with Client(mcp) as client:
print("tools: ", [t.name for t in (await client.list_tools()).tools])
print("resources:", [str(r.uri) for r in (await client.list_resources()).resources])
print("templates:", [t.uri_template for t in (await client.list_resource_templates()).resource_templates])
print("prompts: ", [p.name for p in (await client.list_prompts()).prompts])
asyncio.run(main())Output
tools: ['order_status', 'delivery_cost'] resources: ['policy://returns'] templates: [] prompts: ['support_reply']
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()Discovery tips
List once when connecting, and cache the results. Lists can be long, so they come in pages, with a cursor. And when the server says a list changed, list it again.
| key | value |
|---|---|
| When | on connect |
| Cache | the results |
| Long lists | pages + cursor |
| list_changed | list again |
Summary
Discovery lists tools, resources, templates, and prompts, so the host knows what's available. Next, calling tools.
Key takeaways- list_tools
- list_resources
- list_prompts
Next up: Calling Tools — arguments and results