liveBook · Manning

Mcp client

As explained in Build an AI Agent (From Scratch)

An MCP client is the protocol component that connects a host application to one MCP server, retrieves tool definitions, and forwards tool-execution requests.

An MCP client bridges a host application and one MCP server. When the host decides that an agent needs a tool, the client discovers available definitions, forwards execution requests, and returns results. section 3.4.1

The client hides protocol details while exposing a practical session interface: establish a connection, initialize the session, list tools, call a named tool with arguments, and parse the returned result. This separates the agent’s reasoning from tool communication. section 3.4.3

A programmatic client commonly performs these steps:

  • Configure how to launch the server with StdioServerParameters, including the command, arguments, environment variables, and API key. section 3.4.3
  • Open stdio_client as a subprocess context and create a ClientSession over its read and write streams. section 3.4.3
  • Call initialize(), then use list_tools() to retrieve names, descriptions, and parameter schemas. section 3.4.3
  • Call call_tool() with a tool name and argument dictionary; the server executes the tool and returns the result. section 3.4.3
  • Convert MCP schemas into the format required by the selected LLM provider before exposing tools to the model. section 3.4.1

Tavily search client

A Python client launches tavily-mcp@latest through npx, passes TAVILY_API_KEY, initializes a session, lists Tavily tools, and calls tavily_search with a query. Async context managers clean up the subprocess and communication streams.

How Build an AI Agent (From Scratch) covers it

How deep it goes
Explains lifecycle, stdio setup, session methods, schemas, and result handling, stopping short of broader production reliability details.
Examples
Uses a Python Tavily subprocess client, tool listings, a web-search call, and MCP-to-OpenAI schema conversion.
What it assumes
Assumes a host with an LLM and an MCP server, while teaching client connections, sessions, discovery, execution, and schema adaptation.
What you can do after
Builds a Python client that launches an MCP server, discovers tools, invokes them, and adapts schemas for an LLM provider.
How it connects
Connects host applications, MCP servers, tool discovery, tool execution, stdio transport, and LLM tool formats.

Also explained in

Compare how 8 books explain mcp client →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Build an AI Agent (From Scratch). The section links point to the parts of the book it draws on.