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 ConfigChangeHandler

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

Overview

Concrete singleton change handler that listens to ConfigManager events and applies business logic—starting, stopping, or modifying MCP servers—in response to configuration changes.

Description

The ConfigChangeHandler class registers as an observer on the ConfigManager's `CONFIG_CHANGED` and `RUNTIME_ENVIRONMENT_CHANGED` events. When configuration changes are detected, it determines whether each change requires a server restart (functional fields like `command`, `url`, `type`) or only a metadata update (non-functional fields like `tags`, `instructionOverride`). It routes through ServerManager's hot-reload facade (`loadMcpServer`, `unloadMcpServer`) so all changes use the canonical loading pipeline. It also reconciles declared templates, refreshes runtime instruction configuration, and sends `listChanged` notifications to connected clients when capabilities change.

Usage

Import this class when you need to:

  • Wire configuration change events to server lifecycle actions at startup
  • Determine if a config change requires a server restart or just metadata update
  • Send capability change notifications to clients after hot-reload
  • Reconcile template index and instruction configuration after config changes

Code Reference

Source Location

  • Repository: 1MCP Agent
  • File: src/core/configChangeHandler.ts (L16-445)

Signature

export class ConfigChangeHandler {
  private static instance: ConfigChangeHandler;

  public static getInstance(configManager?: ConfigManager): ConfigChangeHandler;

  public async initialize(): Promise<void>;
  public async stop(): Promise<void>;
}

Import

import { ConfigChangeHandler } from '@src/core/configChangeHandler.js';

I/O Contract

Inputs

Name Type Required Description
configManager ConfigManager No ConfigManager instance to observe

Outputs

Name Type Description
Server lifecycle actions void (side effects) Calls ServerManager.loadMcpServer/unloadMcpServer
listChanged notifications void (side effects) Notifies inbound clients of capability changes

Usage Examples

Basic Initialization

import { ConfigManager } from '@src/config/configManager.js';
import { ConfigChangeHandler } from '@src/core/configChangeHandler.js';

const configManager = ConfigManager.getInstance('/path/to/config.json');
await configManager.initialize();

const changeHandler = ConfigChangeHandler.getInstance(configManager);
await changeHandler.initialize();

// ConfigChangeHandler now listens for CONFIG_CHANGED events
// and will start/stop/modify servers automatically

Related Pages

Implements Principle

Page Connections

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