liveBook · Manning

Dynamic tool discovery

As explained in Build an AI Agent (From Scratch)

Tool discovery is the standardized process by which a client requests and receives the definitions of tools available from a server.

Dynamic tool discovery lets an MCP client ask a server which tools it provides and receive standardized definitions before connecting those tools to an LLM. The server owns the definitions and later handles execution, while the client manages communication and provider-specific adaptation. section 3.4.1

A practical discovery flow follows these steps:

  • Initialize an MCP ClientSession over a transport such as stdio. section 3.4.3
  • Call list_tools() and inspect each returned name, description, and inputSchema. section 3.4.1
  • Convert MCP definitions into the LLM provider’s outer tool format; inputSchema supplies the provider’s parameters field. section 3.4.3
  • Give the converted definitions to the LLM, then route any selected tool call back through the MCP server. section 3.4.1 section 3.4.3

Discovering Tavily tools

A Python client launches tavily-mcp@latest through stdio, initializes the session, calls list_tools(), and prints tools such as tavily_search, tavily_extract, tavily_crawl, and tavily_map. The returned definitions can then be converted with mcp_tools_to_openai_format().

How Build an AI Agent (From Scratch) covers it

How deep it goes
Defines the request-response contract and follows discovery through schema conversion, but stops short of server implementation internals.
Examples
Uses a Tavily MCP server to list tavily_search, tavily_extract, tavily_crawl, and tavily_map.
What it assumes
Assumes familiarity with MCP server-client communication, tool schemas, and provider-specific tool envelopes.
What you can do after
Apply it via an MCP ClientSession: initialize, call list_tools(), convert definitions, and pass them to OpenAI.
How it connects
Connects MCP clients with tool execution, JSON Schema, LLM provider tool formats, and stdio or streamable HTTP transports.

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.