-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmcp_server.py
More file actions
32 lines (27 loc) · 899 Bytes
/
Copy pathmcp_server.py
File metadata and controls
32 lines (27 loc) · 899 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
from mcp.server.fastmcp import FastMCP
mcp = FastMCP("roymcpdemo")
@mcp.tool()
# Trace AI解释代码 | 注释代码 | 生成单测 |
def add(a: int, b: int) -> int:
"""Add two numbers together."""
print(f"roy mcp demo called : add({a}, {b})")
return a + b
@mcp.tool()
# Trace AI解释代码 | 注释代码 | 生成单测 |
def weather(city: str) -> str:
"""获取某个城市的天气
Args:
city: 具体城市
"""
return "城市" + city + ",今天天气不错"
@mcp.resource("greeting://{name}")
# Trace AI解释代码 | 注释代码 | 生成单测 |
def greeting(name: str) -> str:
"""Greet a person by name."""
print(f"roy mcp demo called : greeting({name})")
return f"Hello, {name}!"
if __name__ == "__main__":
# 以sse协议暴露服务。
mcp.run(transport='sse')
# 以stdio协议暴露服务。
# mcp.run(transport='stdio')