mirror of
https://github.com/aljazceru/mcp-python-sdk.git
synced 2025-12-19 14:54:24 +01:00
docs: update README with lifespan examples and usage
Add comprehensive documentation for lifespan support: - Add usage examples for both Server and FastMPC classes - Document startup/shutdown patterns - Show context access in tools and handlers - Clean up spacing in test files
This commit is contained in:
@@ -236,7 +236,7 @@ async def test_lambda_function():
|
||||
|
||||
def test_complex_function_json_schema():
|
||||
"""Test JSON schema generation for complex function arguments.
|
||||
|
||||
|
||||
Note: Different versions of pydantic output slightly different
|
||||
JSON Schema formats for model fields with defaults. The format changed in 2.9.0:
|
||||
|
||||
@@ -245,16 +245,16 @@ def test_complex_function_json_schema():
|
||||
"allOf": [{"$ref": "#/$defs/Model"}],
|
||||
"default": {}
|
||||
}
|
||||
|
||||
|
||||
2. Since 2.9.0:
|
||||
{
|
||||
"$ref": "#/$defs/Model",
|
||||
"default": {}
|
||||
}
|
||||
|
||||
|
||||
Both formats are valid and functionally equivalent. This test accepts either format
|
||||
to ensure compatibility across our supported pydantic versions.
|
||||
|
||||
|
||||
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
|
||||
@@ -262,17 +262,17 @@ def test_complex_function_json_schema():
|
||||
"""
|
||||
meta = func_metadata(complex_arguments_fn)
|
||||
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': {}
|
||||
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": {
|
||||
"InnerModel": {
|
||||
|
||||
Reference in New Issue
Block a user