cd /news/artificial-intelligence/day-24-30-mcp-primitives-explained · home topics artificial-intelligence article
[ARTICLE · art-84341] src=dev.to ↗ pub= topic=artificial-intelligence verified=true sentiment=· neutral

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.

read4 min views1 publishedAug 3, 2026

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:

import langgraph as lg
from mcp import Tool, Resource, Prompt

class FlightFinder(Tool):
    def __init__(self, flight_database):
        self.flight_database = flight_database

    def find_flights(self, preferences):
        flights = self.flight_database.query(preferences)
        return flights

class FlightDatabase(Resource):
    def __init__(self):
        self.flights = [...]  # Initialize with some sample flight data

    def query(self, preferences):
        return [flight for flight in self.flights if flight.matches(preferences)]

class FlightDescriptionPrompt(Prompt):
    def __init__(self):
        pass

    def generate_description(self, flight):
        return f"Flight {flight.number} from {flight.departure} to {flight.arrival} at {flight.time}"

flight_finder = FlightFinder(FlightDatabase())
flight_description_prompt = FlightDescriptionPrompt()

preferences = {"departure": "New York", "arrival": "Los Angeles", "time": "morning"}
flights = flight_finder.find_flights(preferences)

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.

── more in #artificial-intelligence 4 stories · sorted by recency
── more on @langgraph 3 stories trending now
sponsored brought to you by zahid.host 4,200+ EU-deployed projects
reading about agents? ship yours in a single git push.

Run your AI side-project on zahid.host

EU-based hosting, git-push deploys, automatic HTTPS, no cold starts. Free tier with a custom domain — perfect for shipping the agent you just read about.

$git push zahid main
Live at https://your-agent.zahid.host
Get free account → Pricing
from €0/mo · no card required
LIVE [news/day-24-30-mcp-primit…] indexed:0 read:4min 2026-08-03 ·