Pairs held MCP tools/call control requests with the tool results Minga sends later.
When Claude Code calls a Minga tool, the bridge does not answer the control request. It holds the request here, keyed by the tool_use id from params._meta["claudecode/toolUseId"], and ends the Minga turn with the tool calls. The next Minga request carries the results; resolve/3 turns each result into the reply line for its held request.
The correlator is a pure value: tool_use_id => {control_request_id, jsonrpc_id}.
hold/2rejects atool_use_idthat is already held.resolve/3removes the id, so each held id resolves at most once. A second resolve, an id that was never held, and a resolve afterabort_all/1return{:error, :unknown_tool_use}. Resolve order does not matter.abort_all/1answers every held call with JSON-RPC error-32800(request cancelled) and returns an empty correlator.
The correlator does not remember resolved ids. A later hold/2 of an id that was resolved before is accepted; Claude Code assigns a new tool_use id to every call, so this does not happen in a valid session.
Tool results
A result is %{content: [part], is_error: boolean} where a part is {:text, text} or {:image, media_type, data} with data as raw bytes. It becomes the MCP CallToolResult: text parts become {"type": "text", "text": ...}, image parts become {"type": "image", "data": base64, "mimeType": ...}, and isError is set from is_error. Results are conversation content; do not log them.
Summary
Types
One call to hold: the ids needed to answer its control request later.
Functions
Answers every held call with JSON-RPC error -32800 and returns an empty correlator. Lines are ordered by tool_use_id.
Converts a tool result to an MCP CallToolResult map.
Holds a call until its result arrives. Rejects a tool_use_id that is already held.
Returns an empty correlator.
Returns the held tool_use ids in sorted order.
Answers the held call tool_use_id with result. Returns the control_response line to write and the correlator without that call.
Types
@type held() :: %{ tool_use_id: String.t(), control_request_id: String.t(), jsonrpc_id: MingaClaudeBridge.Wire.jsonrpc_id() }
One call to hold: the ids needed to answer its control request later.
@opaque t()
Functions
@spec abort_all(t()) :: {[MingaClaudeBridge.Wire.line()], t()}
Answers every held call with JSON-RPC error -32800 and returns an empty correlator. Lines are ordered by tool_use_id.
Converts a tool result to an MCP CallToolResult map.
Holds a call until its result arrives. Rejects a tool_use_id that is already held.
@spec new() :: t()
Returns an empty correlator.
Returns the held tool_use ids in sorted order.
@spec resolve(t(), String.t(), result()) :: {:ok, MingaClaudeBridge.Wire.line(), t()} | {:error, :unknown_tool_use}
Answers the held call tool_use_id with result. Returns the control_response line to write and the correlator without that call.