AI Hints
Home›MCP Tutorial›Prompts Quiz and the Client
MCP · Lesson 50 of 120

The Client Class

One object.

⏱ 2 min read▶ Video at 44:24🎓 Free
Watch this lesson in the MCP courseWatch on YouTube ↗Full MCP course

We've used the Client class all along. Now let's look at it properly. One object connects to one server, over any transport, and gives you every MCP feature as a method.

The Client Class
From the video: The Client Class
  • One object
  • One server
  • Every feature

What Client accepts

Pass a server object to connect in-process, for tests. Pass stdio server parameters to start a local program. Pass a URL to connect over HTTP. The methods are the same either way.

PassConnects byUse for
MCPServer objectin-processtests
StdioServerParameterssubprocesslocal servers
URL stringstreamable HTTPremote servers

Connection details

After connecting, the client knows the server's name, the protocol version they agreed, and what the server supports. Run it. The server name, the version date, and its capabilities.

client_info.pypython
import asyncio
from mcp import Client
from northwind import mcp

async def main():
    async with Client(mcp) as client:
        print("server:  ", client.server_info.name)
        print("protocol:", client.protocol_version)
        caps = client.server_capabilities
        print("has:     ", [k for k in ["tools", "resources", "prompts"] if getattr(caps, k)])

asyncio.run(main())
Output
server:   northwind
protocol: 2026-07-28
has:      ['tools', 'resources', 'prompts']
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()

Summary

Client connects in-process, over standard IO, or over HTTP, with the same methods. Next, listing everything a server offers.

Key takeaways
  • Server object
  • stdio
  • URL
Next up: Listing Everything — discovery