Create reusable, parameterized prompt templates for MCP clients.
@mcp.prompt
decorator.
@prompt
Decoratorask_about_topic
).*args
or **kwargs
are not supported as prompts. This restriction exists because FastMCP needs to generate a complete parameter schema for the MCP protocol, which isn’t possible with variable argument lists.@mcp.prompt
decorator:
New in version: 2.11.0
Optional 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.New in version: 2.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:
list[int]
, dict[str, str]
, float
, bool
Avoid: Complex Pydantic models, deeply nested structures, custom classesstr
: Automatically converted to a single PromptMessage
.PromptMessage
: Used directly as provided. (Note a more user-friendly Message
constructor is available that can accept raw strings instead of TextContent
objects.)list[PromptMessage | str]
: Used as a sequence of messages (a conversation).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 a PromptMessage
.data_uri
. If analysis_type
or include_charts
are omitted, their default values will be used.
New in version: 2.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:
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.
New in version: 2.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
:
New in version: 2.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.
New in version: 2.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 a ValueError
, 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.