Return an `OnRequest` callback that serves each call via `serve_one` with a fresh per-request `Connection`. Wire this into the server side of a `DirectDispatcher` peer-pair to drive an in-process server on the modern per-request-envelope path (each request carries protocol version, clie
(server: Server[LifespanT], lifespan_state: LifespanT)
| 497 | |
| 498 | |
| 499 | def modern_on_request(server: Server[LifespanT], lifespan_state: LifespanT) -> OnRequest: |
| 500 | """Return an `OnRequest` callback that serves each call via `serve_one` with a fresh per-request `Connection`. |
| 501 | |
| 502 | Wire this into the server side of a `DirectDispatcher` peer-pair to drive an |
| 503 | in-process server on the modern per-request-envelope path (each request |
| 504 | carries protocol version, client info, and capabilities in `params._meta`; |
| 505 | no `initialize` handshake). Like `serve_one`, this raises whatever the |
| 506 | handler chain raises - the dispatcher owns the exception-to-error mapping. |
| 507 | """ |
| 508 | |
| 509 | async def handle( |
| 510 | dctx: DispatchContext[TransportContext], method: str, params: Mapping[str, Any] | None |
| 511 | ) -> dict[str, Any]: |
| 512 | meta = (params or {}).get("_meta", {}) |
| 513 | connection = Connection.from_envelope( |
| 514 | meta.get(PROTOCOL_VERSION_META_KEY, LATEST_MODERN_VERSION), |
| 515 | meta.get(CLIENT_INFO_META_KEY), |
| 516 | meta.get(CLIENT_CAPABILITIES_META_KEY), |
| 517 | ) |
| 518 | return await serve_one(server, dctx, method, params, connection=connection, lifespan_state=lifespan_state) |
| 519 | |
| 520 | return handle |