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.