From 70fac26f9fa1ab896e6df16b53e816f3ab08ce50 Mon Sep 17 00:00:00 2001 From: Jeremiah Lowin <153965+jlowin@users.noreply.github.com> Date: Thu, 25 Dec 2025 22:34:11 -0500 Subject: [PATCH] Fix prompt return type documentation (#2741) --- docs/servers/prompts.mdx | 11 +++++++---- src/fastmcp/prompts/prompt.py | 14 ++++++-------- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/docs/servers/prompts.mdx b/docs/servers/prompts.mdx index 03f071d37..967237125 100644 --- a/docs/servers/prompts.mdx +++ b/docs/servers/prompts.mdx @@ -38,11 +38,14 @@ def ask_about_topic(topic: str) -> str: """Generates a user message asking for an explanation of a topic.""" return f"Can you please explain the concept of '{topic}'?" -# Prompt returning a specific message type +# Prompt returning multiple messages @mcp.prompt -def generate_code_request(language: str, task_description: str) -> Message: - """Generates a user message requesting code generation.""" - return Message(f"Write a {language} function that performs the following task: {task_description}") +def generate_code_request(language: str, task_description: str) -> list[Message]: + """Generates a conversation for code generation.""" + return [ + Message(f"Write a {language} function that performs the following task: {task_description}"), + Message("I'll help you write that function.", role="assistant"), + ] ``` **Key Concepts:** diff --git a/src/fastmcp/prompts/prompt.py b/src/fastmcp/prompts/prompt.py index 0259e36a9..146828243 100644 --- a/src/fastmcp/prompts/prompt.py +++ b/src/fastmcp/prompts/prompt.py @@ -242,10 +242,9 @@ class Prompt(FastMCPComponent): """Create a Prompt from a function. The function can return: - - A string (converted to a message) - - A Message object - - A dict (converted to a message) - - A sequence of any of the above + - str: wrapped as single user Message + - list[Message | str]: converted to list[Message] + - PromptResult: used directly """ return FunctionPrompt.from_function( fn=fn, @@ -385,10 +384,9 @@ class FunctionPrompt(Prompt): """Create a Prompt from a function. The function can return: - - A string (converted to a message) - - A Message object - - A dict (converted to a message) - - A sequence of any of the above + - str: wrapped as single user Message + - list[Message | str]: converted to list[Message] + - PromptResult: used directly """ func_name = name or getattr(fn, "__name__", None) or fn.__class__.__name__