Anubis. Server. Transport. Session behaviour
(anubis_mcp v1.14.0)
Copy Markdown
Public contract between server transports and session processes.
Transports never talk to Anubis.Server.Session internals directly. Every
client message flows through a session dispatcher implementing this
behaviour, so the delivery mechanism can be swapped without touching
transport code (for example, to route sessions across a cluster).
Wire protocol
The default dispatcher (Anubis.Server.Transport.Session.Local) delivers
messages to the session process with these shapes, which are part of the
public contract and handled by Anubis.Server.Session:
{:mcp_request, message, context}— synchronousGenServer.call/3. The session replies{:ok, binary() | nil}with the JSON-encoded response (nilwhen no response body is due), or{:error, term()}.{:mcp_notification, message, context}— asynchronousGenServer.cast/2for client notifications.{:mcp_response, message, context}— asynchronousGenServer.cast/2for client responses to server-initiated requests (sampling, roots, elicitation).
Transport context
The context is a map carrying request metadata from the transport to the
session. Keys are transport-specific; the ones consumed by
Anubis.Server.Session are:
:assigns— map merged into the frame assigns:req_headers— HTTP request headers, exposed on the context:remote_ip— client IP, exposed on the context:auth— validated auth claims, exposed on the context
Transports may add any other keys (e.g. :type, :query_params); sessions
ignore unknown keys.
Swapping the dispatcher
All dispatch functions on this module delegate to the configured adapter,
which defaults to Anubis.Server.Transport.Session.Local:
config :anubis_mcp, :session_dispatcher, MyApp.ClusterDispatcherA custom dispatcher must implement this behaviour. It receives the same
session/0 reference transports already resolved, so a cluster-aware
implementation can encode routing information in a :via tuple or resolve
the owning node from the session id carried in the context/0.
Summary
Types
Transport context map. See the module documentation for known keys.
A decoded JSON-RPC message (map with string keys).
Wire shape for client notifications delivered to a session.
Reply expected from a dispatched request.
Wire shape for client requests delivered to a session.
Wire shape for client responses delivered to a session.
A reference to a session process, as resolved by the transport.
Callbacks
Delivers a client notification to the session.
Delivers a client request to the session and returns its reply.
Delivers a client response (to a server-initiated request) to the session.
Functions
Dispatches a client notification through the configured dispatcher.
Dispatches a client request through the configured dispatcher.
Dispatches a client response through the configured dispatcher.
Types
Transport context map. See the module documentation for known keys.
A decoded JSON-RPC message (map with string keys).
Wire shape for client notifications delivered to a session.
Reply expected from a dispatched request.
Wire shape for client requests delivered to a session.
Wire shape for client responses delivered to a session.
@type session() :: GenServer.server()
A reference to a session process, as resolved by the transport.
Callbacks
Delivers a client notification to the session.
@callback dispatch_request(session(), message(), context(), opts) :: request_reply() when opts: [{:timeout, timeout()}]
Delivers a client request to the session and returns its reply.
Supported options:
:timeout— how long to wait for the session reply (default: 5000)
Delivers a client response (to a server-initiated request) to the session.
Functions
Dispatches a client notification through the configured dispatcher.
@spec dispatch_request(session(), message(), context(), keyword()) :: request_reply()
Dispatches a client request through the configured dispatcher.
See dispatch_request/4.
Dispatches a client response through the configured dispatcher.
See dispatch_response/3.