Phase 13: Tools & Protocols

Building an MCP Client: Discovery, Routing, and Dual-Era Fallback

A modern MCP client repeats its contract on every request. Its hardest compatibility decision is knowing when an old server is truly old and when a modern server is reporting a correctable error. Build every MCP 2026-07-28 request with current metadata. Probe stdio servers with server/discover and select a mutually supported version. Authorize a bounded legacy probe only for explicitly allowlisted peers. Accept a legacy era only after validating a positive initialize result for a supported revision. Merge deterministic tool lists without silently overwriting collisions. Route calls to the peer that owns each tool without inventing protocol sessions. An agent host usually talks to more than one MCP server. It must discover each server, merge tool catalogs, resolve duplicate names, route calls, and recover from transport failure. The 2026-07-28 revision makes the steady state simpler because each request is self-contained. Compatibility makes startup more subtle. A client may encounter: a modern server that supports the preferred version;. a modern server that returns a recognized version or header error;. a legacy server that has never heard of server/discover;. a legacy server that stays silent until it receives initialize. Treating every probe error as legacy is dangerous. A malformed modern request, an overloaded server, a dead process, and an old server can all produce the same timeout or connection close. Those signals…

Building an MCP Client: Discovery, Routing, and Dual-Era Fallback: A modern MCP client repeats its contract on every request. Its hardest compatibility…

This free lesson is part of the AI Engineering from Scratch curriculum. Read the full explanation, run the lesson code, and verify the result in the interactive reader or from the repository source.

Browse the complete course catalog or open this lesson on GitHub.