learning-it by example

#29 AI agents and MCP 5.3 min

MCP Resources and Prompts, Not Just Tools

Tools are only one of three things an MCP server can offer. Here are the other two, and the one default that stopped a file leak.

1. In the Model Context Protocol (MCP), who decides when a tool, a resource and a prompt are used?
2. What does an MCP prompt, such as quote_reply in a bike shop server, do when an MCP client gets it?
3. In the resource template shop://docs/{+path}, what does the plus sign do?
4. In an MCP Python demo, a client asked two servers for shop://docs/../staff_pay, a private file one folder above the docs folder. What happened on the server that kept the SDK's default path check, and on the one where it was switched off?
5. In the MCP Python SDK, a default check stops a resource template from reading files outside its docs folder. What does that check cover?

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

  1. List what the server offers

    Copy the code folder first. With the mcp package from the video installed, run python client.py. Check that you see one tool, one resource, one template and one prompt, and that the prompt role is user. Then write down, for each of the four, who decides when it is used: the model, the application or the user.

    A hint

    The video's own run listed book_slot, shop://opening-hours, shop://docs/{+path} and quote_reply.

  2. See why a path can escape

    In a Python prompt in the code folder, set docs to Path('docs').resolve() and build two paths: (docs / 'returns.txt').resolve() and (docs / '../staff_pay.txt').resolve(). For each, check whether its parent equals docs. Predict first. We got True for the first and False for the second, and the second file exists. Write one sentence on what the SDK's path check protects.

    A hint

    Import Path from pathlib. The two dots mean one folder up.

  3. Add a policy document

    Create docs/shipping.txt with one line that starts with Shipping:, then change client.py to read shop://docs/shipping instead of warranty. Predict what the line labelled warranty in the output now shows (the label stays the same), then run python client.py with the mcp package installed. This is a prediction task: we did not run the server.

    A hint

    The resource template adds .txt to the path, so use the name without the extension.

  4. Add a second prompt

    In server.py add a second prompt function called order_update that takes a customer and an order number and returns a short message. Write it like quote_reply, with the decorator and a docstring, and put it above the line that starts with if __name__, because that block starts the server and anything written after it is never registered. Predict what the prompts line in python client.py shows, then run it with the mcp package installed. This is a prediction task: we did not run the server.

    A hint

    Use the same decorator as quote_reply. The prompts line prints the names of all prompts.

These tasks are for you to try on your own machine. Nothing is checked or saved.

What this does not show

The shop and every file are made up, including the private one. Tested with the SDK's own client only, one template form and one transport. The path check covers template arguments, not other ways to build a path.

Up next in AI agents and MCP

More in AI agents and MCP

All AI agents and MCP videos

Related videos