-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
48 lines (39 loc) · 1.38 KB
/
main.py
File metadata and controls
48 lines (39 loc) · 1.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
from fastmcp import FastMCP
from random import random
import os
import time
mcp = FastMCP("Demo 🚀")
@mcp.tool
def random_float() -> float:
"""Return a random float in [0,1)."""
return random()
@mcp.tool
def wait(ms: int) -> str:
"""Wait for the specified time in milliseconds and return a message."""
time.sleep(ms / 1000.0) # Convert milliseconds to seconds
return f"waited for {ms}ms"
@mcp.prompt
def summarize_request(text: str) -> str:
"""Generate a prompt asking for a summary."""
return f"Please summarize the following text:\n\n{text}"
# Static resource
@mcp.resource("config://version")
def get_version():
return "2.0.1"
# Dynamic resource template
@mcp.resource("users://{user_id}/profile")
def get_profile(user_id: int):
# Fetch profile for user_id...
return {"name": f"User {user_id}", "status": "active"}
if __name__ == "__main__":
transport = os.getenv("APP_TRANSPORT", "STDIO").upper()
host = os.getenv("APP_HOST", "0.0.0.0")
port = int(os.getenv("APP_PORT", "8000"))
if transport == "STDIO":
mcp.run(transport="stdio")
elif transport == "HTTP":
mcp.run(transport="http", host=host, port=port, path="/mcp")
elif transport == "SSE":
mcp.run(transport="sse", host=host, port=port, path="/sse")
else:
raise ValueError(f"Invalid TRANSPORT value: {transport}. Must be STDIO, HTTP, or SSE")