Skip to content

Commit 0ab40af

Browse files
committed
update: Added a system prompt class for returning system messages; now users can directly import and use it and fix ruff format
1 parent 3e45b67 commit 0ab40af

File tree

1 file changed

+9
-11
lines changed

1 file changed

+9
-11
lines changed

examples/servers/system_prompt.py

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,26 @@
1-
from mcp.server import FastMCP
2-
3-
# from dotenv import load_dotenv
4-
import os
51
from mcp.server.fastmcp import FastMCP
62
from mcp.server.fastmcp.prompts import base as mcp_messages
73

8-
mcp = FastMCP("weather") # No reason to initialize stateless
9-
10-
4+
mcp = FastMCP("weather")
115

126

137
@mcp.prompt()
148
def weather_system_prompt() -> mcp_messages.SystemMessage:
159
"""
16-
Creates a prompt asking an AI to weather
10+
Creates a prompt asking an AI to weather
1711
Args:
1812
None: None
1913
"""
20-
21-
return mcp_messages.SystemMessage("""You are a helpful weather agent. Your job is to answer weather-related questions clearly and simply. If the user asks for the weather in a city, you tell the current weather, temperature, and a short description like "sunny," "cloudy," or "rainy." If you don’t know the answer, say "Sorry, I don’t have that information.""")
14+
15+
return mcp_messages.SystemMessage(
16+
"You are a helpful agent. You answer questions clearly and simply. "
17+
"If you don’t know something, say you don’t have that information."
18+
)
2219

2320

2421
mcp_app = mcp.streamable_http_app()
2522

2623
if __name__ == "__main__":
2724
import uvicorn
28-
uvicorn.run("system_prompt:mcp_app", host="0.0.0.0", port=8002, reload=True)
25+
26+
uvicorn.run("system_prompt:mcp_app", host="0.0.0.0", port=8002, reload=True)

0 commit comments

Comments
 (0)