13 Bridging LLMs to the Real World with the Model Context Protocol (MCP)

 

This chapter covers:

  • Introduction to Model Context Protocol (MCP)
  • Developing your own MCP server
  • Using a MCP server with the Claude Desktop
  • Using third party MCP servers

As large language models (LLMs) become more advanced, developers face a key challenge: making it easier for these models to work with external data that wasn’t part of their original training. Right now, connecting LLMs to different types of data (like files, websites, or live social media feeds) often requires a custom solution for each source. This adds extra work and complexity.

To solve this, a new framework called the Model Context Protocol (MCP) has been introduced. MCP provides a standard way for LLMs to access and use outside data, no matter where it comes from. It hides the differences between data sources behind a common interface. With MCP, models from providers like Grok, OpenAI, and Claude can easily use inputs like search results, uploaded files (PDFs, images, etc.), or real-time social media posts — without needing a special setup for each one.

Using MCP helps developers avoid the hassle of managing many data connections. It also lets LLMs bring in real-time information — like today’s date or current weather — directly into their responses. MCP also supports more advanced use cases, like analyzing live datasets, and it’s built to handle new types of data in the future.

13.1 What is Model Context Protocol (MCP)?

13.1.1 The Problems MCP Solves

13.1.2 Understanding MCP

13.1.3 MCP Servers Deployment

13.1.4 Components in a MCP Server

13.2 Building Your Own MCP Server

13.2.1 Installing uv

13.2.2 Initializing the project

13.2.3 Installing the packages

13.2.4 Creating the MCP server

13.2.5 Inspecting the MCP server

13.2.6 Implementing Resources

13.2.7 Implementing Tools

13.2.8 Implementing Prompts

13.2.9 Testing the components

13.3 Testing the MCP Server using the Claude Desktop

13.3.1 Configuring Claude Desktop to use the MCP Server

13.3.2 Getting the Weather

13.3.3 Getting the Content of a text file

13.3.4 Getting the Content of a PDF file

13.3.5 Improving the MCP Server

13.4 Trying out Third Party MCP Servers

13.4.1 Location service

13.4.2 Time service

13.5 Summary