Spaces:
Running
Running
Jeremiah Lowin commited on
Commit ·
27acfdd
1
Parent(s): 969a58f
Update tool.py
Browse files
src/fastmcp/tools/tool.py
CHANGED
|
@@ -27,6 +27,10 @@ if TYPE_CHECKING:
|
|
| 27 |
logger = get_logger(__name__)
|
| 28 |
|
| 29 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
class Tool(BaseModel):
|
| 31 |
"""Internal tool registration info."""
|
| 32 |
|
|
@@ -185,7 +189,9 @@ def _convert_to_content(
|
|
| 185 |
return other_content + mcp_types
|
| 186 |
|
| 187 |
if not isinstance(result, str):
|
| 188 |
-
if serializer is
|
|
|
|
|
|
|
| 189 |
try:
|
| 190 |
result = serializer(result)
|
| 191 |
except Exception as e:
|
|
@@ -194,9 +200,6 @@ def _convert_to_content(
|
|
| 194 |
e,
|
| 195 |
exc_info=True,
|
| 196 |
)
|
| 197 |
-
|
| 198 |
-
result = pydantic_core.to_json(result, fallback=str, indent=2).decode()
|
| 199 |
-
else:
|
| 200 |
-
result = pydantic_core.to_json(result, fallback=str, indent=2).decode()
|
| 201 |
|
| 202 |
return [TextContent(type="text", text=result)]
|
|
|
|
| 27 |
logger = get_logger(__name__)
|
| 28 |
|
| 29 |
|
| 30 |
+
def default_serializer(data: Any) -> str:
|
| 31 |
+
return pydantic_core.to_json(data, fallback=str, indent=2).decode()
|
| 32 |
+
|
| 33 |
+
|
| 34 |
class Tool(BaseModel):
|
| 35 |
"""Internal tool registration info."""
|
| 36 |
|
|
|
|
| 189 |
return other_content + mcp_types
|
| 190 |
|
| 191 |
if not isinstance(result, str):
|
| 192 |
+
if serializer is None:
|
| 193 |
+
result = default_serializer(result)
|
| 194 |
+
else:
|
| 195 |
try:
|
| 196 |
result = serializer(result)
|
| 197 |
except Exception as e:
|
|
|
|
| 200 |
e,
|
| 201 |
exc_info=True,
|
| 202 |
)
|
| 203 |
+
result = default_serializer(result)
|
|
|
|
|
|
|
|
|
|
| 204 |
|
| 205 |
return [TextContent(type="text", text=result)]
|