fastmcp.prompts.prompt
Base classes for FastMCP prompts.
Functions
prompt
- Creating prompts that will be modified before registration
- Defining prompts in modules that are discovered by FileSystemProvider
- Creating reusable prompt definitions
- @prompt (without parentheses)
- @prompt() (with empty parentheses)
- @prompt(“custom_name”) (with name as first argument)
- @prompt(name=“custom_name”) (with name as keyword argument)
name_or_fn: Either a function (when used as @prompt), a string name, or Nonename: Optional name for the prompt (keyword-only, alternative to name_or_fn)title: Optional title for the promptdescription: Optional description of what the prompt doesicons: Optional icons for the prompttags: Optional set of tags for categorizing the promptmeta: Optional meta information about the prompttask: Optional task configuration for background execution (default False)
- A FunctionPrompt when decorating a function, or a decorator function when
- called with parameters.
Classes
Message
Wrapper for prompt message with auto-serialization.
Accepts any content - strings pass through, other types
(dict, list, BaseModel) are JSON-serialized to text.
Methods:
to_mcp_prompt_message
PromptArgument
An argument that can be passed to a prompt.
PromptResult
Canonical result type for prompt rendering.
Provides explicit control over prompt responses: multiple messages,
roles, and metadata at both the message and result level.
Methods:
to_mcp_prompt_result
Prompt
A prompt template that can be rendered with parameters.
Methods:
to_mcp_prompt
from_function
- str: wrapped as single user Message
- list[Message | str]: converted to list[Message]
- PromptResult: used directly
render
- str: Wrapped as single user Message
- list[Message | str]: Converted to list[Message]
- PromptResult: Used directly
convert_result
TypeError: for unsupported types
register_with_docket
add_to_docket
docket: The Docket instancearguments: Prompt argumentsfn_key: Function lookup key in Docket registry (defaults to self.key)task_key: Redis storage key for the result**kwargs: Additional kwargs passed to docket.add()
FunctionPrompt
A prompt that is a function.
Methods:
from_function
- str: wrapped as single user Message
- list[Message | str]: converted to list[Message]
- PromptResult: used directly
render
register_with_docket
add_to_docket
docket: The Docket instancearguments: Prompt argumentsfn_key: Function lookup key in Docket registry (defaults to self.key)task_key: Redis storage key for the result**kwargs: Additional kwargs passed to docket.add()

