Spaces:
Sleeping
Sleeping
Jeremiah Lowin Claude commited on
Commit ·
6d63e16
1
Parent(s): 923cf05
Use dataclasses.asdict() for better maintainability
Browse files🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
- src/fastmcp/cli/cli.py +10 -13
src/fastmcp/cli/cli.py
CHANGED
|
@@ -492,26 +492,23 @@ def inspect(
|
|
| 492 |
info = asyncio.run(get_info())
|
| 493 |
|
| 494 |
# Convert to dict for JSON serialization
|
| 495 |
-
|
| 496 |
-
|
| 497 |
-
|
| 498 |
-
|
| 499 |
-
|
| 500 |
-
|
| 501 |
-
elif isinstance(obj, list):
|
| 502 |
-
return [convert_dataclass_to_dict(item) for item in obj]
|
| 503 |
elif isinstance(obj, set):
|
| 504 |
return list(obj)
|
| 505 |
elif hasattr(obj, "model_dump"): # Pydantic models
|
| 506 |
return obj.model_dump()
|
| 507 |
-
elif hasattr(obj, "__dict__"): # Other objects with __dict__
|
| 508 |
-
return {
|
| 509 |
-
k: convert_dataclass_to_dict(v) for k, v in obj.__dict__.items()
|
| 510 |
-
}
|
| 511 |
else:
|
| 512 |
return obj
|
| 513 |
|
| 514 |
-
info_dict =
|
|
|
|
|
|
|
|
|
|
| 515 |
|
| 516 |
# Ensure output directory exists
|
| 517 |
output.parent.mkdir(parents=True, exist_ok=True)
|
|
|
|
| 492 |
info = asyncio.run(get_info())
|
| 493 |
|
| 494 |
# Convert to dict for JSON serialization
|
| 495 |
+
from dataclasses import asdict
|
| 496 |
+
|
| 497 |
+
def convert_for_json(obj):
|
| 498 |
+
"""Convert objects for JSON serialization."""
|
| 499 |
+
if isinstance(obj, list):
|
| 500 |
+
return [convert_for_json(item) for item in obj]
|
|
|
|
|
|
|
| 501 |
elif isinstance(obj, set):
|
| 502 |
return list(obj)
|
| 503 |
elif hasattr(obj, "model_dump"): # Pydantic models
|
| 504 |
return obj.model_dump()
|
|
|
|
|
|
|
|
|
|
|
|
|
| 505 |
else:
|
| 506 |
return obj
|
| 507 |
|
| 508 |
+
info_dict = asdict(
|
| 509 |
+
info,
|
| 510 |
+
dict_factory=lambda fields: {k: convert_for_json(v) for k, v in fields},
|
| 511 |
+
)
|
| 512 |
|
| 513 |
# Ensure output directory exists
|
| 514 |
output.parent.mkdir(parents=True, exist_ok=True)
|