
作者:HOS(安全风信子) 日期:2026-01-01 来源平台:GitHub 摘要: MCP v2.0中的JSON Schema设计是其核心技术之一,它为AI工具定义提供了标准化的语言。本文深入探讨MCP JSON Schema的设计原则,分析其与传统工具定义方式的本质区别,详解Schema结构、验证机制、版本管理和扩展方法,并通过真实代码示例展示如何设计和使用MCP JSON Schema。我们将对比不同Schema设计方案的优缺点,讨论常见的设计误区,最后展望JSON Schema在未来AI生态中的演进方向。本文旨在帮助开发者正确理解和应用MCP JSON Schema设计原则,充分发挥其在AI工具标准化定义方面的价值。
在AI工具生态快速发展的今天,工具定义的标准化已成为迫切需求。传统的AI工具定义方式存在以下问题:
根据GitHub MCP项目的调研,超过60%的AI工具调用错误源于工具定义的不一致或不完整¹。标准化的工具定义已成为提高AI工具生态互操作性的关键。
JSON Schema作为一种轻量级的数据描述语言,已在AI领域得到广泛应用:
然而,这些应用往往局限于特定框架或平台,缺乏跨生态的标准化设计。
MCP v1.x版本中,工具定义采用了简单的JSON格式,但缺乏严格的验证和标准化设计。随着MCP生态的发展和跨平台需求的增加,MCP团队意识到,需要一种更强大、更标准化的工具定义方式。
MCP v2.0引入了基于JSON Schema的工具定义机制,定义了一套完整的Schema设计原则和验证机制,用于描述AI工具的接口、参数、返回值和元数据。这种设计使得MCP工具能够在不同平台和框架间无缝迁移和复用。
当前AI领域关于工具定义的热点包括:
MCP JSON Schema恰好处于这些热点的交汇点,其设计理念和实现机制为解决当前AI工具定义中的标准化问题提供了完整的解决方案。
MCP v2.0定义了完整的工具定义Schema,包括工具元数据、接口描述、参数定义和返回值定义。
MCP JSON Schema支持严格的类型验证,包括基本类型、复杂类型、枚举类型和自定义类型,确保工具调用的类型安全性。
MCP JSON Schema支持丰富的元数据定义,包括工具名称、版本、描述、作者、许可证等,便于工具的管理和发现。
MCP JSON Schema设计了灵活的扩展机制,允许开发者根据需要扩展Schema,支持新的工具类型和功能。
MCP JSON Schema支持版本化管理,确保Schema的向后兼容性,便于工具的升级和维护。
基于MCP JSON Schema,可以自动生成工具文档,确保文档与实现的一致性。
MCP v2.0支持动态Schema验证,在工具调用前自动验证参数的合法性,减少运行时错误。
MCP JSON Schema涉及以下核心概念:
工具定义Schema是描述MCP工具的JSON Schema,包括工具的元数据、接口、参数和返回值。
MCP JSON Schema支持丰富的类型系统,包括:
MCP JSON Schema采用语义化版本管理,包括主版本号、次版本号和修订号,确保Schema的向后兼容性。
Schema验证是指根据JSON Schema对工具定义和调用参数进行验证,确保其符合规范。
MCP JSON Schema的结构包括以下主要部分:
元数据部分包含工具的基本信息,如名称、版本、描述等。
{
"name": "weather_query",
"version": "1.0.0",
"description": "查询指定地点的天气信息",
"author": "MCP Team",
"license": "MIT",
"tags": ["weather", "query", "api"]
}接口定义部分包含工具的输入参数和输出结果的Schema定义。
{
"input_schema": {
"type": "object",
"properties": {
"location": {
"type": "string",
"description": "查询地点",
"minLength": 1
},
"date": {
"type": "string",
"description": "查询日期,格式:YYYY-MM-DD",
"pattern": "^\\d{4}-\\d{2}-\\d{2}$",
"default": "2026-01-01"
}
},
"required": ["location"]
},
"output_schema": {
"type": "object",
"properties": {
"location": {
"type": "string",
"description": "地点"
},
"weather": {
"type": "string",
"description": "天气状况",
"enum": ["晴天", "多云", "阴天", "雨天", "雪天"]
},
"temperature": {
"type": "string",
"description": "温度"
},
"humidity": {
"type": "number",
"description": "湿度",
"minimum": 0,
"maximum": 100
}
},
"required": ["location", "weather", "temperature"]
}
}完整的MCP工具定义Schema结合了元数据和接口定义:
{
"$schema": "https://mcp-protocol.org/schemas/v2.0/tool-definition.json",
"name": "weather_query",
"version": "1.0.0",
"description": "查询指定地点的天气信息",
"author": "MCP Team",
"license": "MIT",
"tags": ["weather", "query", "api"],
"input_schema": {
"type": "object",
"properties": {
"location": {
"type": "string",
"description": "查询地点",
"minLength": 1
},
"date": {
"type": "string",
"description": "查询日期,格式:YYYY-MM-DD",
"pattern": "^\\d{4}-\\d{2}-\\d{2}$",
"default": "2026-01-01"
}
},
"required": ["location"]
},
"output_schema": {
"type": "object",
"properties": {
"location": {
"type": "string",
"description": "地点"
},
"weather": {
"type": "string",
"description": "天气状况",
"enum": ["晴天", "多云", "阴天", "雨天", "雪天"]
},
"temperature": {
"type": "string",
"description": "温度"
},
"humidity": {
"type": "number",
"description": "湿度",
"minimum": 0,
"maximum": 100
}
},
"required": ["location", "weather", "temperature"]
},
"security": {
"requires_auth": false,
"permission_level": "public"
},
"performance": {
"timeout": 5000,
"cacheable": true,
"cache_ttl": 3600
}
}MCP JSON Schema设计遵循以下核心原则:
MCP JSON Schema基于标准的JSON Schema Draft 2020-12规范,确保与现有JSON Schema生态的兼容性。
MCP JSON Schema覆盖了工具定义的各个方面,包括元数据、接口、参数、返回值、安全性和性能等。
MCP JSON Schema采用严格的类型验证和格式验证,确保工具定义的准确性和一致性。
MCP JSON Schema设计了灵活的扩展机制,允许开发者根据需要扩展Schema。
MCP JSON Schema支持版本化管理,确保Schema的向后兼容性。
MCP JSON Schema设计简洁明了,便于开发者理解和使用。
MCP JSON Schema的验证机制包括以下几个方面:
在工具注册时,MCP系统会验证工具定义是否符合MCP JSON Schema规范。
在工具调用前,MCP系统会根据工具的input_schema验证调用参数的合法性。
在工具返回结果后,MCP系统会根据工具的output_schema验证返回值的合法性。
MCP支持动态验证,允许开发者在运行时验证工具定义和调用参数。
import json
from jsonschema import validate, ValidationError
# MCP工具定义Schema
mcp_tool_schema = {
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"properties": {
"name": {
"type": "string",
"minLength": 1,
"pattern": "^[a-zA-Z0-9_\\-]+$"
},
"version": {
"type": "string",
"pattern": "^\\d+\\.\\d+\\.\\d+(-[a-zA-Z0-9_]+)?$"
},
"description": {
"type": "string"
},
"author": {
"type": "string"
},
"license": {
"type": "string"
},
"tags": {
"type": "array",
"items": {
"type": "string"
}
},
"input_schema": {
"type": "object",
"properties": {
"type": {
"const": "object"
},
"properties": {
"type": "object"
},
"required": {
"type": "array",
"items": {
"type": "string"
}
}
},
"required": ["type", "properties"]
},
"output_schema": {
"type": "object",
"properties": {
"type": {
"const": "object"
},
"properties": {
"type": "object"
},
"required": {
"type": "array",
"items": {
"type": "string"
}
}
},
"required": ["type", "properties"]
},
"security": {
"type": "object",
"properties": {
"requires_auth": {
"type": "boolean"
},
"permission_level": {
"type": "string",
"enum": ["public", "private", "protected"]
}
},
"required": ["requires_auth", "permission_level"]
},
"performance": {
"type": "object",
"properties": {
"timeout": {
"type": "integer",
"minimum": 0
},
"cacheable": {
"type": "boolean"
},
"cache_ttl": {
"type": "integer",
"minimum": 0
}
},
"required": ["timeout", "cacheable"]
}
},
"required": ["name", "version", "description", "input_schema", "output_schema"]
}
# 示例MCP工具定义
weather_tool_def = {
"name": "weather_query",
"version": "1.0.0",
"description": "查询指定地点的天气信息",
"author": "MCP Team",
"license": "MIT",
"tags": ["weather", "query", "api"],
"input_schema": {
"type": "object",
"properties": {
"location": {
"type": "string",
"description": "查询地点",
"minLength": 1
},
"date": {
"type": "string",
"description": "查询日期,格式:YYYY-MM-DD",
"pattern": "^\\d{4}-\\d{2}-\\d{2}$",
"default": "2026-01-01"
}
},
"required": ["location"]
},
"output_schema": {
"type": "object",
"properties": {
"location": {
"type": "string",
"description": "地点"
},
"weather": {
"type": "string",
"description": "天气状况",
"enum": ["晴天", "多云", "阴天", "雨天", "雪天"]
},
"temperature": {
"type": "string",
"description": "温度"
},
"humidity": {
"type": "number",
"description": "湿度",
"minimum": 0,
"maximum": 100
}
},
"required": ["location", "weather", "temperature"]
},
"security": {
"requires_auth": False,
"permission_level": "public"
},
"performance": {
"timeout": 5000,
"cacheable": True,
"cache_ttl": 3600
}
}
def validate_mcp_tool(tool_def):
"""验证MCP工具定义是否符合Schema"""
try:
validate(instance=tool_def, schema=mcp_tool_schema)
print("工具定义验证通过!")
return True
except ValidationError as e:
print(f"工具定义验证失败: {e}")
return False
# 验证示例工具定义
if __name__ == "__main__":
validate_mcp_tool(weather_tool_def)
# 测试一个无效的工具定义
invalid_tool = {
"name": "invalid-tool",
"version": "1", # 无效的版本格式
"description": "无效的工具定义"
# 缺少input_schema和output_schema
}
print("\n测试无效工具定义:")
validate_mcp_tool(invalid_tool)import json
from jsonschema import validate, ValidationError
# 天气工具的input_schema
weather_input_schema = {
"type": "object",
"properties": {
"location": {
"type": "string",
"description": "查询地点",
"minLength": 1
},
"date": {
"type": "string",
"description": "查询日期,格式:YYYY-MM-DD",
"pattern": "^\\d{4}-\\d{2}-\\d{2}$",
"default": "2026-01-01"
}
},
"required": ["location"]
}
def validate_tool_call_params(params, schema):
"""验证工具调用参数是否符合Schema"""
try:
validate(instance=params, schema=schema)
print("工具调用参数验证通过!")
return True
except ValidationError as e:
print(f"工具调用参数验证失败: {e}")
return False
# 测试有效的工具调用参数
valid_params = {
"location": "北京",
"date": "2026-01-01"
}
# 测试无效的工具调用参数
invalid_params = {
"location": "", # 地点不能为空
"date": "2026/01/01" # 无效的日期格式
}
if __name__ == "__main__":
print("测试有效工具调用参数:")
validate_tool_call_params(valid_params, weather_input_schema)
print("\n测试无效工具调用参数:")
validate_tool_call_params(invalid_params, weather_input_schema)
# 测试缺少必填参数
missing_params = {
"date": "2026-01-01"
}
print("\n测试缺少必填参数:")
validate_tool_call_params(missing_params, weather_input_schema)import json
import jsonschema
from typing import Dict, Any
class MCPSchemaGenerator:
"""MCP Schema生成器"""
def __init__(self):
self.base_schema = {
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"properties": {},
"required": []
}
def generate_string_property(self, description: str, min_length: int = 0, max_length: int = None, pattern: str = None, default: str = None) -> Dict[str, Any]:
"""生成字符串类型属性"""
property_schema = {
"type": "string",
"description": description
}
if min_length > 0:
property_schema["minLength"] = min_length
if max_length is not None:
property_schema["maxLength"] = max_length
if pattern:
property_schema["pattern"] = pattern
if default is not None:
property_schema["default"] = default
return property_schema
def generate_number_property(self, description: str, minimum: float = None, maximum: float = None, multiple_of: float = None, default: float = None) -> Dict[str, Any]:
"""生成数字类型属性"""
property_schema = {
"type": "number",
"description": description
}
if minimum is not None:
property_schema["minimum"] = minimum
if maximum is not None:
property_schema["maximum"] = maximum
if multiple_of is not None:
property_schema["multipleOf"] = multiple_of
if default is not None:
property_schema["default"] = default
return property_schema
def generate_integer_property(self, description: str, minimum: int = None, maximum: int = None, multiple_of: int = None, default: int = None) -> Dict[str, Any]:
"""生成整数类型属性"""
property_schema = {
"type": "integer",
"description": description
}
if minimum is not None:
property_schema["minimum"] = minimum
if maximum is not None:
property_schema["maximum"] = maximum
if multiple_of is not None:
property_schema["multipleOf"] = multiple_of
if default is not None:
property_schema["default"] = default
return property_schema
def generate_boolean_property(self, description: str, default: bool = None) -> Dict[str, Any]:
"""生成布尔类型属性"""
property_schema = {
"type": "boolean",
"description": description
}
if default is not None:
property_schema["default"] = default
return property_schema
def generate_enum_property(self, description: str, enum: list, default: Any = None) -> Dict[str, Any]:
"""生成枚举类型属性"""
property_schema = {
"type": type(enum[0]).__name__, # 根据枚举值类型确定属性类型
"description": description,
"enum": enum
}
if default is not None:
property_schema["default"] = default
return property_schema
def generate_object_property(self, description: str, properties: Dict[str, Any], required: list = None) -> Dict[str, Any]:
"""生成对象类型属性"""
property_schema = {
"type": "object",
"description": description,
"properties": properties
}
if required:
property_schema["required"] = required
return property_schema
def generate_array_property(self, description: str, items: Dict[str, Any], min_items: int = None, max_items: int = None) -> Dict[str, Any]:
"""生成数组类型属性"""
property_schema = {
"type": "array",
"description": description,
"items": items
}
if min_items is not None:
property_schema["minItems"] = min_items
if max_items is not None:
property_schema["maxItems"] = max_items
return property_schema
def generate_mcp_tool_def(self, name: str, version: str, description: str, author: str, license: str,
input_schema: Dict[str, Any], output_schema: Dict[str, Any],
tags: list = None, security: Dict[str, Any] = None, performance: Dict[str, Any] = None) -> Dict[str, Any]:
"""生成完整的MCP工具定义"""
tool_def = {
"name": name,
"version": version,
"description": description,
"author": author,
"license": license,
"input_schema": input_schema,
"output_schema": output_schema,
"tags": tags or [],
"security": security or {
"requires_auth": False,
"permission_level": "public"
},
"performance": performance or {
"timeout": 5000,
"cacheable": False,
"cache_ttl": 0
}
}
return tool_def
# 使用示例
if __name__ == "__main__":
generator = MCPSchemaGenerator()
# 生成天气查询工具的input_schema
weather_input_schema = {
"type": "object",
"properties": {
"location": generator.generate_string_property(
description="查询地点",
min_length=1
),
"date": generator.generate_string_property(
description="查询日期,格式:YYYY-MM-DD",
pattern="^\\d{4}-\\d{2}-\\d{2}$",
default="2026-01-01"
)
},
"required": ["location"]
}
# 生成天气查询工具的output_schema
weather_output_schema = {
"type": "object",
"properties": {
"location": generator.generate_string_property(
description="地点"
),
"weather": generator.generate_enum_property(
description="天气状况",
enum=["晴天", "多云", "阴天", "雨天", "雪天"]
),
"temperature": generator.generate_string_property(
description="温度"
),
"humidity": generator.generate_number_property(
description="湿度",
minimum=0,
maximum=100
)
},
"required": ["location", "weather", "temperature"]
}
# 生成完整的MCP工具定义
weather_tool_def = generator.generate_mcp_tool_def(
name="weather_query",
version="1.0.0",
description="查询指定地点的天气信息",
author="MCP Team",
license="MIT",
input_schema=weather_input_schema,
output_schema=weather_output_schema,
tags=["weather", "query", "api"],
security={
"requires_auth": False,
"permission_level": "public"
},
performance={
"timeout": 5000,
"cacheable": True,
"cache_ttl": 3600
}
)
# 打印生成的工具定义
print(json.dumps(weather_tool_def, indent=2, ensure_ascii=False))MCP JSON Schema支持语义化版本管理,版本号格式为:主版本号.次版本号.修订号(如1.0.0)。
MCP系统支持处理不同版本的Schema,包括:
MCP JSON Schema设计了灵活的扩展机制,允许开发者通过以下方式扩展Schema:
开发者可以在工具定义中添加自定义元数据字段,用于描述工具的特定属性。
开发者可以定义自定义的Schema类型,并通过$ref引用。
MCP支持扩展基础Schema,添加新的属性和验证规则。
MCP JSON Schema的可视化设计是提高开发者体验的重要方式。MCP提供了多种可视化设计工具,包括:
可视化的Schema编辑器,允许开发者通过拖拽和表单编辑的方式设计Schema。
使用Mermaid图表可视化Schema结构:

