Jeremiah Lowin commited on
Commit
26b329e
·
1 Parent(s): 21b0f29

remove empty parens from prompt

Browse files
README.md CHANGED
@@ -176,7 +176,7 @@ Learn more in the [**Resources & Templates Documentation**](https://gofastmcp.co
176
  Prompts define reusable message templates to guide LLM interactions. Decorate functions with `@mcp.prompt`. Return strings or `Message` objects.
177
 
178
  ```python
179
- @mcp.prompt()
180
  def summarize_request(text: str) -> str:
181
  """Generate a prompt asking for a summary."""
182
  return f"Please summarize the following text:\n\n{text}"
 
176
  Prompts define reusable message templates to guide LLM interactions. Decorate functions with `@mcp.prompt`. Return strings or `Message` objects.
177
 
178
  ```python
179
+ @mcp.prompt
180
  def summarize_request(text: str) -> str:
181
  """Generate a prompt asking for a summary."""
182
  return f"Please summarize the following text:\n\n{text}"
docs/patterns/decorating-methods.mdx CHANGED
@@ -5,7 +5,7 @@ description: Properly use instance methods, class methods, and static methods wi
5
  icon: at
6
  ---
7
 
8
- 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()`).
9
 
10
  ## Why Are Methods Hard?
11
 
 
5
  icon: at
6
  ---
7
 
8
+ 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`).
9
 
10
  ## Why Are Methods Hard?
11
 
docs/servers/context.mdx CHANGED
@@ -71,7 +71,7 @@ async def get_user_profile(user_id: str, ctx: Context) -> dict:
71
  <VersionBadge version="2.2.5" />
72
 
73
  ```python
74
- @mcp.prompt()
75
  async def data_analysis_request(dataset: str, ctx: Context) -> str:
76
  """Generate a request to analyze data with contextual information."""
77
  # Context is available as the ctx parameter
 
71
  <VersionBadge version="2.2.5" />
72
 
73
  ```python
74
+ @mcp.prompt
75
  async def data_analysis_request(dataset: str, ctx: Context) -> str:
76
  """Generate a request to analyze data with contextual information."""
77
  # Context is available as the ctx parameter
docs/servers/fastmcp.mdx CHANGED
@@ -87,7 +87,7 @@ See [Resources & Templates](/servers/resources) for detailed documentation.
87
  Prompts are reusable message templates for guiding the LLM.
88
 
89
  ```python
90
- @mcp.prompt()
91
  def analyze_data(data_points: list[float]) -> str:
92
  """Creates a prompt asking for analysis of numerical data."""
93
  formatted_data = ", ".join(str(point) for point in data_points)
 
87
  Prompts are reusable message templates for guiding the LLM.
88
 
89
  ```python
90
+ @mcp.prompt
91
  def analyze_data(data_points: list[float]) -> str:
92
  """Creates a prompt asking for analysis of numerical data."""
93
  formatted_data = ", ".join(str(point) for point in data_points)
docs/servers/prompts.mdx CHANGED
@@ -33,13 +33,13 @@ from fastmcp.prompts.prompt import Message, PromptMessage, TextContent
33
  mcp = FastMCP(name="PromptServer")
34
 
35
  # Basic prompt returning a string (converted to user message automatically)
36
- @mcp.prompt()
37
  def ask_about_topic(topic: str) -> str:
38
  """Generates a user message asking for an explanation of a topic."""
39
  return f"Can you please explain the concept of '{topic}'?"
40
 
41
  # Prompt returning a specific message type
42
- @mcp.prompt()
43
  def generate_code_request(language: str, task_description: str) -> PromptMessage:
44
  """Generates a user message requesting code generation."""
45
  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:
69
  ```python
70
  from fastmcp.prompts.prompt import Message
71
 
72
- @mcp.prompt()
73
  def roleplay_scenario(character: str, situation: str) -> list[Message]:
74
  """Sets up a roleplaying scenario with initial messages."""
75
  return [
@@ -89,7 +89,7 @@ Type annotations are important for prompts. They:
89
  from pydantic import Field
90
  from typing import Literal, Optional
91
 
92
- @mcp.prompt()
93
  def generate_content_request(
94
  topic: str = Field(description="The main subject to cover"),
95
  format: Literal["blog", "email", "social"] = "blog",
@@ -111,7 +111,7 @@ def generate_content_request(
111
  Parameters in your function signature are considered **required** unless they have a default value.
112
 
113
  ```python
