#292 AI agents and MCP 5.7 min
MCP Explained Simply: A Flight Booking Demo in Python
People talk about MCP like magic, so I spoke it by hand, in plain JSON lines.
Predict the search results
Copy the code folder first. This needs the mcp package from requirements.txt, so this is a prediction task. Read the FLIGHTS table in server.py and predict how many flights search_flights returns for Leeds to Dublin, and for Leeds to Paris. Then check the first number against the video, which showed 2 flights.
A hint
The function keeps flights where both the from city and the to city match.
Predict a booking code
In server.py read book_flight. Predict the text it returns if raw.py books FL300 for a passenger called Sam as the first booking, and the text it returns for a flight that is not in the table. Compare with the format string in the code.
A hint
The code number is the count of bookings so far, with 3 digits.
Find the four requests
In raw.py find the four requests with ids 1 to 4 and the one notification that has no id. Write down each method name, and say which one is the hello. Predict what would happen if the client sent tools/list before the hello had been answered, and compare with the video's list of mistakes, which only says this is a mistake. If you try it by sending a tools/list line first, the server answers with an error (code -32602) instead of a result.
A hint
The notification is sent right after the hello reply.
Add a flight to the table
In server.py add a fourth flight, for example FL400 from Leeds to Dublin at a price of 75. Predict how many flights each client will say it found. Then, if you have the mcp package installed as the video requires, run python raw.py and python client.py to check. If you cannot run it, read the code to decide.
A hint
Both clients search for Leeds to Dublin and print the number of flights.
These tasks are for you to try on your own machine. Nothing is checked or saved.
What this does not show
A made-up airline server on one machine over standard input and output, with two tools; the calls are scripted, no model chooses them, and nothing checks who is asking; resources, prompts and the web transport are not shown.
Up next in AI agents and MCP
More in AI agents and MCP
- #01 Local AI Agent in Python: No API Key (Ollama)
- #12 Multi-Agent Patterns in Plain Python: Pipeline, Router, Loop
- #22 OpenAI Agents SDK vs LangGraph vs Plain Python
- #23 Agent Memory: What to Keep and What to Forget
- #24 Approval Gates for Risky Agent Actions
- #25 Tool Errors: Retries, Fallbacks and Made-Up Answers
