Prompts: Templates the User Picks

Some requests to an AI assistant come up again and again: review this code, summarise these notes, draft a reply to this email. An MCP server can offer such requests ready-made, as prompts: templates with a name and a few blanks that a person picks in the AI application when they want them. Knowing how prompts work, and when a feature should be a prompt rather than a tool or a resource, lets a server give its users the right kind of control.

A template the user starts

A server already offers two kinds of capability that you may know: tools, which the model decides to call, and resources, which the application reads and attaches as context. A prompt is the third kind. It is a reusable message template stored on the server, and the one who decides to use it is the user.

The host (the AI application, such as a chat app or a coding agent) asks the server which prompts exist and shows them to the user by name. How it shows them is up to the host: the specification gives slash commands as a typical example, and a command palette, a button or a menu entry work just as well. In a coding agent the user might type /, see review_code in the list, choose it and fill in the code to review.

Two protocol requests carry the whole feature. prompts/list returns the prompt definitions, each with its name, description and the arguments it accepts. prompts/get asks for one prompt by name, with values for its arguments, and the server answers with finished messages. The host adds those messages to the conversation, and only then does the model see them.

  • User
  • Host and client
  • MCP server
  • Model
  • Host and client to MCP server: prompts/list
  • MCP server to Host and client: names, arguments
  • User to Host and client: picks review_code
  • Host and client to MCP server: prompts/get, arguments
  • MCP server to Host and client: messages
  • Host and client to Model: messages in the chat

Notice what the server does not do: it never talks to the model. Getting a prompt is ordinary deterministic code that fills a template and returns text.

Saying that the user controls a prompt means the user decides when it is used. It does not mean the user writes it. The wording comes from the server, and the user only chooses the prompt and supplies its argument values.

True or false?

The model can decide on its own to use a prompt in the middle of a conversation, the same way it calls a tool.

False. Prompts need an explicit choice by the user, for example a slash command or a menu entry. Deciding on its own is what the model does with tools.

When a prompt is used, the server returns messages and does not call a model itself.

True. The answer to prompts/get is only a list of messages. The host adds them to the conversation, and the model reads them there.

Defining a prompt in Python

In the 2.x line of the official mcp Python SDK, a server is an MCPServer object (older tutorials and the 1.x line call it FastMCP, which is also the name of a separate framework).

You turn an ordinary function into a prompt with the @mcp.prompt() decorator, the same way @mcp.tool() turns a function into a tool. The parentheses are required: writing @mcp.prompt without them raises a TypeError.

A prompt with one required and one optional argument
from typing import Annotated

from pydantic import Field

from mcp.server import MCPServer

mcp = MCPServer("Code Helper")


@mcp.prompt(title="Code review")
def review_code(
    code: Annotated[str, Field(description="The code to review.")],
    language: Annotated[str, Field(description="The language the code is written in.")] = "python",
) -> str:
    """Review a piece of code."""
    return f"Please review this {language} code:\n\n{code}"

The SDK reads the definition from the function, just as it does for tools. The name is the function name, review_code. The description is the docstring. The optional title is a friendlier label a host may display. Each parameter becomes an argument, and Field(description=...) adds a short explanation of what to put in it. When a client lists the prompts, this is what it receives for this one:

The prompt as prompts/list describes it
{
  "name": "review_code",
  "title": "Code review",
  "description": "Review a piece of code.",
  "arguments": [
    {"name": "code", "description": "The code to review.", "required": true},
    {"name": "language", "description": "The language the code is written in.", "required": false}
  ]
}

The function itself is plain synchronous Python. It runs only when someone gets the prompt: it receives the argument values and returns the text of the request.

Arguments are named strings

The arguments of a prompt are simpler than the parameters of a tool. A tool has an input schema in JSON Schema, with types such as integers and booleans. A prompt has no schema at all: its arguments are a flat list of named text values. Every value travels as a string, so the type hint of a prompt parameter is str, and the description is the place to say what format you expect, such as "a date like 2026-03-01".

Each argument is either required or optional, and the SDK decides which from the function. A parameter with no default value is required: code above has none, so the listing marks it "required": true. A parameter with a default, such as language = "python", is optional, and the default fills in when the user leaves it out.

AspectTool parametersPrompt arguments
Described bya JSON Schemaa list of names with descriptions
Value typesstrings, numbers, booleans, lists and morealways strings
Required whenthe parameter has no defaultthe parameter has no default
A required value is missingan error result the model can readthe whole request fails

The last row matters in practice. The SDK checks required arguments before your function runs. Suppose a client asks for review_code without code. A failed tool call would come back as a result marked as an error, but here the server returns no result at all. It rejects the request with a JSON-RPC error, and the client raises an exception instead of receiving messages. The specification recommends the code -32602 (Invalid params) for this, but the Python SDK (2.3.0) currently answers with -32603 (Internal error), so a test should not count on the specification's code. An unknown prompt name fails the same way.

The difference has a reason. A tool error result is designed for a model that can read it and retry; with a prompt there is no model in the loop yet, only a host that can show the user what is missing.

True or false?

A prompt parameter annotated with a default value becomes an optional argument.

