Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions docs/servers/prompts.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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:**
Expand Down
14 changes: 6 additions & 8 deletions src/fastmcp/prompts/prompt.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,10 +242,9 @@ def from_function(
"""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,
Expand Down Expand Up @@ -385,10 +384,9 @@ def from_function(
"""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__
Expand Down
Loading