114
- @mcp.prompt()
115
  def data_analysis_prompt(
116
  data_uri: str, # Required - no default value
117
  analysis_type: str = "summary", # Optional - has default value
@@ -154,13 +154,13 @@ FastMCP seamlessly supports both standard (`def`) and asynchronous (`async def`)
154
 
155
  ```python
156
  # Synchronous prompt
157
- @mcp.prompt()
158
  def simple_question(question: str) -> str:
159
  """Generates a simple question to ask the LLM."""
160
  return f"Question: {question}"
161
 
162
  # Asynchronous prompt
163
- @mcp.prompt()
164
  async def data_based_prompt(data_id: str) -> str:
165
  """Generates a prompt based on data that needs to be fetched."""
166
  # In a real scenario, you might fetch data from a database or API
@@ -183,7 +183,7 @@ from fastmcp import FastMCP, Context
183
 
184
  mcp = FastMCP(name="PromptServer")
185
 
186
- @mcp.prompt()
187
  async def generate_report_request(report_type: str, ctx: Context) -> str:
188
  """Generates a request for a report."""
189
  return f"Please create a {report_type} report. Request ID: {ctx.request_id}"
@@ -207,7 +207,7 @@ mcp = FastMCP(
207
  on_duplicate_prompts="error" # Raise an error if a prompt name is duplicated
208
  )
209
 
210
- @mcp.prompt()
211
  def greeting(): return "Hello, how can I help you today?"
212
 
213
  # This registration attempt will raise a ValueError because
 
33
  mcp = FastMCP(name="PromptServer")
34
 
35
  # Basic prompt returning a string (converted to user message automatically)
36
+ @mcp.prompt
37
  def ask_about_topic(topic: str) -> str:
38
  """Generates a user message asking for an explanation of a topic."""
39
  return f"Can you please explain the concept of '{topic}'?"
40
 
41
  # Prompt returning a specific message type
42
+ @mcp.prompt
43
  def generate_code_request(language: str, task_description: str) -> PromptMessage:
44
  """Generates a user message requesting code generation."""
45
  content = f"Write a {language} function that performs the following task: {task_description}"
 
69
  ```python
70
  from fastmcp.prompts.prompt import Message
71
 
72
+ @mcp.prompt
73
  def roleplay_scenario(character: str, situation: str) -> list[Message]:
74
  """Sets up a roleplaying scenario with initial messages."""
75
  return [
 
89
  from pydantic import Field
90
  from typing import Literal, Optional
91
 
92
+ @mcp.prompt
93
  def generate_content_request(
94
  topic: str = Field(description="The main subject to cover"),
95
  format: Literal["blog", "email", "social"] = "blog",
 
111
  Parameters in your function signature are considered **required** unless they have a default value.
112
 
113
  ```python
114
+ @mcp.prompt
115
  def data_analysis_prompt(
116
  data_uri: str, # Required - no default value
117
  analysis_type: str = "summary", # Optional - has default value
 
154
 
155
  ```python
156
  # Synchronous prompt
157
+ @mcp.prompt
158
  def simple_question(question: str) -> str:
159
  """Generates a simple question to ask the LLM."""
160
  return f"Question: {question}"
161
 
162
  # Asynchronous prompt
163
+ @mcp.prompt
164
  async def data_based_prompt(data_id: str) -> str:
165
  """Generates a prompt based on data that needs to be fetched."""
166
  # In a real scenario, you might fetch data from a database or API
 
183
 
184
  mcp = FastMCP(name="PromptServer")
185
 
186
+ @mcp.prompt
187
  async def generate_report_request(report_type: str, ctx: Context) -> str:
188
  """Generates a request for a report."""
189
  return f"Please create a {report_type} report. Request ID: {ctx.request_id}"
 
207
  on_duplicate_prompts="error" # Raise an error if a prompt name is duplicated
208
  )
209
 
210
+ @mcp.prompt
211
  def greeting(): return "Hello, how can I help you today?"
212
 
213
  # This registration attempt will raise a ValueError because
tests/server/test_server_interactions.py CHANGED
@@ -1086,7 +1086,7 @@ class TestPrompts:
1086
  async def test_prompt_decorator_with_parens(self):
1087
  mcp = FastMCP()
1088
 
1089
- @mcp.prompt()
1090
  def fn() -> str:
1091
  return "Hello, world!"
1092
 
 
1086
  async def test_prompt_decorator_with_parens(self):
1087
  mcp = FastMCP()
1088
 
1089
+ @mcp.prompt
1090
  def fn() -> str:
1091
  return "Hello, world!"
1092