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 Vs Sync Loading

From Leeroopedia
Knowledge Sources
Domains Software_Architecture, Performance
Last Updated 2026-10-29 00:00 GMT

Overview

Design decision that trades blocking startup (wait for all backends before serving) for non-blocking startup (serve immediately, load backends in background) based on a configurable feature flag.

Description

Async vs Sync Loading addresses the startup-time tradeoff between correctness (all backends connected before the first request) and responsiveness (HTTP listener ready immediately, backends connect in background). In sync mode, the server blocks until every MCP backend connects or fails, guaranteeing a complete capability set on first request. In async mode, the HTTP server starts immediately and the loading manager connects backends in parallel, sending `listChanged` notifications as capabilities become available. A cooperative-activation startup policy can also force async mode even when the feature flag is off.

Usage

Use this principle when:

  • Startup latency must be minimized for user-facing runtimes
  • Some backends are slow to connect and should not block the entire startup
  • Clients can tolerate an initially incomplete capability set with incremental notifications
  • A cooperative runtime upgrade requires the replacement to activate without waiting for all backends

Theoretical Basis

The decision is a branch on a feature flag:

// Abstract decision (NOT real implementation)
const nonblocking = asyncLoading.enabled || startupPolicy === 'cooperative-activation';
const result = nonblocking
  ? await setupServerAsync(transports)  // HTTP starts now, backends load later
  : await setupServerSync(transports);   // Wait for all backends, then serve

In async mode, the loading promise is returned alongside the server manager:

Tstartupasync=Thttp_bindvsTstartupsync=Thttp_bind+max⁡(Tconnect_all)

Practical Guide

  1. Default to sync mode for predictable startup; make async opt-in via `--enable-async-loading`
  2. In async mode, create client manager storage without connecting, then start loading in background
  3. Return a `loadingPromise` that resolves when all initial connection attempts settle
  4. In sync mode, wait for `createClients` to finish before creating the server manager
  5. Both modes should support lazy loading as an orthogonal feature

Related Pages

Implemented By

Page Connections

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