chapter five

5 MCP Tools

 

This chapter covers

  • The MCP ecosystem and MCP architecture
  • Connecting to MCP servers and discovering tools
  • Enabling our LLM agent to use MCP tools

In this chapter, we’ll begin Stage 2 of our build plan by enabling our LLM agent to use tools made available via the Model Context Protocol (MCP).

The adoption of MCP as the standard for how LLM agents connect with external systems has been rapid and widespread. This has resulted in a vast ecosystem of third-party tools that LLM agents (and AI applications more generally) can use to extend their capabilities.

Integrating MCP into our framework requires a solid understanding of the overall MCP architecture. This is where we’ll start, covering concepts such as MCP servers and clients, and learning about MCP primitives in detail.

The infrastructure we built in the previous stage sets us up well to add an MCP integration. To make the MCP tools available to our LLM agent, we’ll introduce two new classes: MCPToolProvider and MCPTool. This is reflected in our updated build plan, as shown in Figure 5.1.

Figure 5.1 We begin stage 2 of our build plan, enabling our LLM agent to use external tools made available via MCP.

5.1 Introducing MCP

5.1.1 The MCP ecosystem

5.1.2 The tool-calling process for an MCP tool

5.1.3 The MCP architecture

5.2 Integrating MCP into our framework

5.2.1 Implementing MCPToolProvider

5.2.2 Implementing MCPTool

5.3 LLMAgentBuilder: a dynamic builder of LLMAgent

5.3.1 Implementing LLMAgentBuilder

5.4 Summary