-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathserver.py
More file actions
62 lines (47 loc) · 1.39 KB
/
server.py
File metadata and controls
62 lines (47 loc) · 1.39 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import uuid
from fastmcp import FastMCP
# Initialize MCP server
mcp = FastMCP("Simple Tools Server")
@mcp.tool()
def generate_uuid(version: int = 4) -> str:
"""
Generate a random UUID.
Args:
version: UUID version (default 4)
Returns:
String containing the generated UUID
"""
return str(uuid.uuid4()) if version == 4 else str(uuid.uuid1())
@mcp.tool()
def convert_temperature(value: float, from_unit: str = "C", to_unit: str = "F") -> float:
"""
Convert temperature between Celsius and Fahrenheit.
Args:
value: Temperature value to convert
from_unit: Source unit ('C' or 'F')
to_unit: Target unit ('C' or 'F')
Returns:
Converted temperature value
"""
if from_unit == "C" and to_unit == "F":
return (value * 9/5) + 32
elif from_unit == "F" and to_unit == "C":
return (value - 32) * 5/9
return value
@mcp.tool()
def text_statistics(text: str) -> dict:
"""
Calculate basic text statistics.
Args:
text: Text to analyze
Returns:
Dictionary with statistics (character count, word count, line count)
"""
return {
"characters": len(text),
"words": len(text.split()),
"lines": len(text.splitlines())
}
if __name__ == "__main__":
# Run with Streamable HTTP transport (recommended for production)
mcp.run(transport="http")