Skip to main content

fastmcp.prompts.prompt

Base classes for FastMCP prompts.

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

Convert to MCP PromptMessage.

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

Convert to MCP GetPromptResult.

Prompt

A prompt template that can be rendered with parameters. Methods:

to_mcp_prompt

Convert the prompt to an MCP prompt.

from_function

Create a Prompt from a function. The function can return:
  • str: wrapped as single user Message
  • list[Message | str]: converted to list[Message]
  • PromptResult: used directly

render

Render the prompt with arguments. Subclasses must implement this method. Return one of:
  • str: Wrapped as single user Message
  • list[Message | str]: Converted to list[Message]
  • PromptResult: Used directly

convert_result

Convert a raw return value to PromptResult. Raises:
  • TypeError: for unsupported types

register_with_docket

Register this prompt with docket for background execution.

add_to_docket

Schedule this prompt for background execution via docket. Args:
  • docket: The Docket instance
  • arguments: Prompt arguments
  • fn_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()

get_span_attributes