README - replace code snippets with examples (#1136)
This commit is contained in:
parent
49991fd2c7
commit
9bf5160eea
1 changed files with 585 additions and 169 deletions
38
examples/snippets/servers/fastmcp_quickstart.py
Normal file
38
examples/snippets/servers/fastmcp_quickstart.py
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
"""
|
||||
FastMCP quickstart example.
|
||||
|
||||
cd to the `examples/snippets/clients` directory and run:
|
||||
uv run server fastmcp_quickstart stdio
|
||||
"""
|
||||
|
||||
from mcp.server.fastmcp import FastMCP
|
||||
|
||||
# Create an MCP server
|
||||
mcp = FastMCP("Demo")
|
||||
|
||||
|
||||
# Add an addition tool
|
||||
@mcp.tool()
|
||||
def add(a: int, b: int) -> int:
|
||||
"""Add two numbers"""
|
||||
return a + b
|
||||
|
||||
|
||||
# Add a dynamic greeting resource
|
||||
@mcp.resource("greeting://{name}")
|
||||
def get_greeting(name: str) -> str:
|
||||
"""Get a personalized greeting"""
|
||||
return f"Hello, {name}!"
|
||||
|
||||
|
||||
# Add a prompt
|
||||
@mcp.prompt()
|
||||
def greet_user(name: str, style: str = "friendly") -> str:
|
||||
"""Generate a greeting prompt"""
|
||||
styles = {
|
||||
"friendly": "Please write a warm, friendly greeting",
|
||||
"formal": "Please write a formal, professional greeting",
|
||||
"casual": "Please write a casual, relaxed greeting",
|
||||
}
|
||||
|
||||
return f"{styles.get(style, styles['friendly'])} for someone named {name}."
|
||||
Loading…
Reference in a new issue