Skip to main content

fastmcp.prompts.function_prompt

Standalone @prompt decorator for FastMCP.

Functions

prompt

Standalone decorator to mark a function as an MCP prompt. Returns the original function with metadata attached. Register with a server using mcp.add_prompt().

Classes

DecoratedPrompt

Protocol for functions decorated with @prompt.

PromptMeta

Metadata attached to functions by the @prompt decorator.

FunctionPrompt

A prompt that is a function. Methods:

from_function

Create a Prompt from a function. Args:
  • fn: The function to wrap
  • metadata: PromptMeta object with all configuration. If provided, individual parameters must not be passed.
  • name, title, etc.: Individual parameters for backwards compatibility. Cannot be used together with metadata parameter.
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.