chapter thirteen

13 Bridging LLMs to the real world with the Model Context Protocol

 

This chapter covers

  • Introducing Model Context Protocol (MCP)
  • Developing your own MCP server
  • Using an MCP server with 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 (such as files, websites, or live social media feeds) often requires a custom solution for each source, adding work and complexity.

To solve this problem, a new framework called the Model Context Protocol (MCP) was 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 such as Grok, OpenAI, and Claude can easily use inputs such as search results, uploaded files (PDFs, images, and so on), or real-time social media posts without requiring a special setup for each one.

13.1 What is MCP?

13.1.1 The problems MCP solves

13.1.2 Understanding MCP

13.1.3 MCP server deployment

13.1.4 Components in an MCP server

13.2 Building an 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 a prompt

13.2.9 Testing the components

13.3 Testing the MCP server using 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

Summary