Sub topic 9
Reusable prompts for common workflows
This chapter assumes you have a working FastMCP server with at least one tool, as built in the earlier chapters. You should also know what a JSON-RPC request and response look like. The chapter shows how to package a recurring instruction as an MCP prompt, so teammates can start a workflow with the same wording every time.
What a prompt is in MCP
An MCP prompt is a named, parameterized message template that a server publishes. The host application lists the prompts, and the user picks one. Many hosts show prompts as slash commands or menu entries. The server fills in the template with the user's arguments and returns one or more messages. The host then sends those messages to the model.
The key property is who decides to use it. The protocol's design intent for each primitive is different:
| Primitive | Who triggers it | Typical effect | Example from this tutorial |
|---|---|---|---|
| Tool | The model | Runs code, may change state | `get_service_owner` |
| Resource | The application or user | Supplies read-only context | `runbook://billing` |
| Prompt | The user | Starts a workflow with a prepared message | `incident_summary` |
A prompt does not run your business logic against a live system. It builds text. If you want the model to look up an owner, that is a tool. If you want every engineer to ask for an incident summary in the same way, that is a prompt.
The protocol exchange
Prompts use two requests. A server that supports them declares a prompts capability during initialization, which you saw in the lifecycle chapter. FastMCP does this for you as soon as you register one.
- The client sends
prompts/list. The server replies with each prompt's name, description, and argument definitions. - The user selects a prompt and fills in the arguments. The client sends
prompts/getwith the name and anargumentsobject. - The server replies with an optional description and a list of messages. Each message has a
role(userorassistant) andcontent.
All argument values travel as strings in prompts/get. Keep that in mind when you design arguments. A numeric limit arrives as "5", not 5.
A first prompt
The earlier chapters already defined incident_summary. A function that returns a plain str is treated as a single user message. Here is a complete file that adds a second prompt with several messages.
import logging
import sys
from mcp.server.fastmcp import FastMCP
from mcp.server.fastmcp.prompts import base
logging.basicConfig(stream=sys.stderr, level=logging.INFO)
mcp = FastMCP("team-tools")
RUNBOOKS = {
"billing": "1. Check the queue depth.\n2. Restart the worker.\n3. Page payments-team.",
}
@mcp.prompt()
def incident_summary(service: str) -> str:
"""Ask the model to draft an incident summary for a service."""
return (
f"Draft a short incident summary for the {service} service. "
"Include impact, current status, and next steps."
)
@mcp.prompt(
name="triage_alert",
description="Start triage for an alert using the service runbook.",
)
def triage_alert(service: str, severity: str = "high") -> list[base.Message]:
runbook = RUNBOOKS.get(service, "No runbook found.")
return [
base.UserMessage(
f"An alert fired for the {service} service with severity {severity}. "
"Use the runbook below to propose the first three actions."
),
base.UserMessage(f"Runbook:\n{runbook}"),
base.UserMessage(
"Call get_service_owner if you need to know who to page. "
"Do not claim an action was taken unless a tool confirms it."
),
]
if __name__ == "__main__":
mcp.run()FastMCP builds the argument list from the function signature. service has no default, so the client marks it as required. severity has a default, so it is optional. The function's docstring becomes the description unless you pass description=. Check your installed SDK version for the exact decorator options, because the Python SDK is still changing.
Choosing roles and message structure
The role field is part of the protocol. FastMCP gives you base.UserMessage and base.AssistantMessage. Most team prompts only need user messages. An assistant message is useful when you want to show the model a sample of the expected answer format. Put the example in the assistant role and the real request after it, so the model follows the pattern.
@mcp.prompt()
def release_notes(version: str) -> list[base.Message]:
"""Draft release notes for a version in the team's format."""
return [
base.UserMessage("Write release notes for v1.3.9 in our format."),
base.AssistantMessage(
"## v1.3.9\n- Fixed: retry loop in the billing worker\n- Changed: queue timeout is now 30s"
),
base.UserMessage(
f"Now write release notes for {version}. "
"Ask me for the change list if you do not have it."
),
]This prompt belongs in the same file, below the others and above the if __name__ block. The sample is invented text and carries no real data. Use fictional examples so the model does not copy a real incident into a new answer.
Prompts, resources, and tools together
A prompt can tell the model which tools and resources to use, but it cannot force the model to use them. Name them in the text, as triage_alert does with get_service_owner. This keeps the workflow readable, and it works even in hosts that handle prompts differently.
The protocol also lets a prompt message include an embedded resource, so the host receives the runbook as a resource object instead of pasted text. Support varies by host, so inlining text, as triage_alert does, is the safe default. Embed a resource only when you know your team's host renders it.
Decide between the three primitives with these questions:
- Does the model need to decide on its own to call it? Use a tool.
- Is it reference data that is addressed by a stable name? Use a resource.
- Is it a repeatable request that a person starts? Use a prompt.
If the same instruction is typed into chat by five people each week, it is a prompt candidate.
Testing prompts
Start the Inspector from the earlier chapter:
npx @modelcontextprotocol/inspector python server.pyOpen the Prompts tab and list the prompts. Select triage_alert, fill in service with billing, and request the prompt. The Inspector shows the returned messages. Check three things:
- The required and optional arguments match what you intended.
- The messages are in the order and roles you expect.
- A missing or unknown value produces a message you can understand.
The raw request the client sends looks like this:
{
"jsonrpc": "2.0",
"id": 7,
"method": "prompts/get",
"params": {
"name": "triage_alert",
"arguments": { "service": "billing", "severity": "critical" }
}
}The response contains a messages array, where each item has a role and a content object with type: "text" and the text.
Common errors
- Prompt does not appear in the host. The host may not support prompts, or it may have cached the list. Hosts differ here, and some ignore prompts completely. Confirm in the Inspector first. If it works there, the server is correct.
- Missing required argument. The call to
prompts/getfails with a JSON-RPC error. Give arguments sensible defaults when you can, so the user has less to fill in. - Wrong type assumptions. Arguments arrive as strings. Pydantic usually converts
"5"to an integer in a function annotatedint, but a value such as"five"is rejected. Prefer string arguments plus your own checks for free-form values. - Output on stdout. With stdio, a stray
printin a prompt function corrupts the protocol stream. Useloggingto stderr as shown at the top of the file. - Unbounded content. If a prompt inlines a large runbook or log, it may exceed the model's context window. Truncate and say so in the text.
Designing prompts that people reuse
- Name for the task.
triage_alertandrelease_notesdescribe a job.prompt1does not. - Write the description for a menu. Users see it in a picker, so state in one line what they will get.
- Keep arguments few. Two or three. Each extra argument is a field someone has to fill in.
- State the output format. Say whether you want bullets, a table, or a paragraph, and set length limits.
- Add guardrails in the text. Phrases such as "do not claim an action was taken unless a tool confirms it" reduce false reports.
- Version your wording. Prompts are shared team assets. Review changes in code review like any other change, because a small edit changes how every user's request is phrased.
- Do not hide actions in a prompt. A prompt should never trigger a side effect. Side effects belong in tools, which carry the confirmation practices covered in the security chapter.
Summary
Prompts are user-initiated templates that return messages. The client discovers them with prompts/list and fetches them with prompts/get. In FastMCP, @mcp.prompt() turns a function into a prompt, its parameters become string arguments, and its return value becomes one or more messages. Use tools for model-driven actions, resources for read-only context, and prompts for repeatable requests that people start themselves.
Exercise
Your team keeps pasting the same text into chat before every code review: "Review this change for security problems, list findings by severity, and do not suggest style changes." Write a FastMCP prompt named security_review that takes a required focus argument (for example "authentication") and an optional language argument defaulting to "Python". It should return a single user message. Then explain why this belongs in a prompt and not a tool.
Show answer
Code:
@mcp.prompt(name="securityreview", description="Start a security-focused code review.")
def securityreview(focus: str, language: str = "Python") -> str:
return (
f"Review the {language} change I will paste next for security problems, "
f"with a focus on {focus}. List findings by severity, highest first. "
"Do not suggest style changes."
)
It is a prompt because a person starts it, it only builds text, and it has no side effects or live data lookups. A tool is for actions the model chooses to take, such as querying a system. Here the user chooses the workflow, and the server only supplies consistent wording. Since arguments are strings, focus and language need no conversion.