|
1 | 1 | from __future__ import annotations |
2 | 2 |
|
3 | 3 | from collections.abc import Iterable, Mapping |
4 | | -from typing import TYPE_CHECKING, Any, Generic, Literal, cast, overload |
| 4 | +from typing import TYPE_CHECKING, Any, Generic, cast |
5 | 5 |
|
6 | 6 | from mcp_types import ClientCapabilities, InputRequiredResult, InputResponseRequestParams, InputResponses, LoggingLevel |
7 | 7 | from pydantic import AnyUrl, BaseModel |
@@ -99,47 +99,31 @@ async def report_progress(self, progress: float, total: float | None = None, mes |
99 | 99 | """ |
100 | 100 | await self.request_context.session.report_progress(progress, total, message) |
101 | 101 |
|
102 | | - @overload |
103 | | - async def read_resource( |
104 | | - self, uri: str | AnyUrl, *, allow_input_required: Literal[False] = False |
105 | | - ) -> Iterable[ReadResourceContents]: ... |
106 | | - |
107 | | - @overload |
108 | | - async def read_resource( |
109 | | - self, uri: str | AnyUrl, *, allow_input_required: bool |
110 | | - ) -> Iterable[ReadResourceContents] | InputRequiredResult: ... |
111 | | - |
112 | | - async def read_resource( |
113 | | - self, uri: str | AnyUrl, *, allow_input_required: bool = False |
114 | | - ) -> Iterable[ReadResourceContents] | InputRequiredResult: |
| 102 | + async def read_resource(self, uri: str | AnyUrl) -> Iterable[ReadResourceContents]: |
115 | 103 | """Read a resource by URI. |
116 | 104 |
|
| 105 | + This is a content reader: an `InputRequiredResult` returned by a |
| 106 | + resource template function (the 2026-07-28 multi-round-trip flow) |
| 107 | + raises here. A handler that wants to receive and forward one as its |
| 108 | + own result calls `MCPServer.read_resource(uri, context)` instead. |
| 109 | +
|
117 | 110 | Args: |
118 | 111 | uri: Resource URI to read |
119 | | - allow_input_required: When `False` (default), an |
120 | | - `InputRequiredResult` returned by a resource template function |
121 | | - (the 2026-07-28 multi-round-trip flow) raises instead of being |
122 | | - returned. Pass `True` to receive it — a handler may forward it |
123 | | - as its own result; the retry's answers then arrive on |
124 | | - `ctx.input_responses`. |
125 | 112 |
|
126 | 113 | Returns: |
127 | | - The resource content as either text or bytes, or — only with |
128 | | - `allow_input_required=True` — the `InputRequiredResult` the |
129 | | - resource template function returned. |
| 114 | + The resource content as either text or bytes |
130 | 115 |
|
131 | 116 | Raises: |
132 | 117 | ResourceNotFoundError: If no resource or template matches the URI. |
133 | 118 | ResourceError: If template creation or resource reading fails. |
134 | | - RuntimeError: If the resource returned an `InputRequiredResult` |
135 | | - and `allow_input_required` is `False`. |
| 119 | + RuntimeError: If the resource returned an `InputRequiredResult`. |
136 | 120 | """ |
137 | 121 | assert self._mcp_server is not None, "Context is not available outside of a request" |
138 | 122 | result = await self._mcp_server.read_resource(uri, self) |
139 | | - if isinstance(result, InputRequiredResult) and not allow_input_required: |
| 123 | + if isinstance(result, InputRequiredResult): |
140 | 124 | raise RuntimeError( |
141 | | - "Resource returned InputRequiredResult; pass allow_input_required=True to " |
142 | | - "receive it and forward it as this handler's result." |
| 125 | + "Resource returned InputRequiredResult; ctx.read_resource() only returns " |
| 126 | + "content — use MCPServer.read_resource(uri, context) to receive and forward it." |
143 | 127 | ) |
144 | 128 | return result |
145 | 129 |
|
|
0 commit comments