True. The SDK marks a parameter required only when it has no default. With a default, the listing shows required false and the default fills in.

Like a tool, a prompt describes its arguments with a JSON Schema, so an argument can be declared as an integer.

False. Prompt arguments have no schema and no types. Every value is sent as a string, and the description says which format is expected.

Getting a prompt without one of its required arguments returns messages that explain the problem.

False. The request fails with a JSON-RPC error. The client receives an error instead of a result, and no messages come back.

What a prompt returns: messages

Getting a prompt returns a list of messages. Each message has a role, either user or assistant, and a content block. Text is by far the most common content, and a message may also carry an image, audio, a link to a resource or a resource embedded in full. The host adds these messages to the conversation. A user message stands in for what the user would otherwise have typed; an assistant message appears as if the assistant had already said it.

A function that returns a plain str produces exactly one user message with that text. Here is what a client receives when it gets review_code with code set to print("hi") and no language:

The result of prompts/get
{
  "description": "Review a piece of code.",
  "messages": [
    {
      "role": "user",
      "content": {"type": "text", "text": "Please review this python code:\n\nprint(\"hi\")"}
    }
  ],
  "resultType": "complete"
}

To start a conversation that already has a few turns, return a list of messages. The SDK has one class for each role, UserMessage and AssistantMessage. You create a message by calling the class with a string, and it wraps the string in a text content block for you. Both are kinds of the more general class Message, so list[Message] is the return type hint for a list that mixes them.

A prompt that returns three messages
from mcp.server.mcpserver.prompts.base import AssistantMessage, Message, UserMessage


@mcp.prompt()
def debug_error(error: str) -> list[Message]:
    """Start a debugging conversation."""
    return [
        UserMessage("I'm seeing this error:"),
        UserMessage(error),
        AssistantMessage("I'll help debug that. What have you tried so far?"),
    ]

Because the server answers with fixed text for fixed arguments, a prompt is tested like any other server code, with no model involved: a client connects, gets the prompt with chosen arguments and reads the messages. With the SDK's Client, get_prompt takes the name and a dictionary of strings, and a JSON-RPC error such as a missing argument arrives as an MCPError exception.

Rendering a prompt from a client
from mcp import Client, MCPError


async def show_prompts():
    async with Client(mcp, raise_exceptions=True) as client:
        result = await client.get_prompt("review_code", {"code": 'print("hi")'})
        for message in result.messages:
            print(message.role, message.content.text)

        try:
            await client.get_prompt("review_code", {})
        except MCPError as error:
            print(error)  # Missing required arguments: {'code'}

With raise_exceptions=True, as in the course's tests, the error carries the server's own message: Missing required arguments: {'code'} here, or Unknown prompt: ... for a name the server does not have. Without it, as with a real host, the server hides the details and the message is only Internal server error.

True or false?

Every message a prompt returns has the role user.

False. A message has the role user or assistant. A plain string return gives one user message, and AssistantMessage adds an assistant turn.

Getting the same prompt twice with the same arguments returns the same messages.

True. Rendering a prompt is ordinary code that fills a template, so fixed arguments give fixed messages. That is what makes prompts easy to test.

Tool, resource or prompt: who decides

The three capabilities can look alike, since all of them end with something in front of the model. The useful question is not what the feature contains but who should decide that it is used. If the model should decide in the middle of a task, it is a tool. If the application, or the user through the application, should choose data to put into the context, it is a resource. If the user should start a whole request on purpose, it is a prompt.

CapabilityWho decidesWhat it isExample
Toolthe modelan action, a function the model calls with argumentsbook a meeting, search flights
Resourcethe applicationread-only data loaded into the contexta file, a record, a schedule
Promptthe usera message template the user picks by namereview this code, plan a vacation

Take a server for a calendar. Booking a meeting is a change the model should make when the conversation calls for it, so it is a tool. This week's schedule is data the application can attach so the model knows what is already planned, so it is a resource. "Plan my week around my meetings" is a request that a person starts on a Monday morning and wants to phrase the same way every time, so it is a prompt. The prompt does not do the work itself: its message asks the model, and the model can then read the resource and call the tools.

Two signs point to the wrong choice. The first is an instruction written into a tool description in the hope that the model uses it at the right moment: it usually belongs in a prompt, because the user knows when they want it. The second is a tool whose only job is to return fixed text the user asked for, which is also usually a prompt.

One more point follows from how prompts work. Since the wording of a prompt reaches the model as part of the conversation, any argument a user types into it is input like any other: the specification asks servers to validate prompt inputs and outputs carefully.

True or false?

A monthly report that a user asks for with the same wording each time is a good fit for a prompt.

True. The user decides when to start it and the server supplies the wording, which is what a prompt is for.

Deleting a record when the conversation calls for it fits a prompt, since the user started the conversation.

False. An action the model takes during the conversation, with arguments it chooses, is a tool. Starting the conversation does not make each later action the user's choice.

A prompt can ask the model to use tools and resources of the same server.

True. A prompt is only messages, so its text can ask the model to read data and take actions. The model then calls the tools and reads the resources as usual.