Building an MCP Client — Discovery, Invocation, Session Management

Most MCP content ships server tutorials and waves a hand at the client. Client code is where the hard orchestration lives: process spawning, capability negotiation, tool list merging across multiple servers, sampling callbacks, reconnection, and namespace collision resolution. This lesson builds a multi-server client that lifts three different MCP servers into one flat tool namespace for the model.

Build 1.3 hr Python (stdlib, multi-server MCP client)

Prerequisites: Phase 13 · 07 (building an MCP server)

#Learning Objectives

  • Spawn an MCP server as a child process, complete initialize, and send a notifications/initialized.
  • Maintain per-server session state (capabilities, tool list, last-seen notification ids).
  • Merge tool lists across multiple servers into one namespace with collision handling.
  • Route a tool call to the server that owns it and reassemble the response.
Full Access lesson

Keep going. The rest of this lesson is one step away.

Unlock all 503 lessons, video, code, quizzes and every future update. Pay in your own currency with Paystack.

The text and code of this lesson are based on AI Engineering from Scratch by Rohit Ghumare, MIT licensed.