mirror of
https://github.com/aljazceru/mcp-python-sdk.git
synced 2025-12-19 14:54:24 +01:00
relax pydantic, pydantic-settings, and uvicorn
This commit is contained in:
@@ -25,11 +25,11 @@ dependencies = [
|
|||||||
"anyio>=4.5",
|
"anyio>=4.5",
|
||||||
"httpx>=0.27",
|
"httpx>=0.27",
|
||||||
"httpx-sse>=0.4",
|
"httpx-sse>=0.4",
|
||||||
"pydantic>=2.10.1,<3.0.0",
|
"pydantic>=2.7.2,<3.0.0",
|
||||||
"starlette>=0.27",
|
"starlette>=0.27",
|
||||||
"sse-starlette>=1.6.1",
|
"sse-starlette>=1.6.1",
|
||||||
"pydantic-settings>=2.6.1",
|
"pydantic-settings>=2.5.2",
|
||||||
"uvicorn>=0.30",
|
"uvicorn>=0.23.1",
|
||||||
]
|
]
|
||||||
|
|
||||||
[project.optional-dependencies]
|
[project.optional-dependencies]
|
||||||
|
|||||||
@@ -235,8 +235,48 @@ async def test_lambda_function():
|
|||||||
|
|
||||||
|
|
||||||
def test_complex_function_json_schema():
|
def test_complex_function_json_schema():
|
||||||
|
"""Test JSON schema generation for complex function arguments.
|
||||||
|
|
||||||
|
Note: This test accepts two equivalent JSON Schema formats for models with defaults:
|
||||||
|
1. Pre-pydantic 2.7.2:
|
||||||
|
{
|
||||||
|
"$ref": "#/$defs/Model",
|
||||||
|
"default": {}
|
||||||
|
}
|
||||||
|
|
||||||
|
2. Pydantic 2.7.2+:
|
||||||
|
{
|
||||||
|
"allOf": [
|
||||||
|
{
|
||||||
|
"$ref": "#/$defs/Model"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"default": {}
|
||||||
|
}
|
||||||
|
|
||||||
|
Both formats are valid JSON Schema and represent the same validation rules.
|
||||||
|
The newer format using allOf is more correct according to the JSON Schema spec
|
||||||
|
as it properly composes the reference with additional properties.
|
||||||
|
|
||||||
|
This change in format does not affect runtime behavior since:
|
||||||
|
1. Both schemas validate the same way
|
||||||
|
2. The actual model classes and validation logic are unchanged
|
||||||
|
3. func_metadata uses model_validate/model_dump, not the schema directly
|
||||||
|
"""
|
||||||
meta = func_metadata(complex_arguments_fn)
|
meta = func_metadata(complex_arguments_fn)
|
||||||
assert meta.arg_model.model_json_schema() == {
|
actual_schema = meta.arg_model.model_json_schema()
|
||||||
|
|
||||||
|
# Create a copy of the actual schema to normalize
|
||||||
|
normalized_schema = actual_schema.copy()
|
||||||
|
|
||||||
|
# Normalize the my_model_a_with_default field to handle both pydantic formats
|
||||||
|
if 'allOf' in actual_schema['properties']['my_model_a_with_default']:
|
||||||
|
normalized_schema['properties']['my_model_a_with_default'] = {
|
||||||
|
'$ref': '#/$defs/SomeInputModelA',
|
||||||
|
'default': {}
|
||||||
|
}
|
||||||
|
|
||||||
|
assert normalized_schema == {
|
||||||
"$defs": {
|
"$defs": {
|
||||||
"InnerModel": {
|
"InnerModel": {
|
||||||
"properties": {"x": {"title": "X", "type": "integer"}},
|
"properties": {"x": {"title": "X", "type": "integer"}},
|
||||||
|
|||||||
Reference in New Issue
Block a user