chore: import upstream snapshot with attribution
Deploy Docs / deploy-docs (push) Failing after 1s
Conformance Tests / client-conformance (push) Failing after 3s
Conformance Tests / server-conformance (push) Failing after 1s
GitHub Actions Security Analysis / zizmor (push) Failing after 1s
CI / checks (push) Failing after 59m20s
CI / all-green (push) Waiting to run
Deploy Docs / deploy-docs (push) Failing after 1s
Conformance Tests / client-conformance (push) Failing after 3s
Conformance Tests / server-conformance (push) Failing after 1s
GitHub Actions Security Analysis / zizmor (push) Failing after 1s
CI / checks (push) Failing after 59m20s
CI / all-green (push) Waiting to run
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
"""MCPServer quickstart example.
|
||||
|
||||
Run from the repository root:
|
||||
uv run examples/snippets/servers/mcpserver_quickstart.py
|
||||
"""
|
||||
|
||||
from mcp.server.mcpserver import MCPServer
|
||||
|
||||
# Create an MCP server
|
||||
mcp = MCPServer("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}."
|
||||
|
||||
|
||||
# Run with streamable HTTP transport
|
||||
if __name__ == "__main__":
|
||||
mcp.run(transport="streamable-http", json_response=True)
|
||||
Reference in New Issue
Block a user