Understanding MCP Prompts
You have now built Tools to give the model hands (actions) and Resources to give the model eyes (context). The final piece of the puzzle is Prompts.
While Tools and Resources are designed for the Model and the Application respectively, Prompts are designed for the User.
What Are Prompts?
An MCP Prompt is a pre-defined template that users can select to start a conversation with an LLM.
Think about the friction users face when staring at a blank chat box. They might want to plan a complex trip, but they don’t want to type out a long paragraph like:
“Please act as a travel agent. I want to go to Paris. I am leaving from London. I want to stay for 5 days. Please make sure the budget is moderate and include local food recommendations…”
This is tedious and error-prone.
MCP allows the server to define this structure as a Prompt. The server provides a template named plan-trip that asks for specific arguments: destination and days.
The Interaction Flow
It is important to understand that LLMs do not access Prompts.
Prompts are a UI convenience feature. Here is the flow:
- Selection: The user sees a list of available prompts in their client (like Claude Desktop or an IDE) and selects “Plan Itinerary”.
-
Input: The UI asks the user to fill in the blanks:
- Destination: “Paris”
- Days: “5”
- (The user does not need to type the full instruction paragraph).
- Generation: The MCP Server takes those inputs, fills them into a hidden text template, and returns the full, detailed instruction text to the Host Application.
- Submission: The Host Application pastes that detailed text into the chat, effectively speaking on the user’s behalf.
This ensures that the LLM receives a high-quality, structured request every time, without the user needing to be a “prompt engineering” expert.
Building a Prompt Server
You will now create a server that provides a travel itinerary helper. Ensure you are still inside your lesson_2 directory.
Create a new file named prompts_demo_server.py and add the following code:
from mcp.server.fastmcp import FastMCP
mcp = FastMCP("Prompt Demo")
@mcp.prompt()
def draft_itinerary(destination: str, days: int) -> str:
"""Creates a prompt for the LLM to generate a travel plan."""
return f"""
Please create a detailed {days}-day itinerary for a trip to {destination}.
1. List specific tourist attractions.
2. Recommend local food.
3. Keep the budget moderate.
"""
if __name__ == "__main__":
mcp.run(transport="streamable-http")
Analyzing the Code
-
@mcp.prompt(): This decorator registers the function as a user-facing prompt. -
Arguments: The function arguments (
destination,days) automatically become the form fields the user needs to fill out in the UI. - Return Value: The string returned by this function is exactly what will be sent to the LLM.
Running the Server
Run your prompt server using uv:
$ uv run --with mcp prompts_demo_server.py
Your server is now running. It holds a template ready to be filled, but it won’t do anything until a user (or a developer tool) asks for it.
In the next section, you will finally stop running these servers in isolation and start interacting with them using the MCP Inspector.