MCP Parameters 增加描述
摘要 本文介绍了两种为MCP工具函数参数添加描述的方法,解决CLINE界面参数显示"No description"的问题。方法1使用Pydantic的Annotated+Field组合,将类型提示与验证规则分离;方法2直接使用Field类定义参数。文中提供了text2Voice函数的具体实现示例,展示了如何通过参数元数据添加中文描述,最终在CLINE界面成功显示参数说明。这两种
·
场景:本地MCP开发完后是否发现CLINE上显示的Parameters 显示No description

方法1 :使用参数元数据 (Annotated)
可以使用 Pydantic 的with 类提供有关参数的其他元数据Annotated。这种方法更受欢迎,因为它更现代,并且将类型提示与验证规则分开
参考代码:
from typing import Annotated
from pydantic import Field
@mcp.tool
def deal_image(
image_url: Annotated[str, Field(description="URL of the image to process")],
resize: Annotated[bool, Field(description="Whether to resize the image")] = False,
width: Annotated[int, Field(description="Target width in pixels", ge=1, le=2000)] = 800,
format: Annotated[
Literal["jpeg", "png", "webp"],
Field(description="Output image format")
] = "jpeg"
) -> dict:
"""Process an image with optional resizing."""
# Implementation...
方法2:使用字段(Field)
参考代码:
@mcp.tool
def getDataFromSql(
query: str = Field(description="Search query string"),
limit: int = Field(10, description="Maximum number of results", ge=1, le=100)
) -> list:
"""Search the database with the provided query."""
# Implementation...
具体实现代码
def register(mcp):
@mcp.tool(
name='text2Voice',
description='文字转语音'
)
def text2Voice(text: Annotated[str, Field(description="传入文本")] ) -> dict[str, Any] | None:
"""语音转文字
text:传入文本
"""
res=utils.Text2Voice(text=text,download=True)
logging.info(f"text2Voice res: {res}")
return res
效果

火山引擎开发者社区是火山引擎打造的AI技术生态平台,聚焦Agent与大模型开发,提供豆包系列模型(图像/视频/视觉)、智能分析与会话工具,并配套评测集、动手实验室及行业案例库。社区通过技术沙龙、挑战赛等活动促进开发者成长,新用户可领50万Tokens权益,助力构建智能应用。
更多推荐
所有评论(0)