Expand description
Turning a decoded envelope into a method to dispatch, without naming one.
§The trait is the seam, and it is monomorphised on purpose
MethodTable knows a method’s name and can turn its raw params into a
typed value, but it is declared by the consumer and implemented by whichever
protocol module is in play. Nothing here mentions tools/call or
initialize; that is the whole point of the split, and it is what lets T27
and T29 add A2A and ACP without touching a line of this file.
The trait is generic over its own MethodId and its own decoded params
rather than erasing them to Box<dyn Debug>. Erasing would put a heap
allocation on the path this whole layer exists to keep allocation-free, and
it would throw away the type the caller needed before anything could be
dispatched. The associated types are what “consumed through impl MethodTable so it monomorphises” means in practice.
§Three type parameters, because a reply carries nothing
Routed has one type parameter per arm that holds a value: the request
params, the notification params, and nothing for the reply. A single
parameter would mean either erasing the two params types into one or
manufacturing a value the reply arm never reads, and both are worse than
carrying the third type. It is the same argument as not erasing to
Box<dyn Debug>, applied to the reply case.
§Where an error is raised
A method that is not in the table is -32601 and a params shape that does
not fit is -32602 — both decided here, from the same code, whether the
table is MCP’s or A2A’s. The message is the only part a protocol supplies.
That is the difference between “route” and “dispatch”, and keeping the seam
between them is what lets a later task fill in the second half without
rewriting the first.
Enums§
- Reply
Payload - The undecoded half of a reply.
- Route
Error - Why a frame was refused.
- Routed
- A routed message: the method it names and its params, already typed.
Traits§
- Method
Table - The set of methods one protocol speaks, and how to decode each one’s params.
Functions§
- route_
frame - Decodes a frame and routes every message in it, refusing a batch when
policysays this session does not accept one. - route_
one - Routes one message, decoding its params into the table’s own types.
Type Aliases§
- Routed
Frame - What a routed frame contains, for one table.
- Routed
Message - The same, for a single message.