@mcp.prompt decorator.
What Are Prompts?
Prompts provide parameterized message templates for LLMs. When a client requests a prompt:- FastMCP finds the corresponding prompt definition.
- If it has parameters, they are validated against your function signature.
- Your function executes with the validated inputs.
- The generated message(s) are returned to the LLM to guide its response.
Prompts
The @prompt Decorator
The most common way to define a prompt is by decorating a Python function. The decorator uses the function name as the prompt’s identifier.
- Name: By default, the prompt name is taken from the function name.
- Parameters: The function parameters define the inputs needed to generate the prompt.
- Inferred Metadata: By default:
- Prompt Name: Taken from the function name (
ask_about_topic). - Prompt Description: Taken from the function’s docstring.
- Prompt Name: Taken from the function name (
Decorator Arguments
While FastMCP infers the name and description from your function, you can override these and add additional metadata using arguments to the@mcp.prompt decorator:
@prompt Decorator Arguments
Sets the explicit prompt name exposed via MCP. If not provided, uses the function name
A human-readable title for the prompt
Provides the description exposed via MCP. If set, the function’s docstring is ignored for this purpose
A set of strings used to categorize the prompt. These can be used by the server and, in some cases, by clients to filter or group available prompts.
A boolean to enable or disable the prompt. See Disabling Prompts for more information
New in version
2.13.0Optional list of icon representations for this prompt. See Icons for detailed examplesNew in version
2.11.0Optional meta information about the prompt. This data is passed through to the MCP client as the _meta field of the client-side prompt object and can be used for custom metadata, versioning, or other application-specific purposes.Argument Types
New in version2.9.0
The MCP specification requires that all prompt arguments be passed as strings, but FastMCP allows you to use typed annotations for better developer experience. When you use complex types like list[int] or dict[str, str], FastMCP:
- Automatically converts string arguments from MCP clients to the expected types
- Generates helpful descriptions showing the exact JSON string format needed
- Preserves direct usage - you can still call prompts with properly typed arguments
Return Values
FastMCP intelligently handles different return types from your prompt function:str: Automatically converted to a singlePromptMessage.PromptMessage: Used directly as provided. (Note a more user-friendlyMessageconstructor is available that can accept raw strings instead ofTextContentobjects.)list[PromptMessage | str]: Used as a sequence of messages (a conversation).PromptResult: Full control over messages, description, and metadata. See PromptResult below.Any: If the return type is not one of the above, the return value is attempted to be converted to a string and used as aPromptMessage.
PromptResult
New in version2.14.1
For complete control over prompt responses, return a PromptResult object. This lets you include metadata alongside your prompt messages, which is useful for passing runtime information to clients.
PromptResult accepts three fields:
messages - A list of PromptMessage or Message objects representing the conversation to send to the LLM.
description - Optional description of the prompt result. If not provided, defaults to the prompt’s docstring.
meta - Optional metadata dictionary that will be included in the MCP response’s _meta field. Use this for runtime metadata like categorization, priority, or other client-specific data.
The
meta field in PromptResult is for runtime metadata specific to this render response. This is separate from the meta parameter in @mcp.prompt(meta={...}), which provides static metadata about the prompt definition itself (returned when listing prompts).str, PromptMessage, or lists from your prompt functions—PromptResult is opt-in for when you need to include metadata.
Required vs. Optional Parameters
Parameters in your function signature are considered required unless they have a default value.data_uri. If analysis_type or include_charts are omitted, their default values will be used.
Disabling Prompts
New in version2.8.0
You can control the visibility and availability of prompts by enabling or disabling them. Disabled prompts will not appear in the list of available prompts, and attempting to call a disabled prompt will result in an “Unknown prompt” error.
By default, all prompts are enabled. You can disable a prompt upon creation using the enabled parameter in the decorator:
Async Prompts
FastMCP seamlessly supports both standard (def) and asynchronous (async def) functions as prompts.
async def when your prompt function performs I/O operations like network requests, database queries, file I/O, or external service calls.
Accessing MCP Context
New in version2.2.5
Prompts can access additional MCP information and features through the Context object. To access it, add a parameter to your prompt function with a type annotation of Context:
Notifications
New in version2.9.1
FastMCP automatically sends notifications/prompts/list_changed notifications to connected clients when prompts are added, enabled, or disabled. This allows clients to stay up-to-date with the current prompt set without manually polling for changes.
Server Behavior
Duplicate Prompts
New in version2.1.0
You can configure how the FastMCP server handles attempts to register multiple prompts with the same name. Use the on_duplicate_prompts setting during FastMCP initialization.
"warn"(default): Logs a warning, and the new prompt replaces the old one."error": Raises aValueError, preventing the duplicate registration."replace": Silently replaces the existing prompt with the new one."ignore": Keeps the original prompt and ignores the new registration attempt.

