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

Implementation:1mcp app Agent AsyncLoadingOrchestrator

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

Overview

Concrete event-driven orchestrator that coordinates capability aggregation and client notifications after MCP server loading completes, wiring LoadingManager events to CapabilityAggregator and NotificationManager.

Description

The AsyncLoadingOrchestrator class bridges the loading manager's state transitions to the capability aggregation and notification pipeline. When the loading manager emits `LoadingComplete`, the orchestrator triggers a capability snapshot update via the CapabilityAggregator. If capabilities changed, it publishes the snapshot and sends `listChanged` notifications to connected clients. The orchestrator also initializes the internal capabilities provider and supports per-connection notification manager setup. It respects the `asyncLoading.enabled` feature flag and a `cooperative-activation` startup policy.

Usage

Import this class when you need to:

  • Wire loading completion to capability aggregation at server startup
  • Send `listChanged` notifications to clients when backends become ready
  • Force-refresh capabilities after a backend availability change
  • Initialize per-connection notification managers when inbound connections arrive

Code Reference

Source Location

  • Repository: 1MCP Agent
  • File: src/core/capabilities/asyncLoadingOrchestrator.ts (L37-360)

Signature

export type BackendStartupPolicy = 'configured' | 'cooperative-activation';

export class AsyncLoadingOrchestrator extends EventEmitter {
  constructor(
    outboundConnections: OutboundConnections,
    serverManager: ServerManager,
    loadingManager: McpLoadingManager,
  );

  public async initialize(startupPolicy?: BackendStartupPolicy): Promise<void>;
  public initializeNotifications(inboundConnection: InboundConnection): void;

  public async refreshCapabilities(): Promise<CapabilityRefreshResult>;
  public getCapabilityAggregator(): CapabilityAggregator;
  public getNotificationManager(): NotificationManager | null;
  public isReady(): boolean;
  public getStatusSummary(): string;
  public updateConfig(): void;
  public shutdown(): void;
}

Import

import { AsyncLoadingOrchestrator, BackendStartupPolicy } from '@src/core/capabilities/asyncLoadingOrchestrator.js';

I/O Contract

Inputs

Name Type Required Description
outboundConnections OutboundConnections Yes Connected MCP backends
serverManager ServerManager Yes Server manager facade
loadingManager McpLoadingManager Yes Loading manager to observe
startupPolicy BackendStartupPolicy No 'configured' or 'cooperative-activation'

Outputs

Name Type Description
refreshCapabilities CapabilityRefreshResult { changed, shouldNotifyListChanged }
AsyncLoadingOrchestratorEvent enum OrchestratorReady, CapabilitySnapshotPublished, NotificationsSent

Usage Examples

Wiring at Startup

import { AsyncLoadingOrchestrator } from '@src/core/capabilities/asyncLoadingOrchestrator.js';

const asyncOrchestrator = new AsyncLoadingOrchestrator(clients, serverManager, loadingManager);
await asyncOrchestrator.initialize('configured');

// Later, when an inbound connection arrives:
asyncOrchestrator.initializeNotifications(inboundConnection);

Manual Capability Refresh

const result = await asyncOrchestrator.refreshCapabilities();
if (result.changed) {
  console.log('Capabilities updated, listChanged sent to clients');
}

Related Pages

Implements Principle

Page Connections

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