|
6 | 6 | from functools import reduce |
7 | 7 | from operator import or_ |
8 | 8 | from types import TracebackType |
9 | | -from typing import Annotated, Any, Final, Literal, Protocol, cast, overload |
| 9 | +from typing import Annotated, Any, Final, Literal, Protocol, TypeAlias, cast, overload |
10 | 10 |
|
11 | 11 | import anyio |
12 | 12 | import anyio.abc |
|
53 | 53 | ) |
54 | 54 | from mcp.shared.jsonrpc_dispatcher import JSONRPCDispatcher, cancelled_request_id_from_params |
55 | 55 | from mcp.shared.message import ClientMessageMetadata, SessionMessage |
56 | | -from mcp.shared.session import RequestResponder |
57 | 56 | from mcp.shared.subscriptions import SUBSCRIPTION_ID_META_KEY, event_from_wire |
58 | 57 | from mcp.shared.transport_context import TransportContext |
59 | 58 |
|
@@ -172,16 +171,15 @@ class LoggingFnT(Protocol): |
172 | 171 | async def __call__(self, params: types.LoggingMessageNotificationParams) -> None: ... # pragma: no branch |
173 | 172 |
|
174 | 173 |
|
| 174 | +IncomingMessage: TypeAlias = types.ServerNotification | Exception |
| 175 | +"""What `message_handler` receives: every server notification, plus transport-level exceptions.""" |
| 176 | + |
| 177 | + |
175 | 178 | class MessageHandlerFnT(Protocol): |
176 | | - async def __call__( |
177 | | - self, |
178 | | - message: RequestResponder[types.ServerRequest, types.ClientResult] | types.ServerNotification | Exception, |
179 | | - ) -> None: ... # pragma: no branch |
| 179 | + async def __call__(self, message: IncomingMessage) -> None: ... # pragma: no branch |
180 | 180 |
|
181 | 181 |
|
182 | | -async def _default_message_handler( |
183 | | - message: RequestResponder[types.ServerRequest, types.ClientResult] | types.ServerNotification | Exception, |
184 | | -) -> None: |
| 182 | +async def _default_message_handler(message: IncomingMessage) -> None: |
185 | 183 | await anyio.lowlevel.checkpoint() |
186 | 184 |
|
187 | 185 |
|
|
0 commit comments