convert_openapi_to_mcp_tools 添加了"type"字段,导致可选模式的方案被破坏
以下是示例代码: Python from fastapi_mcp.openapi.convert import convert_openapi_to_mcp_tools from jsonschema import validate openapi_schema = { "openapi": "3.0.3", "info": { "title": "Union Test", "version": "1.0.0" }, "paths": { "/test": { "post": { "operationId": "test_union", "summary": "Test endpoint with a union type", "requestBody": { "required": True, "content": { "application/json": { "schema": { "type": "object", "properties": { "value": { "anyOf": [ {"type": "string", "maxLength": 2000}, {"type": "null"} ], "title": "value" } }, "required": ["value"] } } } }, "responses": { "200": { "description": "OK" } } } } } }
mcp_tools = convert_openapi_to_mcp_tools(openapi_schema=openapi_schema) first_tool = mcp_tools[0][0] mcp_input_schema = first_tool.inputSchema
使用原始 OpenAPI 协议进行验证(正常工作)
validate(instance={"value": None}, schema=openapi_schema)
使用 MCP 生成的协议进行验证(失败)
validate(instance={"value": None}, schema=mcp_input_schema)
jsonschema.exceptions.ValidationError: None 不是 'string' 类型
内容来源: tadata-org/fastapi_mcp