← Master Index
Vol. 15 Module 15.3 Lecture

MCP Client

Model Context Protocol — MCP (added)

How This Lesson Fits the Module & Volume

The MCP server exposes capabilities. The MCP client lives inside the host—Claude Desktop, Cursor, or your LangGraph runtime—and translates agent tool calls into protocol requests. Confusing client with server is the most common 15.3 error.

After this lecture you will specialize: tools (actions) vs resources (readable context). Memory from 15.2 still applies: client results land in working memory.

Learning Objectives

By the end of this lesson, students should be able to:

  • Define the MCP client as the host-side protocol speaker.
  • Contrast host vs client vs server responsibilities.
  • Describe the client lifecycle: connect, initialize, discover, invoke, tear down.
  • Explain how listed tools become LLM function/tool schemas.
  • Place HITL approval on the client/host, not on the remote server alone.
  • Connect multiple servers to one host without merging trust domains blindly.
Definition

An MCP client is the component, embedded in an AI host, that maintains a session with one MCP server: it performs the JSON-RPC handshake, caches the tool/resource catalog, invokes calls on behalf of the model, and returns results into the host’s agent loop.

Host vs Client vs Server

RoleOwnsDoes not own
HostUX, model, memory, HITL, multi-agent graphDownstream DB/API details
ClientMCP session, catalog cache, call routingBusiness I/O implementation
ServerTools/resources implementation + ACLsPlanning / which tool to pick

One host often runs many clients (one session per server). That is how an IDE can attach Git, Slack, and Postgres at once.

Client Lifecycle

Connect

  • Spawn stdio or open HTTP
  • initialize + ack
  • Store server capabilities

Discover

  • tools/list, resources/list
  • Map to LLM tool schemas
  • Refresh on notifications

Invoke

  • Model emits a tool call
  • Host may require HITL
  • Client sends tools/call

Bridging MCP Tools to the Agent Loop

# Conceptual host-side client wrapping one MCP server class McpClientSession: def __init__(self, transport, allowlist: set[str] | None = None): self.transport = transport self.allowlist = allowlist self.tools: list[dict] = [] def start(self) -> None: self.transport.request("initialize", {"protocolVersion": "2024-11-05", "capabilities": {}}) listed = self.transport.request("tools/list", {}) self.tools = listed["tools"] def as_llm_tools(self) -> list[dict]: out = [] for t in self.tools: if self.allowlist and t["name"] not in self.allowlist: continue out.append({ "type": "function", "function": { "name": t["name"], "description": t.get("description", ""), "parameters": t.get("inputSchema", {"type": "object"}), }, }) return out def invoke(self, name: str, arguments: dict, approved: bool) -> str: if not approved: return "BLOCKED: human approval required" result = self.transport.request("tools/call", {"name": name, "arguments": arguments}) texts = [c["text"] for c in result.get("content", []) if c.get("type") == "text"] return "\n".join(texts) or str(result) # Host agent loop: llm.choose(tools) -> session.invoke(...) -> append to working memory

Policy Belongs on the Client/Host

Servers enforce data ACLs; hosts enforce product policy: which servers are installed, which tools are allowlisted, which calls need HITL, how results are compacted into working memory, and whether to write recaps into episodic LTM. A client that auto-approves every tools/call is a foot-gun.

Strengths

  • One host can multiplex many servers
  • Natural point for allowlists and HITL
  • Translates MCP schemas ↔ model tool APIs
  • Keeps agent frameworks server-agnostic

Tradeoffs

  • Catalogs go stale without refresh
  • Name collisions across servers
  • Latency stacking (model + RPC)
  • Misconfigured client = silent capability leak
Common Misconception

“The MCP client is a separate product the user installs, like the server.” Users install servers (and configure hosts). The client is library code inside Claude Desktop, Cursor, or your agent runtime. If you are writing a custom host in LangGraph, you embed the client SDK.

Knowledge Check

  1. Short Answer: Where does the MCP client run? Answer: Inside the host (IDE, chat app, or agent runtime).
  2. True/False: One host may open multiple MCP client sessions. Answer: True—typically one per server.
  3. Multiple Choice: Mapping tools/list → OpenAI-style function schemas is done by the: (a) GPU driver, (b) client/host, (c) vector index. Answer: (b).
  4. Short Answer: Who should usually enforce HITL approval for dangerous tools? Answer: The host/client policy layer.
  5. True/False: The client implements lookup_ticket against the database. Answer: False—the server does.
  6. Multiple Choice: Name collisions across servers are handled by: (a) ignoring them, (b) namespacing/allowlists in the host, (c) CNNs. Answer: (b).
  7. Short Answer: What happens to tool results after invoke? Answer: They enter the host’s working memory / agent loop.
  8. True/False: Users typically install MCP clients from a marketplace, not servers. Answer: False—they install/configure servers; clients are embedded.
  9. Multiple Choice: initialize is sent by the: (a) client to the server, (b) database to the LLM, (c) user to DNS. Answer: (a).
  10. Short Answer: Next lecture focuses on invocable MCP actions named what? Answer: MCP Tools.

Key Takeaways

  • The client is host-side protocol + catalog + invocation glue.
  • Hosts multiplex clients; servers stay implementation details.
  • Allowlists, HITL, and memory compaction belong with the client/host.
  • Do not confuse installing a server with “installing a client app.”
  • Continue with MCP Tools.
Trainer’s Guide

Lab: Given two fake servers both exposing search, design a host allowlist + prefix (jira.search vs wiki.search) and show the LLM tool list.

Whiteboard: Sequence diagram with HITL gate between model tool call and client.invoke.

Recap: The MCP client is the host’s protocol adapter. Continue with MCP Tools.