π The fast, Pythonic way to build MCP servers and clients.
remove empty parens from prompt
Jeremiah Lowind64077b03bab
diff --git a/README.md b/README.mdindex e9ce712ef..f8ce41cc0 100644--- a/README.md+++ b/README.md@@ -176,7 +176,7 @@ Learn more in the [**Resources & Templates Documentation**](https://gofastmcp.coPrompts define reusable message templates to guide LLM interactions. Decorate functions with `@mcp.prompt`. Return strings or `Message` objects.```pythondef summarize_request(text: str) -> str:"""Generate a prompt asking for a summary."""return f"Please summarize the following text:\n\n{text}"diff --git a/docs/patterns/decorating-methods.mdx b/docs/patterns/decorating-methods.mdxindex 3b2c22dd6..4e8ad8489 100644--- a/docs/patterns/decorating-methods.mdx+++ b/docs/patterns/decorating-methods.mdx@@ -5,7 +5,7 @@ description: Properly use instance methods, class methods, and static methods wiicon: at----FastMCP's decorator system is designed to work with functions, but you may see unexpected behavior if you try to decorate an instance or class method. This guide explains the correct approach for using methods with all FastMCP decorators (`@tool`, `@resource()`, and `@prompt()`).+FastMCP's decorator system is designed to work with functions, but you may see unexpected behavior if you try to decorate an instance or class method. This guide explains the correct approach for using methods with all FastMCP decorators (`@tool`, `@resource`, and `.prompt`).## Why Are Methods Hard?diff --git a/docs/servers/context.mdx b/docs/servers/context.mdxindex 2818de3c0..0f075d264 100644--- a/docs/servers/context.mdx+++ b/docs/servers/context.mdx@@ -71,7 +71,7 @@ async def get_user_profile(user_id: str, ctx: Context) -> dict:<VersionBadge version="2.2.5" />```pythonasync def data_analysis_request(dataset: str, ctx: Context) -> str:"""Generate a request to analyze data with contextual information."""# Context is available as the ctx parameterdiff --git a/docs/servers/fastmcp.mdx b/docs/servers/fastmcp.mdxindex 40808fb95..13279525d 100644--- a/docs/servers/fastmcp.mdx+++ b/docs/servers/fastmcp.mdx@@ -87,7 +87,7 @@ See [Resources & Templates](/servers/resources) for detailed documentation.Prompts are reusable message templates for guiding the LLM.```pythondef analyze_data(data_points: list[float]) -> str:"""Creates a prompt asking for analysis of numerical data."""formatted_data = ", ".join(str(point) for point in data_points)diff --git a/docs/servers/prompts.mdx b/docs/servers/prompts.mdxindex 6a8f0a62a..47f19ff9e 100644--- a/docs/servers/prompts.mdx+++ b/docs/servers/prompts.mdx@@ -33,13 +33,13 @@ from fastmcp.prompts.prompt import Message, PromptMessage, TextContentmcp = FastMCP(name="PromptServer")# Basic prompt returning a string (converted to user message automatically)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 typedef generate_code_request(language: str, task_description: str) -> PromptMessage:"""Generates a user message requesting code generation."""content = f"Write a {language} function that performs the following task: {task_description}"@@ -69,7 +69,7 @@ FastMCP intelligently handles different return types from your prompt function:```pythonfrom fastmcp.prompts.prompt import Messagedef roleplay_scenario(character: str, situation: str) -> list[Message]:"""Sets up a roleplaying scenario with initial messages."""return [@@ -89,7 +89,7 @@ Type annotations are important for prompts. They:from pydantic import Fieldfrom typing import Literal, Optionaldef generate_content_request(topic: str = Field(description="The main subject to cover"),format: Literal["blog", "email", "social"] = "blog",@@ -111,7 +111,7 @@ def generate_content_request(Parameters in your function signature are considered **required** unless they have a default value.```pythondef data_analysis_prompt(data_uri: str, # Required - no default valueanalysis_type: str = "summary", # Optional - has default value@@ -154,13 +154,13 @@ FastMCP seamlessly supports both standard (`def`) and asynchronous (`async def`)```python# Synchronous promptdef simple_question(question: str) -> str:"""Generates a simple question to ask the LLM."""return f"Question: {question}"# Asynchronous promptasync def data_based_prompt(data_id: str) -> str:"""Generates a prompt based on data that needs to be fetched."""# In a real scenario, you might fetch data from a database or API@@ -183,7 +183,7 @@ from fastmcp import FastMCP, Contextmcp = FastMCP(name="PromptServer")async def generate_report_request(report_type: str, ctx: Context) -> str:"""Generates a request for a report."""return f"Please create a {report_type} report. Request ID: {ctx.request_id}"@@ -207,7 +207,7 @@ mcp = FastMCP(on_duplicate_prompts="error" # Raise an error if a prompt name is duplicated)def greeting(): return "Hello, how can I help you today?"# This registration attempt will raise a ValueError becausediff --git a/tests/server/test_server_interactions.py b/tests/server/test_server_interactions.pyindex 921902819..9d6df95bc 100644--- a/tests/server/test_server_interactions.py+++ b/tests/server/test_server_interactions.py@@ -1086,7 +1086,7 @@ class TestPrompts:async def test_prompt_decorator_with_parens(self):mcp = FastMCP()- @mcp.prompt()+ @mcp.promptdef fn() -> str:return "Hello, world!"