Serve a single connection over the given streams until the read side closes. Thin wrapper over `serve_loop`: enters the server lifespan, then drives the loop. Transports with their own lifespan owner (the streamable-HTTP manager) call `serve_loop` directly instead.
(
self,
read_stream: ReadStream[SessionMessage | Exception],
write_stream: WriteStream[SessionMessage],
initialization_options: InitializationOptions,
# When False, exceptions are returned as messages to the client.
# When True, exceptions are raised, which will cause the server to shut down
# but also make tracing exceptions much easier during testing and when using
# in-process servers.
raise_exceptions: bool = False,
)
| 433 | return self._session_manager |
| 434 | |
| 435 | async def run( |
| 436 | self, |
| 437 | read_stream: ReadStream[SessionMessage | Exception], |
| 438 | write_stream: WriteStream[SessionMessage], |
| 439 | initialization_options: InitializationOptions, |
| 440 | # When False, exceptions are returned as messages to the client. |
| 441 | # When True, exceptions are raised, which will cause the server to shut down |
| 442 | # but also make tracing exceptions much easier during testing and when using |
| 443 | # in-process servers. |
| 444 | raise_exceptions: bool = False, |
| 445 | ) -> None: |
| 446 | """Serve a single connection over the given streams until the read side closes. |
| 447 | |
| 448 | Thin wrapper over `serve_loop`: enters the server lifespan, |
| 449 | then drives the loop. Transports with their own lifespan owner |
| 450 | (the streamable-HTTP manager) call `serve_loop` directly instead. |
| 451 | """ |
| 452 | async with self.lifespan(self) as lifespan_context: |
| 453 | await serve_loop( |
| 454 | self, |
| 455 | read_stream, |
| 456 | write_stream, |
| 457 | lifespan_state=lifespan_context, |
| 458 | init_options=initialization_options, |
| 459 | raise_exceptions=raise_exceptions, |
| 460 | ) |
| 461 | |
| 462 | def streamable_http_app( |
| 463 | self, |