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 effectively access and use external context is a central challenge for application developers. Previously, integrating context from different sources meant wrapping each one as a tool, following specific protocols—a time-consuming and repetitive process repeated by countless teams. Imagine if, instead, data and service providers could expose their resources as ready-made tools, instantly available for any agent or application. This is the promise of the Model Context Protocol (MCP), introduced by Anthropic.
MCP defines a standardized way for services to expose “tools” through MCP servers. Agents, or “MCP hosts,” connect to these servers via MCP clients, discovering and using remote tools as easily as local ones. This approach moves much of the integration work to where it belongs—at the source—allowing developers to focus on building more capable agents rather than reinventing the same plumbing. Once the connection is set up, tools from MCP servers work seamlessly with existing agent architectures.