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 FlashMCP needs to generate a complete parameter schema for the MCP protocol, which isn’t possible with variable argument lists.str
: 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.
@mcp.prompt
decorator:
name
: Sets the explicit prompt name exposed via MCP.description
: Provides the description exposed via MCP. If set, the function’s docstring is ignored for this purpose.tags
: A set of strings used to categorize the prompt. Clients might use tags to filter or group available prompts.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.1.0
You can configure how the FlashMCP server handles attempts to register multiple prompts with the same name. Use the on_duplicate_prompts
setting during FlashMCP
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.