Skip to content

Commit 2a61357

Browse files
relax pydantic requirements
1 parent 44c0004 commit 2a61357

File tree

2 files changed

+45
-4
lines changed

2 files changed

+45
-4
lines changed

pyproject.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@ dependencies = [
2525
"anyio>=4.5",
2626
"httpx>=0.27",
2727
"httpx-sse>=0.4",
28-
"pydantic>=2.10.1,<3.0.0",
28+
"pydantic>=2.7.2,<3.0.0",
2929
"starlette>=0.27",
3030
"sse-starlette>=1.6.1",
31-
"pydantic-settings>=2.6.1",
32-
"uvicorn>=0.30",
31+
"pydantic-settings>=2.5.2",
32+
"uvicorn>=0.23.1",
3333
]
3434

3535
[project.optional-dependencies]

tests/server/fastmcp/test_func_metadata.py

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from typing import Annotated
22

33
import annotated_types
4+
import json
45
import pytest
56
from pydantic import BaseModel, Field
67

@@ -235,8 +236,48 @@ async def check_call(args):
235236

236237

237238
def test_complex_function_json_schema():
239+
"""Test JSON schema generation for complex function arguments.
240+
241+
Note: This test accepts two equivalent JSON Schema formats for models with defaults:
242+
1. Pre-pydantic 2.7.2:
243+
{
244+
"$ref": "#/$defs/Model",
245+
"default": {}
246+
}
247+
248+
2. Pydantic 2.7.2+:
249+
{
250+
"allOf": [
251+
{
252+
"$ref": "#/$defs/Model"
253+
}
254+
],
255+
"default": {}
256+
}
257+
258+
Both formats are valid JSON Schema and represent the same validation rules.
259+
The newer format using allOf is more correct according to the JSON Schema spec
260+
as it properly composes the reference with additional properties.
261+
262+
This change in format does not affect runtime behavior since:
263+
1. Both schemas validate the same way
264+
2. The actual model classes and validation logic are unchanged
265+
3. func_metadata uses model_validate/model_dump, not the schema directly
266+
"""
238267
meta = func_metadata(complex_arguments_fn)
239-
assert meta.arg_model.model_json_schema() == {
268+
actual_schema = meta.arg_model.model_json_schema()
269+
270+
# Create a copy of the actual schema to normalize
271+
normalized_schema = actual_schema.copy()
272+
273+
# Normalize the my_model_a_with_default field to handle both pydantic formats
274+
if 'allOf' in actual_schema['properties']['my_model_a_with_default']:
275+
normalized_schema['properties']['my_model_a_with_default'] = {
276+
'$ref': '#/$defs/SomeInputModelA',
277+
'default': {}
278+
}
279+
280+
assert normalized_schema == {
240281
"$defs": {
241282
"InnerModel": {
242283
"properties": {"x": {"title": "X", "type": "integer"}},

0 commit comments

Comments
 (0)