refactor: 统一类型注解风格并优化代码结构
- 将裸 except 改为显式 Exception 捕获 - 用列表推导式替换冗余 for 循环 - 为类属性添加 ClassVar 注解 - 统一 Union/Optional 写法为 | - 移除未使用的导入 - 修复 SQLAlchemy 空值比较语法 - 优化字符串拼接与字典更新逻辑 - 补充缺失的 noqa 注释与异常链 BREAKING CHANGE: 所有插件基类的类级字段现要求显式 ClassVar 注解,自定义插件需同步更新
This commit is contained in:
@@ -21,11 +21,11 @@ mcp = FastMCP("Demo Server")
|
||||
@mcp.tool()
|
||||
def add(a: int, b: int) -> int:
|
||||
"""将两个数字相加
|
||||
|
||||
|
||||
Args:
|
||||
a: 第一个数字
|
||||
b: 第二个数字
|
||||
|
||||
|
||||
Returns:
|
||||
两个数字的和
|
||||
"""
|
||||
@@ -35,11 +35,11 @@ def add(a: int, b: int) -> int:
|
||||
@mcp.tool()
|
||||
def multiply(a: float, b: float) -> float:
|
||||
"""将两个数字相乘
|
||||
|
||||
|
||||
Args:
|
||||
a: 第一个数字
|
||||
b: 第二个数字
|
||||
|
||||
|
||||
Returns:
|
||||
两个数字的乘积
|
||||
"""
|
||||
@@ -49,10 +49,10 @@ def multiply(a: float, b: float) -> float:
|
||||
@mcp.tool()
|
||||
def get_weather(city: str) -> str:
|
||||
"""获取指定城市的天气信息(模拟)
|
||||
|
||||
|
||||
Args:
|
||||
city: 城市名称
|
||||
|
||||
|
||||
Returns:
|
||||
天气信息字符串
|
||||
"""
|
||||
@@ -73,11 +73,11 @@ def get_weather(city: str) -> str:
|
||||
@mcp.tool()
|
||||
def echo(message: str, repeat: int = 1) -> str:
|
||||
"""重复输出一条消息
|
||||
|
||||
|
||||
Args:
|
||||
message: 要重复的消息
|
||||
repeat: 重复次数,默认为 1
|
||||
|
||||
|
||||
Returns:
|
||||
重复后的消息
|
||||
"""
|
||||
@@ -87,10 +87,10 @@ def echo(message: str, repeat: int = 1) -> str:
|
||||
@mcp.tool()
|
||||
def check_prime(number: int) -> bool:
|
||||
"""检查一个数字是否为质数
|
||||
|
||||
|
||||
Args:
|
||||
number: 要检查的数字
|
||||
|
||||
|
||||
Returns:
|
||||
如果是质数返回 True,否则返回 False
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user