Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Principle:1mcp app Agent Async MCP Loading

From Leeroopedia
Knowledge Sources
Domains Concurrency, Reliability
Last Updated 2026-10-29 00:00 GMT

Overview

Pattern that coordinates parallel MCP server initialization with concurrency limits, retry with exponential backoff, OAuth-aware error handling, and background retry for failed servers.

Description

Async MCP Loading manages the non-blocking initialization of multiple MCP backends. It uses a parallel executor with a configurable concurrency limit to avoid overwhelming the system, tracks per-server loading state (pending, loading, ready, failed, awaiting-oauth, cancelled), and retries failed connections with exponential backoff. After the initial loading wave completes, a background retry timer periodically attempts to reconnect servers that remain in a failed state. The loading manager emits events at each state transition, enabling the async loading orchestrator to publish capability snapshots and notify clients.

Usage

Use this principle when:

  • Multiple MCP backends must connect in parallel without blocking the HTTP server
  • Failed backends should be retried with backoff rather than abandoned
  • OAuth-required errors must be handled distinctly from connection failures
  • Background retry should periodically attempt recovery of persistently failed servers
  • Loading operations must be cancellable for hot-reload (add/remove) without race conditions

Theoretical Basis

The loading wave uses bounded parallel execution:

load(S)=⋃s∈SloadSingle(s)with |active|≤maxConcurrent

Retry follows exponential backoff:

delay(retryCount)=retryDelayMs×2retryCount−1

Background retry is an idempotent interval:

// Abstract algorithm (NOT real implementation)
setInterval(() => {
  failed = stateTracker.getByState('failed')
    .filter(s => !(s.error instanceof NonRetryableError));
  retry(failed.slice(0, maxPerCycle));
}, backgroundRetryIntervalMs);

Practical Guide

  1. Track loading state per server with a state tracker that emits progress events
  2. Use per-server abort controllers to cancel loading operations during hot-reload
  3. Distinguish OAuth-required errors from retryable connection errors
  4. Cap background retry attempts per cycle to avoid overwhelming slow backends
  5. Reset the retry attempt counter after a stable period to allow transient failures to recover

Related Pages

Implemented By

Uses Heuristics

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment