-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathexample_server.py
More file actions
50 lines (35 loc) · 943 Bytes
/
Copy pathexample_server.py
File metadata and controls
50 lines (35 loc) · 943 Bytes
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
from datetime import datetime
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:
"""Adds two numbers.
Args:
a: The first number.
b: The second number.
Returns:
The sum of the two numbers.
"""
return a + b
# Add a tool to get the current time
@mcp.tool()
def get_current_time() -> str:
"""Gets the current time.
Returns:
The current time in 'YYYY-MM-DD HH:MM:SS' format.
"""
return datetime.now().strftime("%Y-%m-%d %H:%M:%S")
# Add a dynamic greeting resource
@mcp.resource("greeting://{name}")
def get_greeting(name: str) -> str:
"""Gets a personalised greeting.
Args:
name: The name to include in the greeting.
Returns:
A personalised greeting string.
"""
return f"Hello, {name}!"
if __name__ == "__main__":
mcp.run()