MCP协议中Tool的JSON Schema定义规范
请详细解释MCP Server中Tool定义的JSON Schema规范。如何编写高质量的Tool参数Schema?如何描述参数类型、枚举、嵌套对象、数组?
回答
Yahuda
MCP Tool Schema基于JSON Schema draft-07+。
基本结构:name/description/inputSchema(type:object/properties/required)。
类型:string/number/integer/boolean/array/object/null。
高质量Schema原则:description要详细(LLM据此理解参数)、enum限制枚举值、default减少必传参数、示例值通过description提供。
最佳实践:参数3-5个、description动词开头、避免type:any、枚举值不超过5个。