{"slug": "day-24-30-mcp-primitives-explained", "title": "Day 24/30: MCP Primitives Explained", "summary": "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.", "body_md": "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.\n\nThis 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.\n\nLet'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.\n\nResources, 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.\n\nPrompts, 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.\n\nSo, 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.\n\nHere's an example of how you might use these primitives in a real-world system:\n\n``` python\nimport langgraph as lg\nfrom mcp import Tool, Resource, Prompt\n\n# Define a tool that takes a user's travel preferences and returns a list of suitable flights\nclass FlightFinder(Tool):\n    def __init__(self, flight_database):\n        self.flight_database = flight_database\n\n    def find_flights(self, preferences):\n        # Use the flight database to find flights that match the user's preferences\n        flights = self.flight_database.query(preferences)\n        return flights\n\n# Define a resource that represents the flight database\nclass FlightDatabase(Resource):\n    def __init__(self):\n        self.flights = [...]  # Initialize with some sample flight data\n\n    def query(self, preferences):\n        # Return a list of flights that match the user's preferences\n        return [flight for flight in self.flights if flight.matches(preferences)]\n\n# Define a prompt that generates a natural-language description of a flight option\nclass FlightDescriptionPrompt(Prompt):\n    def __init__(self):\n        pass\n\n    def generate_description(self, flight):\n        # Use the flight data to generate a natural-language description\n        return f\"Flight {flight.number} from {flight.departure} to {flight.arrival} at {flight.time}\"\n\n# Create instances of the tool, resource, and prompt\nflight_finder = FlightFinder(FlightDatabase())\nflight_description_prompt = FlightDescriptionPrompt()\n\n# Use the tool to find flights that match the user's preferences\npreferences = {\"departure\": \"New York\", \"arrival\": \"Los Angeles\", \"time\": \"morning\"}\nflights = flight_finder.find_flights(preferences)\n\n# Use the prompt to generate a natural-language description of each flight option\nfor flight in flights:\n    description = flight_description_prompt.generate_description(flight)\n    print(description)\n```\n\nOne 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.\n\nAs 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.", "url": "https://wpnews.pro/news/day-24-30-mcp-primitives-explained", "canonical_source": "https://dev.to/yashwanth_kasi/day-2430-mcp-primitives-explained-1ldi", "published_at": "2026-08-03 06:10:23+00:00", "updated_at": "2026-08-03 06:43:04.145647+00:00", "lang": "en", "topics": ["artificial-intelligence", "ai-agents", "developer-tools"], "entities": ["LangGraph", "Model Context Protocol", "MCP"], "alternates": {"html": "https://wpnews.pro/news/day-24-30-mcp-primitives-explained", "markdown": "https://wpnews.pro/news/day-24-30-mcp-primitives-explained.md", "text": "https://wpnews.pro/news/day-24-30-mcp-primitives-explained.txt", "jsonld": "https://wpnews.pro/news/day-24-30-mcp-primitives-explained.jsonld"}}