The following examples walk throught the core concept of MCP which includes:
- sampling
- call tool
- list tool
- roots
- logging & notification
MCP Server allow us to gains access to data & functionality to the outside (third-party) service. Think of MCP as a standard way to for LLM to communicate with database, files, APIs, and internal tools.
Without MCP, LLM integration look like this: user -> app -> custom tool logic -> LLM
Every tool integration is custom built:
- custom auth
- custom api wrapper
- custom schema
- custom error handling
With MCP: user -> LLM -> MCP Client -> MCP Server -> Tools Instead of writing custom tool definition, you expose tools via MCP and any MCP-compatible model can adopt this.
This project demonstrates how to use the MCP framework to sample text from a model. Sampling allows a server to access a language model like Claude through a connected MCP client. Instead of the server directly calling Claude, it asks the client to make the call on its behalf. This shifts the responsibility and cost of text generation from the server to the client.
Logging and progress notifications are simple to implement but make a huge difference in user experience when working with MCP servers. They help users understand what's happening during long-running operations instead of wondering if something has broken.
Roots are a way to grant MCP servers access to specific files and folders on your local machine. Think of them as a permission system that says "Hey, MCP server, you can access these files" - but they do much more than just grant permission.