Skip to content

Commit c5b3b57

Browse files
committed
fix: Added no cover pragma with TODO notes until FastMCP is updated to version 2.13.1
to be able to write more exhaustive tests for `meta` `ToolResult` in the MCP server.
1 parent 137126a commit c5b3b57

File tree

1 file changed

+9
-3
lines changed
  • pydantic_ai_slim/pydantic_ai

1 file changed

+9
-3
lines changed

pydantic_ai_slim/pydantic_ai/mcp.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,10 @@ async def direct_call_tool(
290290
else:
291291
user_contents.append(part)
292292

293-
if len(parts_metadata) > 0:
293+
# The following branching cannot be tested until FastMCP is updated to version 2.13.1
294+
# such that the MCP server can generate ToolResult and result.meta can be specified.
295+
# TODO: Add tests for the following branching once FastMCP is updated.
296+
if len(parts_metadata) > 0: # pragma: no cover
294297
if result.meta is not None and len(result.meta) > 0:
295298
# Merge the tool result metadata and parts metadata into the return metadata
296299
return_metadata = {'result': result.meta, 'content': parts_metadata}
@@ -301,7 +304,7 @@ async def direct_call_tool(
301304
return_metadata = parts_metadata[0]
302305
else:
303306
return_metadata = {'content': parts_metadata}
304-
else:
307+
else: # pragma: no cover
305308
if result.meta is not None and len(result.meta) > 0:
306309
return_metadata = result.meta
307310
# TODO: What else should we cover here?
@@ -450,7 +453,10 @@ async def _map_tool_result_part(
450453
return messages.BinaryContent(data=base64.b64decode(part.data), media_type=part.mimeType), metadata
451454
elif isinstance(part, mcp_types.EmbeddedResource):
452455
return self._get_content(part.resource), metadata
453-
elif isinstance(part, mcp_types.ResourceLink):
456+
# The following branching cannot be tested until FastMCP is updated to version 2.13.1
457+
# such that the MCP server can generate ToolResult and result.meta can be specified.
458+
# TODO: Add tests for the following branching once FastMCP is updated.
459+
elif isinstance(part, mcp_types.ResourceLink): # pragma: no cover
454460
resource_result: mcp_types.ReadResourceResult = await self._client.read_resource(part.uri)
455461
# Check if metadata already exists. If so, merge it with nested the resource metadata.
456462
parts_metadata: dict[int, dict[str, Any]] = {}

0 commit comments

Comments
 (0)