GitHub

ServerProtocolService

API reference for ServerProtocolService.

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

AttributeTypeDescription
disconnectsQueue[int] = disconnects

The ids of the clients that left, as they leave.

supports_ackbool = supports_ack

Whether clients send an Ack after each stream chunk.

supports_span_propagationbool = supports_span_propagation

Whether requests carry their caller's span.

supports_notificationsbool = supports_notifications

Whether the server can write to a client unasked (an MCP server over it serves no subscriptions otherwise).

codec_forCodecFor

codec_for(schema): the codec filling the value holes of the messages for schema, the very function of the RpcSerialization behind this transport (encode caches compare it by identity).

initial_messageEffect[Option[object]]

The value a worker client sent first (rpc.worker.initial_message), waiting for it; None on the other transports. Never fails.

client_idsEffect[AbstractSet[int]] | None

The ids of the clients connected now (never fails), or None when the transport does not report them.

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
ParameterTypeDescription
runCallable[[WriteRequest], Effect[Never]]
disconnectsQueue[int]
sendCallable[[int, Message], Effect[None]]
endCallable[[int], Effect[None]]
supports_ackbool
supports_span_propagationbool
codec_forCodecFor
initial_messageEffect[Option[object]] = _NO_INITIAL_MESSAGE
supports_notificationsbool = True
client_idsEffect[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_ids

run

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.

ParameterTypeDescription
fWriteRequest

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).

ParameterTypeDescription
client_idint
responseMessage

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.

ParameterTypeDescription
client_idint

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)