Day 24/30: MCP Primitives Explained A developer detailed the Model Context Protocol (MCP) primitives—tools, resources, and prompts—after debugging a LangGraph-based flight-booking agent that failed to match user preferences due to insufficient prompt context. The post explains each primitive's purpose and provides a Python example using LangGraph and MCP classes. I recently spent a frustrating afternoon debugging a LangGraph-based agentic AI system that was supposed to book flights for users. The system would correctly identify the user's travel preferences, but then it would inexplicably suggest flights that didn't match those preferences. After hours of poring over the code, I finally tracked down the issue: the system was using an MCP prompt to generate flight options, but it wasn't providing enough context for the prompt to produce relevant results. This experience taught me the importance of understanding the different primitives available in the Model Context Protocol MCP . In MCP, you have three main types of primitives: tools, resources, and prompts. Each of these primitives serves a distinct purpose, and knowing when to use each one is crucial for building effective agentic AI systems. Let's start with tools. Tools are reusable functions that can be used to perform specific tasks within your agentic AI system. They're like libraries that you can call upon to handle common tasks, such as data processing or API interactions. In the context of my flight-booking system, a tool might be a function that takes a user's travel preferences as input and returns a list of suitable flights. Resources, on the other hand, are pieces of information that your system can draw upon to inform its decision-making. They might include databases, APIs, or even simple data structures like lists or dictionaries. In my system, a resource might be a database of flight information, including departure and arrival times, prices, and availability. Prompts, as I learned the hard way, are used to generate text or other output based on a given input. They're like a conversational AI that can respond to questions or statements. In my system, a prompt might be used to generate a natural-language description of a flight option, based on the user's preferences and the available flight data. So, when should you use each of these primitives? The key is to think about the specific task you're trying to accomplish. If you need to perform a specific, well-defined task, a tool is probably the way to go. If you need to access or manipulate some kind of data, a resource is likely a better choice. And if you need to generate text or other output based on a given input, a prompt is the way to go. Here's an example of how you might use these primitives in a real-world system: python import langgraph as lg from mcp import Tool, Resource, Prompt Define a tool that takes a user's travel preferences and returns a list of suitable flights class FlightFinder Tool : def init self, flight database : self.flight database = flight database def find flights self, preferences : Use the flight database to find flights that match the user's preferences flights = self.flight database.query preferences return flights Define a resource that represents the flight database class FlightDatabase Resource : def init self : self.flights = ... Initialize with some sample flight data def query self, preferences : Return a list of flights that match the user's preferences return flight for flight in self.flights if flight.matches preferences Define a prompt that generates a natural-language description of a flight option class FlightDescriptionPrompt Prompt : def init self : pass def generate description self, flight : Use the flight data to generate a natural-language description return f"Flight {flight.number} from {flight.departure} to {flight.arrival} at {flight.time}" Create instances of the tool, resource, and prompt flight finder = FlightFinder FlightDatabase flight description prompt = FlightDescriptionPrompt Use the tool to find flights that match the user's preferences preferences = {"departure": "New York", "arrival": "Los Angeles", "time": "morning"} flights = flight finder.find flights preferences Use the prompt to generate a natural-language description of each flight option for flight in flights: description = flight description prompt.generate description flight print description One practical gotcha to watch out for when working with MCP primitives is the temptation to overuse prompts. While prompts can be incredibly powerful, they can also be computationally expensive and may not always produce the desired results. Make sure to carefully consider the trade-offs before reaching for a prompt to solve a particular problem. As we move forward in our journey to build more sophisticated agentic AI systems, we'll be exploring even more advanced techniques for combining these primitives to achieve complex tasks. Tomorrow, we'll be diving deeper into the world of LangGraph and MCP, and exploring new ways to push the boundaries of what's possible with these powerful tools.