Skip to content

Commit 2445540

Browse files
committed
Make error handing in MCP ResourceLink reading consistent.
1 parent 278d141 commit 2445540

File tree

1 file changed

+5
-2
lines changed
  • pydantic_ai_slim/pydantic_ai

1 file changed

+5
-2
lines changed

pydantic_ai_slim/pydantic_ai/mcp.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -627,8 +627,11 @@ async def _map_tool_result_part(
627627
return self._get_content(resource)
628628
elif isinstance(part, mcp_types.ResourceLink):
629629
result = await self.read_resource(str(part.uri))
630-
# If resource not found, return an empty string as it's impossible to fetch anyway
631-
return result if result is not None else ''
630+
# Rather than hide an invalid resource link, we raise an error so it's consistent with any
631+
# other error that could happen during resource reading.
632+
if result is None:
633+
raise MCPError(message=f'Invalid ResourceLink {part.uri} returned by tool', code=-32002)
634+
return result
632635
else:
633636
assert_never(part)
634637

0 commit comments

Comments
 (0)