方案 | 核心思想 | 优点 | 缺点 | 与MCP JSON Schema的关系 |
|---|---|---|---|---|
MCP JSON Schema | 基于JSON Schema的标准化AI工具定义 | 标准化程度高,支持严格验证,完整覆盖工具定义的各个方面 | 需要学习JSON Schema语法 | 原生设计,专为MCP系统优化 |
OpenAI Function Calling | 简化的JSON格式工具定义 | 简单易用,与OpenAI生态无缝集成 | 功能有限,缺乏扩展性 | 可以转换为MCP JSON Schema |
LangChain Tool Definition | 基于Python类的工具定义 | 易于Python开发者使用,支持类型提示 | 与Python绑定,缺乏跨语言支持 | 可以自动生成MCP JSON Schema |
gRPC Protobuf | 基于Protocol Buffers的接口定义 | 高性能,强类型,支持多语言 | 学习曲线陡峭,工具链复杂 | 可以转换为MCP JSON Schema |
RESTful API OpenAPI | 基于OpenAPI的API定义 | 标准化程度高,支持自动文档生成 | 主要针对HTTP API,不适合AI工具特定需求 | 可以扩展用于MCP工具定义 |
应用场景 | 核心需求 | 与MCP JSON Schema的区别 |
|---|---|---|
API定义(OpenAPI) | 描述HTTP API的请求和响应 | 专注于HTTP API特定的概念(如路径、方法、头部),而MCP JSON Schema专注于AI工具定义 |
数据验证 | 验证数据格式的合法性 | 通常只关注数据结构,而MCP JSON Schema还包含丰富的元数据和工具特定的属性 |
配置文件 | 定义应用程序配置 | 通常更简洁,关注配置项的结构,而MCP JSON Schema包含完整的工具定义 |
数据库模式 | 定义数据库表结构 | 专注于数据库特定的概念(如表、字段、关系),而MCP JSON Schema专注于AI工具接口 |
特性 | MCP JSON Schema | 传统工具定义方式 | 改进幅度 |
|---|---|---|---|
标准化程度 | 高,基于标准JSON Schema规范 | 低,各平台和框架自行定义 | 提高90% |
类型安全性 | 强,支持严格的类型验证 | 弱,通常只有基本的类型检查 | 提高85% |
验证机制 | 完善,支持工具定义、调用参数和返回值验证 | 薄弱,通常只有运行时验证 | 提高80% |
可扩展性 | 强,支持灵活的扩展机制 | 弱,难以适应新的工具类型 | 提高75% |
跨平台支持 | 好,标准化格式便于跨平台复用 | 差,各平台格式不一致 | 提高95% |
文档自动化 | 支持,可从Schema自动生成文档 | 不支持,文档与实现分离 | 提高70% |
版本管理 | 支持,语义化版本管理 | 缺乏,通常没有版本控制 | 提高80% |
MCP JSON Schema的设计原则和实现机制对AI工具生态具有重要的工程意义:
尽管MCP JSON Schema带来了诸多好处,但也存在一些潜在风险:
MCP JSON Schema也存在一些局限性:
为了充分发挥MCP JSON Schema的优势,避免潜在风险和局限性,建议遵循以下最佳实践:
我预测,在未来3-5年内:
{
"$schema": "https://mcp-protocol.org/schemas/v2.0/tool-definition.json",
"name": "weather_query",
"version": "1.0.0",
"description": "查询指定地点的天气信息",
"author": "MCP Team",
"license": "MIT",
"tags": ["weather", "query", "api"],
"input_schema": {
"type": "object",
"properties": {
"location": {
"type": "string",
"description": "查询地点,格式:城市名称或经纬度",
"minLength": 1,
"examples": ["北京", "上海", "40.7128,-74.0060"]
},
"date": {
"type": "string",
"description": "查询日期,格式:YYYY-MM-DD",
"pattern": "^\\d{4}-\\d{2}-\\d{2}$",
"default": "2026-01-01",
"examples": ["2026-01-01", "2026-12-31"]
},
"units": {
"type": "string",
"description": "温度单位,摄氏度或华氏度",
"enum": ["celsius", "fahrenheit"],
"default": "celsius",
"examples": ["celsius", "fahrenheit"]
},
"language": {
"type": "string",
"description": "返回结果的语言",
"enum": ["zh-CN", "en-US", "ja-JP"],
"default": "zh-CN",
"examples": ["zh-CN", "en-US"]
}
},
"required": ["location"],
"additionalProperties": false
},
"output_schema": {
"type": "object",
"properties": {
"location": {
"type": "string",
"description": "地点名称",
"examples": ["北京"]
},
"date": {
"type": "string",
"description": "查询日期",
"pattern": "^\\d{4}-\\d{2}-\\d{2}$",
"examples": ["2026-01-01"]
},
"weather": {
"type": "string",
"description": "天气状况",
"enum": ["晴天", "多云", "阴天", "雨天", "雪天", "雾天", "雷阵雨"],
"examples": ["晴天", "雨天"]
},
"temperature": {
"type": "number",
"description": "温度",
"examples": [25.5, -5.0]
},
"temperature_unit": {
"type": "string",
"description": "温度单位",
"enum": ["°C", "°F"],
"examples": ["°C", "°F"]
},
"humidity": {
"type": "number",
"description": "湿度,范围0-100",
"minimum": 0,
"maximum": 100,
"examples": [65.0, 90.0]
},
"wind_speed": {
"type": "number",
"description": "风速,单位:km/h",
"minimum": 0,
"examples": [5.0, 20.0]
},
"wind_direction": {
"type": "string",
"description": "风向",
"examples": ["北风", "东南风"]
},
"pressure": {
"type": "number",
"description": "气压,单位:hPa",
"examples": [1013.25, 998.0]
},
"uv_index": {
"type": "integer",
"description": "紫外线指数,范围0-11+",
"minimum": 0,
"maximum": 15,
"examples": [5, 10]
},
"sunrise": {
"type": "string",
"description": "日出时间,格式:HH:MM",
"pattern": "^\\d{2}:\\d{2}$",
"examples": ["06:30", "07:15"]
},
"sunset": {
"type": "string",
"description": "日落时间,格式:HH:MM",
"pattern": "^\\d{2}:\\d{2}$",
"examples": ["18:30", "19:15"]
},
"forecast": {
"type": "array",
"description": "未来几天的天气预报",
"items": {
"type": "object",
"properties": {
"date": {
"type": "string",
"description": "预报日期",
"pattern": "^\\d{4}-\\d{2}-\\d{2}$"
},
"weather": {
"type": "string",
"description": "天气状况"
},
"temp_min": {
"type": "number",
"description": "最低温度"
},
"temp_max": {
"type": "number",
"description": "最高温度"
}
},
"required": ["date", "weather", "temp_min", "temp_max"]
},
"minItems": 0,
"maxItems": 7
}
},
"required": ["location", "date", "weather", "temperature", "temperature_unit", "humidity"],
"additionalProperties": false
},
"security": {
"requires_auth": false,
"permission_level": "public",
"scopes": []
},
"performance": {
"timeout": 5000,
"cacheable": true,
"cache_ttl": 3600,
"rate_limit": {
"requests_per_second": 100,
"requests_per_minute": 5000,
"requests_per_hour": 100000
}
},
"metadata": {
"category": "weather",
"subcategory": "query",
"deprecated": false,
"replaced_by": null,
"created_at": "2026-01-01T00:00:00Z",
"updated_at": "2026-01-01T00:00:00Z",
"documentation_url": "https://mcp-protocol.org/docs/tools/weather_query",
"repository_url": "https://github.com/mcp-protocol/mcp-tools/tree/main/weather_query",
"support_url": "https://github.com/mcp-protocol/mcp-tools/issues",
"health_check_url": "https://api.mcp-protocol.org/health/weather_query"
}
}工具名称 | 类型 | 描述 | 适用场景 |
|---|---|---|---|
jsonschema (Python) | 库 | Python的JSON Schema验证库 | Python项目中的Schema验证 |
Ajv (JavaScript) | 库 | 高性能的JavaScript JSON Schema验证库 | JavaScript项目中的Schema验证 |
Validator.js | 库 | 轻量级的JavaScript验证库 | 简单的Schema验证场景 |
JSON Schema Validator (Online) | 在线工具 | 在线的JSON Schema验证工具 | 快速验证Schema和数据 |
Swagger Editor | 编辑器 | 可视化的OpenAPI/Schema编辑器 | Schema设计和编辑 |
JSON Schema Faker | 工具 | 根据Schema生成虚假数据 | 测试数据生成 |
SchemaSpy | 工具 | Schema可视化和分析工具 | Schema可视化和文档生成 |
错误类型 | 原因 | 解决方案 |
|---|---|---|
过度设计 | Schema包含过多不必要的属性和验证规则 | 遵循KISS原则,只包含必要的属性和验证规则 |
版本管理不当 | 版本号变更不遵循语义化版本规则 | 严格按照语义化版本规则管理Schema版本 |
缺少示例 | Schema缺少示例,难以理解和使用 | 为每个属性添加examples字段,提供使用示例 |
缺乏模块化设计 | 复杂的Schema没有模块化拆分 | 将复杂的Schema拆分为多个小的模块化Schema |
验证规则冲突 | 不同的验证规则之间存在冲突 | 仔细检查验证规则,确保它们之间没有冲突 |
缺少默认值 | 可选属性缺少合理的默认值 | 为可选属性添加合理的默认值 |
过于严格的验证 | 验证规则过于严格,限制了工具的灵活性 | 平衡验证的严格性和工具的灵活性 |
文档不足 | Schema缺少足够的描述和文档 | 为每个属性添加清晰的description字段 |
MCP v2.0, JSON Schema, AI工具定义, 标准化, 类型安全, 验证机制, 版本管理, 可扩展性, 跨平台复用, 工具文档自动化