Chapter 5. Building MCP Servers: Providing Tools, Prompts and Resources to Applications
On the other side of the MCP equation from the client is the server. In Chapter 3, the client examples all made use of a server that gave the host application the ability to do math. This serverwas pre-built and was run locally. In this chapter, our examples will show the construction of this same server from scratch, including all of the primitives and features that servers can provide to clients and host applications. We will begin with a high-level view of the server, including what servers do and how they’re useful, how they connect to clients, and the two main paths for building them with the Python SDK. Then, we will get right into the details:
-
server primitives (tools, prompts, and resources) and how to serve them
-
server utilities (completion, logging, notifications, and pagination) and how to use them
-
server security
-
using client-provided resources like sampling and elicitation
As a server ...