Implementation:1mcp app Agent PresetManager
| Knowledge Sources | |
|---|---|
| Domains | Configuration, Filtering |
| Last Updated | 2026-10-29 00:00 GMT |
Overview
Concrete singleton that manages MCP server filter presets with JSON file storage, debounced file watching, change detection, and client notification callbacks.
Description
The PresetManager class stores presets (named tag-query configurations) in a `presets.json` file within the config directory. It watches the file for external changes and reloads with a 500ms debounce. On reload, it compares each preset's resolved server list before and after to detect meaningful changes, then notifies registered callbacks. Presets can be created, validated, tested against current server configuration, and deleted. The tag query evaluator resolves preset criteria to a server list using AND/OR/NOT expressions.
Usage
Import this class when you need to:
- Initialize preset management at server startup with file watching
- Register callbacks for preset change notifications
- Create, validate, or delete presets programmatically
- Test a preset against current server configuration to see which servers match
- Resolve a preset name to a tag expression string for filtering
Code Reference
Source Location
- Repository: 1MCP Agent
- File: src/domains/preset/manager/presetManager.ts (L27-467)
Signature
export class PresetManager {
private static instance: PresetManager | null;
public static getInstance(configDirOption?: string): PresetManager;
public static resetInstance(): void;
public async initialize(): Promise<void>;
public async loadPresetsWithoutWatcher(): Promise<void>;
public async reloadFromStorage(): Promise<void>;
public async cleanup(): Promise<void>;
public onPresetChange(callback: (presetName: string) => Promise<void>): void;
public offPresetChange(callback: (presetName: string) => Promise<void>): void;
public async savePreset(name: string, config: Omit<PresetConfig, 'name' | 'created' | 'lastModified'>): Promise<void>;
public getPreset(name: string): PresetConfig | null;
public getPresetList(): PresetListItem[];
public async deletePreset(name: string): Promise<boolean>;
public hasPreset(name: string): boolean;
public getPresetNames(): string[];
public async validatePreset(name: string, config: Omit<PresetConfig, 'name' | 'created' | 'lastModified'>): Promise<PresetValidationResult>;
public resolvePresetToExpression(name: string): string | null;
public async testPreset(name: string): Promise<{ servers: string[]; tags: string[] }>;
}
Import
import { PresetManager } from '@src/domains/preset/manager/presetManager.js';
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| configDirOption | string | No | Config directory for preset storage |
| name | string | Yes | Preset name for CRUD operations |
| config | Omit<PresetConfig, ...> | Yes | Preset definition (tagQuery, strategy, description) |
Outputs
| Name | Type | Description |
|---|---|---|
| getPreset | null | Preset configuration or null if not found |
| testPreset | { servers, tags } | Matching servers and tags for a preset |
| onPresetChange | callback | Called when a preset's effective server list changes |
Usage Examples
Initialization with Notifications
import { PresetManager } from '@src/domains/preset/manager/presetManager.js';
import { PresetNotificationService } from '@src/domains/preset/services/presetNotificationService.js';
const presetManager = PresetManager.getInstance(configDir);
await presetManager.initialize();
const notificationService = PresetNotificationService.getInstance();
presetManager.onPresetChange(async (presetName) => {
await notificationService.notifyPresetChange(presetName);
});
Creating and Testing a Preset
await presetManager.savePreset('dev-only', {
description: 'Development servers only',
strategy: 'include',
tagQuery: { type: 'tag', tag: 'dev' },
});
const result = await presetManager.testPreset('dev-only');
console.log(result.servers); // ['server1', 'server2', ...]