Add by_alias to wire-crossing model_dump calls

This commit is contained in:
Jeremiah Lowin 2026-07-05 18:14:32 -04:00
commit 1f319df0c3
No known key found for this signature in database
5 changed files with 10 additions and 5 deletions

View file

@ -1221,7 +1221,7 @@ async def _list_tools(mcp_url: str) -> list[dict[str, Any]]:
async with ClientSession(read, write) as session:
await session.initialize()
result = await session.list_tools()
return [t.model_dump() for t in result.tools]
return [t.model_dump(by_alias=True) for t in result.tools]
except Exception as exc:
logger.debug(f"Could not list tools from {mcp_url}: {exc}")
return []

View file

@ -161,7 +161,7 @@ class EventStore(SDKEventStore):
entry = EventEntry(
event_id=event_id,
stream_id=stream_id,
message=message.model_dump(mode="json") if message else None,
message=message.model_dump(mode="json", by_alias=True) if message else None,
)
await self._event_store.put(key=event_id, value=entry, ttl=self._ttl)

View file

@ -204,7 +204,9 @@ class ProxyTool(Tool):
if task_metadata:
meta = meta or {}
meta["modelcontextprotocol.io/task"] = (
task_metadata.model_dump(exclude_none=True)
task_metadata.model_dump(
by_alias=True, exclude_none=True
)
)
result = await client.call_tool_mcp(

View file

@ -157,7 +157,9 @@ def _format_prompt_result(result: Any) -> str:
if isinstance(msg.content, TextContent):
content = msg.content.text
else:
content = msg.content.model_dump(mode="json", exclude_none=True)
content = msg.content.model_dump(
mode="json", by_alias=True, exclude_none=True
)
messages.append(
{

View file

@ -60,7 +60,8 @@ def _extract_searchable_text(tool: Tool) -> str:
def serialize_tools_for_output_json(tools: Sequence[Tool]) -> list[dict[str, Any]]:
"""Serialize tools to the same dict format as ``list_tools`` output."""
return [
tool.to_mcp_tool().model_dump(mode="json", exclude_none=True) for tool in tools
tool.to_mcp_tool().model_dump(mode="json", by_alias=True, exclude_none=True)
for tool in tools
]