Module: MCPClient::RequestMetaScope

Included in:
ServerHTTP, ServerSSE, ServerStdio, ServerStreamableHTTP
Defined in:
lib/mcp_client/request_meta_scope.rb

Overview

The operations a transport may make a cache decision for, each wrapped in a scope that reserves the evaluation of the host's request_meta for the request the operation leads to (MCP 2026-07-28 server/utilities/caching: a decision is weighed on the parameters the request will carry, and a host callable that vends a one-time value is read once for the two).

Prepended to the transports, so the reservation is a property of the operation rather than of any path through it:

  • it is adopted only by the operation it was opened for, which the opener hands it to by name (MCPClient::RequestMetadata#offer_request_meta_hold); an operation that merely uses the same method reserves its own;
  • it is spent by the request the operation sends and by nothing else -- a reconnect's handshake, the subscriptions/listen a reconnect re-opens, a notifications/cancelled for an abandoned request, and every request host code issues from behind the boundary the transport crosses to reach it -- a nested list, a raw rpc_request or fetch_prompts_list of the very method the operation holds -- all read the host afresh (JsonRpcCommon#request_meta_claim);
  • it never outlives the operation, whichever way that ends -- a value returned, a reconnect or an initialization that raised, an error a caller swallowed -- because the scope drops it from an ensure.

Constant Summary collapse

SCOPED_OPERATIONS =

Each operation and the JSON-RPC method of the request it leads to.

{
  list_tools: 'tools/list',
  list_prompts: 'prompts/list',
  list_resources: 'resources/list',
  list_resource_templates: 'resources/templates/list',
  read_resource: 'resources/read',
  get_prompt: 'prompts/get',
  call_tool: 'tools/call'
}.freeze
HOST_CALLBACKS =

Where a transport hands control to host code: a notification listener (and, through it, a subscription's listeners and the client's own dispatch) and a handler for a server-initiated request. Whatever that code asks of the transport is an operation of its own -- a raw rpc_request, a send_rpc, a public fetch_prompts_list, a nested list -- so it never reaches the reservation the operation it interrupted is holding, whatever method it names. A tools/call it issues records the definition it goes out under into a slot of its own for the same reason (CalledToolDefinition): the call whose response is still being parsed keeps its own.

i[route_notification handle_server_request].freeze