learning-it by example

#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.

1. In MCP, which program offers tools and which program wants to use them?
2. What are the three phases of an MCP connection in the June 2025 revision of the Model Context Protocol specification?
3. In the hand-written client over standard input and output, how is each MCP message sent and read?
4. In a Python MCP flight booking demo, a hand-written client booked a made-up flight on a made-up airline server. What did its booking call return?
5. Why should an MCP server that talks over standard input and output never print to standard output?

Practice only: nothing is saved and no score counts towards anything. Each answer comes with the reason.

  1. 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.

  2. 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.

  3. 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.

  4. 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

All AI agents and MCP videos

Related videos