-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Expand file tree
/
Copy pathtransport_context.py
More file actions
30 lines (21 loc) · 1.06 KB
/
transport_context.py
File metadata and controls
30 lines (21 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
"""Transport-specific metadata attached to each inbound message.
`TransportContext` is the base; each transport defines its own subclass with
whatever fields make sense (HTTP request id, ASGI scope, stdio process handle,
etc.). The dispatcher passes it through opaquely; only the layers above the
dispatcher (`ServerRunner`, `Context`, user handlers) read its concrete fields.
"""
from dataclasses import dataclass
__all__ = ["TransportContext"]
@dataclass(kw_only=True, frozen=True)
class TransportContext:
"""Base transport metadata for an inbound message.
Subclass per transport and add fields as needed. Instances are immutable.
"""
kind: str
"""Short identifier for the transport (e.g. ``"stdio"``, ``"streamable-http"``)."""
can_send_request: bool
"""Whether the transport can deliver server-initiated requests to the peer.
``False`` for stateless HTTP and HTTP with JSON response mode; ``True`` for
stdio, SSE, and stateful streamable HTTP. When ``False``,
`DispatchContext.send_request` raises `NoBackChannelError`.
"""