|
10 | 10 | from dataclasses import field, replace |
11 | 11 | from datetime import timedelta |
12 | 12 | from pathlib import Path |
13 | | -from typing import Annotated, Any |
| 13 | +from typing import Annotated, Any, overload |
14 | 14 |
|
15 | 15 | import anyio |
16 | 16 | import httpx |
@@ -320,18 +320,29 @@ async def list_resource_templates(self) -> list[_mcp.ResourceTemplate]: |
320 | 320 | result = await self._client.list_resource_templates() |
321 | 321 | return [_mcp.map_from_mcp_resource_template(t) for t in result.resourceTemplates] |
322 | 322 |
|
323 | | - async def read_resource(self, uri: str) -> str | messages.BinaryContent | list[str | messages.BinaryContent]: |
| 323 | + @overload |
| 324 | + async def read_resource(self, uri: str) -> str | messages.BinaryContent | list[str | messages.BinaryContent]: ... |
| 325 | + |
| 326 | + @overload |
| 327 | + async def read_resource( |
| 328 | + self, uri: _mcp.Resource |
| 329 | + ) -> str | messages.BinaryContent | list[str | messages.BinaryContent]: ... |
| 330 | + |
| 331 | + async def read_resource( |
| 332 | + self, uri: str | _mcp.Resource |
| 333 | + ) -> str | messages.BinaryContent | list[str | messages.BinaryContent]: |
324 | 334 | """Read the contents of a specific resource by URI. |
325 | 335 |
|
326 | 336 | Args: |
327 | | - uri: The URI of the resource to read. |
| 337 | + uri: The URI of the resource to read, or a Resource object. |
328 | 338 |
|
329 | 339 | Returns: |
330 | 340 | The resource contents. If the resource has a single content item, returns that item directly. |
331 | 341 | If the resource has multiple content items, returns a list of items. |
332 | 342 | """ |
| 343 | + resource_uri = uri if isinstance(uri, str) else uri.uri |
333 | 344 | async with self: # Ensure server is running |
334 | | - result = await self._client.read_resource(AnyUrl(uri)) |
| 345 | + result = await self._client.read_resource(AnyUrl(resource_uri)) |
335 | 346 | return ( |
336 | 347 | self._get_content(result.contents[0]) |
337 | 348 | if len(result.contents) == 1 |
|
0 commit comments