Forget a request we noted but then dropped, so its entry does not leak (the response will never arrive to clear it). No-op for non-requests.
Record an outgoing request's id->method mapping, keyed by the direction the request itself travelled. Reaps expired/overflowing orphans first so the map stays bounded in a long session.
Resolve the originating method for a response/error by its id. The request it answers flowed the opposite direction, so look there. An entry that has already passed its TTL is treated as absent (the response arrived too late to be trusted) and cleared.
Current number of tracked in-flight requests (for tests / introspection).
Tracks in-flight requests so responses (which carry no
methodon the wire) can be tagged with the method that produced them. Without this, rules and the UI cannot say "this is the tools/call result".MCP is bidirectional: the client issues requests (tools/call, tools/list, …) and the server issues requests back (sampling/createMessage, roots/list, elicitation/create) whose replies travel the other way. The two id-spaces are independent and collide (both start at 1), so the in-flight map is keyed by
(request-direction, id).Entries are normally cleared the instant their response is correlated. But a dropped request, a crashed peer, or a server that simply never replies would otherwise leak an entry forever — unbounded growth over a long session. A TTL + size cap reap those orphans without ever disturbing a normally-timed round trip. The
Mappreserves insertion order, which (since each entry'stsis stamped at insertion) is also oldest-first order, so both evictors can scan/trim from the front.