@dollhousemcp/mcp-server
Version:
DollhouseMCP - A Model Context Protocol (MCP) server that enables dynamic AI persona management from markdown files, allowing Claude and other compatible AI assistants to activate and switch between different behavioral personas.
154 lines • 6.52 kB
TypeScript
import { Server } from "@modelcontextprotocol/sdk/server/index.js";
import { EnhancedIndexHandler } from "../handlers/EnhancedIndexHandler.js";
import { MCPAQLHandler } from "../handlers/mcp-aql/MCPAQLHandler.js";
import { PersonaHandler } from "../handlers/PersonaHandler.js";
import { ElementCRUDHandler } from "../handlers/ElementCRUDHandler.js";
import { CollectionHandler } from "../handlers/CollectionHandler.js";
import { PortfolioHandler } from "../handlers/PortfolioHandler.js";
import { GitHubAuthHandler } from "../handlers/GitHubAuthHandler.js";
import { DisplayConfigHandler } from "../handlers/DisplayConfigHandler.js";
import { IdentityHandler } from "../handlers/IdentityHandler.js";
import { ConfigHandler } from "../handlers/ConfigHandler.js";
import { SyncHandler } from "../handlers/SyncHandlerV2.js";
import { ToolRegistry } from "../handlers/ToolRegistry.js";
import { StartupTimer } from "../telemetry/StartupTimer.js";
export interface HandlerBundle {
personaHandler: PersonaHandler;
elementCrudHandler: ElementCRUDHandler;
collectionHandler: CollectionHandler;
portfolioHandler: PortfolioHandler;
githubAuthHandler: GitHubAuthHandler;
displayConfigHandler: DisplayConfigHandler;
identityHandler: IdentityHandler;
configHandler: ConfigHandler;
syncHandler: SyncHandler;
toolRegistry: ToolRegistry;
enhancedIndexHandler: EnhancedIndexHandler;
mcpAqlHandler: MCPAQLHandler;
}
export declare class DollhouseContainer {
private services;
private personasDir;
/** Issue #706: Set to true once completeDeferredSetup() resolves. */
deferredSetupComplete: boolean;
constructor();
/**
* Register a service with the DI container
*
* FIX: Added explicit type parameter for type safety
* The factory is stored as () => unknown internally to allow heterogeneous storage,
* but the type T is preserved for resolve() calls
*
* @template T The service type
* @param name Unique service identifier
* @param factory Factory function that creates the service instance
* @param options Configuration options (singleton behavior)
*/
register<T>(name: string, factory: () => T, options?: {
singleton?: boolean;
}): void;
/**
* Resolve a service from the DI container
*
* FIX: Type safety improved with explicit casting and validation
* The 'as T' cast is safe because:
* 1. Services are registered with typed factories
* 2. The service name acts as a type discriminator
* 3. Incorrect usage will be caught at the registration site
*
* @template T The expected service type
* @param name Service identifier
* @returns The service instance
* @throws Error if service is not registered
*/
resolve<T>(name: string): T;
private registerServices;
getPersonasDir(): string | null;
/**
* Prepare portfolio — critical path only.
*
* Issue #706: Split from the original monolithic preparePortfolio().
* Only work required before MCP connect() runs here. Non-critical work
* (memory auto-load, activation restore, log hooks, danger zone init)
* is deferred to completeDeferredSetup() which runs post-connect.
*/
preparePortfolio(): Promise<void>;
/**
* Complete non-critical setup after MCP connect().
*
* Issue #706: These operations were previously in preparePortfolio() but are
* non-fatal and can safely run after the server is accepting connections.
* This shrinks the critical path by 1000-3700ms.
*/
completeDeferredSetup(): Promise<void>;
/**
* Wire sinks, hooks, collectors, and security — everything EXCEPT
* the web console leader election and permission server.
*
* Called by completeDeferredSetup() in MCP stdio mode, and directly
* by the --web standalone path which IS the server (#1866).
*/
completeSinkSetup(timer?: StartupTimer): Promise<void>;
/**
* Leader election, web console server, and permission server.
* Only called in MCP stdio mode — --web standalone mode IS the server (#1866).
*/
completeConsoleSetup(timer?: StartupTimer): Promise<void>;
private deferredMemoryAutoload;
private deferredActivationRestore;
private deferredPolicyExport;
private deferredLogHooks;
private deferredMetricsCollectors;
/** Try to resolve a service, returning undefined if not registered */
private tryResolve;
/** Wire SSE broadcast sinks for the web console */
private wireSSEBroadcasts;
private deferredWebConsole;
private deferredPermissionServer;
private deferredDangerZoneInit;
private deferredPatternEncryption;
private deferredBackgroundValidator;
/**
* Restore per-session activation state from the ActivationStore.
* Called during preparePortfolio() after auto-load memories.
*
* Issue #598: Each element type is restored independently.
* Missing elements (deleted since last session) are skipped and pruned.
* Auto-loaded memories are deduplicated (not activated twice).
*/
private restoreActivations;
/**
* Bootstrap all handlers without registering MCP tools.
* Used by web-only mode (--web) to get MCPAQLHandler without an MCP Server.
* Issue #796: Split DI container bootstrap from transport connect.
*/
bootstrapHandlers(): Promise<HandlerBundle>;
/**
* Create all handlers with dependency injection and register MCP tools.
* @param server - MCP Server instance for tool registration
*/
createHandlers(server: Server): Promise<HandlerBundle>;
/**
* Log tool token statistics for monitoring and documentation.
* Shows current mode token count, alternative mode comparison, and savings.
*
* This is important for:
* 1. Documenting actual token savings achieved
* 2. Monitoring context window usage
* 3. Supporting future MCP-AQL adapter development
*
* Issue #237 enhancement
*/
private logToolTokenStats;
/**
* Wire all metric collectors into the MetricsManager.
* Mirrors wireLogHooks() — keeps collector registration out of the constructor.
*/
private wireMetricsCollectors;
private collectLruCachesForMetrics;
dispose(): Promise<void>;
private buildDisposalPromises;
private reportDisposalFailures;
private initializeCollectionCache;
}
//# sourceMappingURL=Container.d.ts.map