chapter thirteen

13 Building and consuming MCP servers

 

This chapter covers

  • The purpose and architecture behind the Model Context Protocol (MCP)
  • Building and exposing your own MCP server, with a practical weather tool example
  • Testing and consuming MCP servers and related tools in applications
  • Integrating remote MCP tools into agents alongside local tools

Building AI agents that can reliably access and use external context is one of the central challenges for application developers. Until recently, integrating data from multiple sources meant wrapping each one as a tool, often using different protocols—a repetitive, time-consuming task duplicated across teams.

The Model Context Protocol (MCP), introduced by Anthropic, solves this problem by defining a unified way for services to expose tools through MCP servers. Agents, or MCP hosts, connect to these servers via MCP clients, discovering and invoking remote tools as easily as local ones. This shifts integration work to where it belongs—at the source—so developers can focus on building capable agents rather than re-implementing the same wrappers. Once connected, MCP tools slot seamlessly into existing agent architectures.

13.1 Introduction to MCP Servers

13.1.1 The Problem: Context Integration at Scale

13.1.2 The Solution: The Model Context Protocol (MCP)

13.1.3 The MCP Ecosystem

13.2 How to Build MCP Servers

13.2.1 Essential Resources for MCP Server Development

13.2.2 Official Language-Specific MCP SDKs

13.2.3 Consuming MCP Servers in LLM Applications and Agents

13.3 Building a Weather MCP Server

13.3.1 Implementing the MCP Server

13.3.2 Trying out the MCP Server with MCP Inspector

13.3.3 Consuming the MCP Server from a Test MCP Host

13.4 Integrating the Weather MCP Tool into an Agent

13.4.1 Preparing the Travel Agent for Live Weather Data

13.4.2 Integrating the AccuWeather MCP Tool

13.4.3 Updating the Agent Chat Loop

13.4.4 Combining Local and Remote Tools

13.4.5 Testing and Verification

13.4.6 Using the Agent for Complex Queries

13.5 Summary