Spaces:
Running
Running
File size: 744 Bytes
ee0baf8 3d12e67 ee0baf8 224caf9 ee0baf8 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | import asyncio
from typing import Any
import yaml
from fastmcp import FastMCP
# Define a simple custom serializer
def custom_dict_serializer(data: Any) -> str:
return yaml.dump(data, width=100, sort_keys=False)
server = FastMCP(name="CustomSerializerExample", tool_serializer=custom_dict_serializer)
@server.tool
def get_example_data() -> dict:
"""Returns some example data."""
return {"name": "Test", "value": 123, "status": True}
async def example_usage():
result = await server._mcp_call_tool("get_example_data", {})
print("Tool Result:")
print(result)
print("This is an example of using a custom serializer with FastMCP.")
if __name__ == "__main__":
asyncio.run(example_usage())
server.run()
|