mirror of
https://github.com/PrefectHQ/fastmcp.git
synced 2026-08-28 10:18:08 +02:00
Align output serialization with return types
This commit is contained in:
parent
98bf8557d5
commit
af71f669a3
5 changed files with 104 additions and 7 deletions
|
|
@ -1,6 +1,7 @@
|
|||
"""Core tool transform functionality."""
|
||||
|
||||
import re
|
||||
from dataclasses import dataclass
|
||||
from typing import Annotated, Any
|
||||
|
||||
import pytest
|
||||
|
|
@ -722,6 +723,27 @@ async def test_transform_fn_wrapped_result_respects_serialize_by_alias():
|
|||
assert result.structured_content == {"result": {"id": "42"}}
|
||||
|
||||
|
||||
async def test_transform_fn_configured_dataclass_respects_serialize_by_alias():
|
||||
"""A transform uses its return annotation for nested dataclass serialization."""
|
||||
from pydantic import ConfigDict, with_config
|
||||
|
||||
@with_config(ConfigDict(serialize_by_alias=True))
|
||||
@dataclass
|
||||
class Item:
|
||||
id: Annotated[str, Field(serialization_alias="itemId")]
|
||||
|
||||
def base() -> None:
|
||||
pass
|
||||
|
||||
async def transform() -> list[Item]:
|
||||
return [Item(id="42")]
|
||||
|
||||
transformed = Tool.from_tool(base, transform_fn=transform)
|
||||
result = await transformed.run({})
|
||||
|
||||
assert result.structured_content == {"result": [{"itemId": "42"}]}
|
||||
|
||||
|
||||
class TestProxy:
|
||||
@pytest.fixture
|
||||
def mcp_server(self) -> FastMCP:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue