Area 03 · AI Agents · Concept 09 of 20

MCP Clients

The app side (IDE, chat app, your agent) that connects to MCP servers and uses their tools.

01–10 · The basePhase 3 · Weeks 11–14≈ 1.5 hours

The idea

An MCP client starts or connects to servers, asks what tools and resources they offer, and passes those to the model. When the model calls a tool, the client forwards the call to the right server and returns the result.

Desktop chat apps and IDEs are MCP clients configured with a JSON file listing servers. In your own agent you use the SDK’s client session: initialise, list_tools, call_tool.

The client is also where you enforce safety: which servers are allowed, which tools need user approval, and how results are shown.

Why it matters

Writing a client lets your own agents use the whole ecosystem of MCP servers without custom integrations.

Words to know

  • Client sessionA live connection to one MCP server.

Try it without code

Read a client config

  1. Open your desktop app’s MCP config file.
  2. Find the command, args and env for each server.
  3. Add your notes server from the previous lesson.

Use it in code

Connect to a stdio server, list its tools and call one.

python
import asyncio
from mcp import ClientSession, StdioServerParameters
from mcp.client.stdio import stdio_client

params = StdioServerParameters(command="python", args=["server.py"])

async def main():
    async with stdio_client(params) as (read, write):
        async with ClientSession(read, write) as session:
            await session.initialize()
            tools = await session.list_tools()
            print([t.name for t in tools.tools])
            result = await session.call_tool("add_note", {"title": "idea", "body": "Try MCP"})
            print(result.content[0].text)

asyncio.run(main())
# To use with a model: convert each tool's name, description and inputSchema
# into your provider's tool format, and route tool_use calls to session.call_tool.
PRACTICE · TICK IT AFTER THIS

Make your agent loop load tools from an MCP server at startup instead of hard-coded tool definitions.

Common mistakes

  • Auto-approving every tool from every server.
  • Not closing sessions, leaving server processes running.

Go deeper