interfaces.tsโข3.93 kB
/**
* Database interfaces for server and group management
* These interfaces provide abstraction over the underlying database implementation
*/
import { ServerConfig } from "../types/config.js";
/**
* Represents a configuration source (where configs are imported from)
* Stored in the 'configSources' collection.
*/
export interface IConfigSource {
id: string; // Unique ID generated by the DB layer
type: "global" | "app" | "profile"; // Type of configuration source
appId?: string; // Application ID if type is 'app' or 'profile'
profileId?: string; // Profile ID if type is 'profile'
path: string; // Original file path for reference
priority: number; // For conflict resolution (higher = higher priority)
lastSynced: number; // Unix timestamp of last sync
}
/**
* Represents a canonical, internally managed MCP server configuration record.
* Stored in the 'servers' collection.
*/
export interface ServerConfigRecord {
id: string; // Unique ID generated by the DB layer (e.g., UUID)
name: string; // User-defined name from mcp.json
type: "stdio" | "http" | "sse";
config: ServerConfig; // The actual server configuration object
lastModified: number; // Unix timestamp
checksum: string; // Checksum of the config for change detection
sourceId?: string; // Reference to IConfigSource.id
}
/**
* Represents a named, user-defined collection of ServerConfigRecord IDs.
* Stored in the 'groups' collection.
*/
export interface ServerConfigGroup {
id: string; // Unique ID generated by the DB layer
name: string; // User-defined group name (unique)
description?: string; // Optional description
serverIds: string[]; // Array of ServerConfigRecord.id strings
}
/**
* Interface for interacting with ServerConfigRecord data.
*/
export interface IServerConfigRecordRepository {
add(server: Omit<ServerConfigRecord, "id">): Promise<ServerConfigRecord>;
update(server: ServerConfigRecord): Promise<ServerConfigRecord | null>;
delete(id: string): Promise<boolean>;
findById(id: string): Promise<ServerConfigRecord | null>;
findByName(name: string): Promise<ServerConfigRecord | null>;
findAll(): Promise<ServerConfigRecord[]>;
// Additional query methods can be added as needed (e.g., findByType)
}
/**
* Interface for interacting with ServerConfigGroup data.
*/
export interface IServerConfigGroupRepository {
add(group: Omit<ServerConfigGroup, "id">): Promise<ServerConfigGroup>;
update(group: ServerConfigGroup): Promise<ServerConfigGroup | null>;
delete(id: string): Promise<boolean>;
findById(id: string): Promise<ServerConfigGroup | null>;
findByName(name: string): Promise<ServerConfigGroup | null>;
findAll(): Promise<ServerConfigGroup[]>;
/**
* Retrieves all ServerConfigRecord objects that are members of a specific group.
* This method will internally query the IServerConfigRecordRepository.
*/
findServersInGroup(groupId: string): Promise<ServerConfigRecord[]>;
// Additional query methods can be added as needed
}
/**
* Interface for interacting with ConfigSource data.
*/
export interface IConfigSourceRepository {
add(source: Omit<IConfigSource, "id">): Promise<IConfigSource>;
update(source: IConfigSource): Promise<IConfigSource | null>;
delete(id: string): Promise<boolean>;
findById(id: string): Promise<IConfigSource | null>;
findByPath(path: string): Promise<IConfigSource | null>;
findByAppId(appId: string): Promise<IConfigSource[]>;
findAll(): Promise<IConfigSource[]>;
}
/**
* Central service interface for managing the database and providing access to repositories.
*/
export interface IDatabaseService {
servers: IServerConfigRecordRepository;
groups: IServerConfigGroupRepository;
configSources: IConfigSourceRepository;
init(): Promise<void>; // Initializes the database (loads data, sets up indexes)
close(): Promise<void>; // Closes the database connection (flushes data to disk)
}