A server transport (Effect's RpcServer.Protocol): run
hands each message of a client to the server, send and end
answer a client. with_run builds one from its parts.
Attributes#
| Attribute | Type | Description |
|---|---|---|
disconnects | Queue[int] = disconnects | The ids of the clients that left, as they leave. |
supports_ack | bool = supports_ack | Whether clients send an |
supports_span_propagation | bool = supports_span_propagation | Whether requests carry their caller's span. |
supports_notifications | bool = supports_notifications | Whether the server can write to a client unasked (an MCP server over it serves no subscriptions otherwise). |
codec_for | CodecFor |
|
initial_message | Effect[Option[object]] | The value a worker client sent first
( |
client_ids | Effect[AbstractSet[int]] | None | The ids of the clients connected now (never fails), or |
Functions#
__init__#
__init__(run, disconnects, send, end, supports_ack, supports_span_propagation, codec_for, initial_message=_NO_INITIAL_MESSAGE, supports_notifications=True, client_ids=None) -> None| Parameter | Type | Description |
|---|---|---|
run | Callable[[WriteRequest], Effect[Never]] | |
disconnects | Queue[int] | |
send | Callable[[int, Message], Effect[None]] | |
end | Callable[[int], Effect[None]] | |
supports_ack | bool | |
supports_span_propagation | bool | |
codec_for | CodecFor | |
initial_message | Effect[Option[object]] = _NO_INITIAL_MESSAGE | |
supports_notifications | bool = True | |
client_ids | Effect[AbstractSet[int]] | None = None |
def __init__( # noqa: PLR0917
self,
run: Callable[[WriteRequest], Effect[Never]],
disconnects: Queue[int],
send: Callable[[int, Message], Effect[None]],
end: Callable[[int], Effect[None]],
supports_ack: bool,
supports_span_propagation: bool,
codec_for: CodecFor,
initial_message: Effect[Option[object]] = _NO_INITIAL_MESSAGE,
supports_notifications: bool = True,
client_ids: Effect[AbstractSet[int]] | None = None,
) -> None:
self._run = run
self.disconnects = disconnects
self._send = send
self._end = end
self.supports_ack = supports_ack
self.supports_span_propagation = supports_span_propagation
self._codec_for = codec_for
self._initial_message = initial_message
self.supports_notifications = supports_notifications
self._client_ids = client_idsrun#
run(f) -> Effect[Never]Hands each encoded message to f with its client's id, until
interrupted (it never returns and never fails). Messages that
arrived before the server ran are handed over first.
| Parameter | Type | Description |
|---|---|---|
f | WriteRequest |
Returns Effect[Never]
def run(self, f: WriteRequest) -> Effect[Never]:
"""Hands each encoded message to ``f`` with its client's id, until
interrupted (it never returns and never fails). Messages that
arrived before the server ran are handed over first."""
return self._run(f)send#
send(client_id, response) -> Effect[None]Writes the encoded response to client_id; never fails
(the built-in transports drop it for a client that has left).
| Parameter | Type | Description |
|---|---|---|
client_id | int | |
response | Message |
Returns Effect[None]
def send(self, client_id: int, response: Message) -> Effect[None]:
"""Writes the encoded ``response`` to ``client_id``; never fails
(the built-in transports drop it for a client that has left)."""
return self._send(client_id, response)end#
end(client_id) -> Effect[None]Ends the responses to client_id: the HTTP transport closes
its response body and stdio its output; the socket and worker
transports do nothing. Never fails.
| Parameter | Type | Description |
|---|---|---|
client_id | int |
Returns Effect[None]
def end(self, client_id: int) -> Effect[None]:
"""Ends the responses to ``client_id``: the HTTP transport closes
its response body and stdio its output; the socket and worker
transports do nothing. Never fails."""
return self._end(client_id)