Skip to content

Commit 5d8927d

Browse files
Merge branch 'v1.x' into fweinberger/dcr-empty-url-coerce-v1x
2 parents aabed62 + 8d4c2f5 commit 5d8927d

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/mcp/server/fastmcp/utilities/func_metadata.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
BaseModel,
1111
ConfigDict,
1212
Field,
13+
PydanticUserError,
1314
RootModel,
1415
WithJsonSchema,
1516
create_model,
@@ -411,9 +412,16 @@ def _try_create_model_and_schema(
411412
# Use StrictJsonSchema to raise exceptions instead of warnings
412413
try:
413414
schema = model.model_json_schema(schema_generator=StrictJsonSchema)
414-
except (TypeError, ValueError, pydantic_core.SchemaError, pydantic_core.ValidationError) as e:
415+
except (
416+
PydanticUserError,
417+
TypeError,
418+
ValueError,
419+
pydantic_core.SchemaError,
420+
pydantic_core.ValidationError,
421+
) as e:
415422
# These are expected errors when a type can't be converted to a Pydantic schema
416-
# TypeError: When Pydantic can't handle the type
423+
# PydanticUserError: When Pydantic can't handle the type (e.g. PydanticInvalidForJsonSchema);
424+
# subclasses TypeError on pydantic <2.13 and RuntimeError on pydantic >=2.13
417425
# ValueError: When there are issues with the type definition (including our custom warnings)
418426
# SchemaError: When Pydantic can't build a schema
419427
# ValidationError: When validation fails

0 commit comments

Comments
 (0)