The operations.py module#

Summary#

CallCoordinator

Join, shield and replay mutating tool calls for one server.

call_key

Return the identity of a call: tool name plus its JSON-serializable arguments.

REPLAY_TTL_S

Seconds a finished idempotent result stays available to an identical retry.

Description#

Make long-running mutating tool calls survive host timeouts.

Component activation, case loading and solver runs often outlast an MCP host’s request timeout. The host then cancels the call and usually retries, which interrupts the work and starts it a second time. CallCoordinator:

  • shields the running work from client cancellation so it completes;

  • lets a retry with identical arguments join the call that is still running;

  • replays, once and within replay_ttl_s, the result of an idempotent call that finished after the host gave up. Any other mutating call clears the replay cache, so a replay never hides a state change made in between.

Nothing is ever undone.

Module detail#

operations.call_key(tool: str, kwargs: dict[str, Any]) → tuple[str, str]#

Return the identity of a call: tool name plus its JSON-serializable arguments.

Arguments that cannot be serialized (for example an injected request context) are left out, so they never make identical calls look different.

Parameters:
toolstr

Tool name.

kwargsdict[str, Any]

Keyword arguments of the call.

Returns:
tuple[str, str]

Hashable call identity.

operations.REPLAY_TTL_S = 300.0#

Seconds a finished idempotent result stays available to an identical retry.