/** Duck-typed MCP server that supports notifications */ interface McpServerLike { notification(notification: { method: string; }): Promise; sendNotification?(notification: { method: string; }): Promise; } /** Duck-typed ToolRegistry */ interface ToolRegistryLike { register(builder: unknown): void; getBuilders?(): unknown[]; /** Optional: clear all builders before re-registering (for hot-reload) */ clear?(): void; } /** * Configuration for the development server. */ export interface DevServerConfig { /** * Directory to watch for file changes. * Relative paths are resolved from the current working directory. */ readonly dir: string; /** * File extension filter for watched files. * @default ['.ts', '.js', '.mjs', '.mts'] */ readonly extensions?: string[]; /** * Debounce interval in milliseconds. * Prevents rapid-fire reloads when editors save multiple files. * @default 300 */ readonly debounce?: number; /** * Setup callback invoked on every reload. * * Receives a fresh ToolRegistry. The callback should: * 1. Import/define all tools * 2. Register them on the registry * * This is called on initial startup and on every file change. */ readonly setup: (registry: ToolRegistryLike) => void | Promise; /** * Optional callback when a reload occurs. * Useful for logging or triggering downstream updates. */ readonly onReload?: (changedFile: string) => void; /** * Optional MCP server reference for sending tool list change notifications. * When provided, the dev server sends `notifications/tools/list_changed` * on every reload, so the LLM client picks up changes automatically. */ readonly server?: McpServerLike; /** * Optional real ToolRegistry reference for hot-reload. * * When provided, builders collected during `setup()` are automatically * transferred to this registry after each reload, making hot-reload * effective. Without this, the user must close over their own registry * in the setup callback (fragile and undocumented pattern). * * If the registry implements `clear()`, old builders are removed * before re-registration to avoid duplicates. */ readonly registry?: ToolRegistryLike; } /** * Interface for a running dev server instance. */ export interface DevServer { /** Start watching and perform initial load */ start(): Promise; /** Stop the watcher and clean up */ stop(): void; /** Force a manual reload (useful from CLI) */ reload(reason?: string): Promise; } /** * Create a cache-busting import URL for ESM modules. * Appends a timestamp query to force the module to be re-evaluated. * * Use this inside a DevServer `setup` callback to re-import ESM modules: * ```ts * const mod = await import(cacheBustUrl('./src/tools.ts')); * ``` */ export declare function cacheBustUrl(filePath: string): string; /** * Create an HMR-enabled MCP development server. * * Watches a directory for file changes and automatically reloads * tools, then notifies the connected MCP client via the native * `notifications/tools/list_changed` notification. * * @param config - Dev server configuration * @returns A {@link DevServer} instance with start/stop/reload controls * * @example * ```typescript * import { createDevServer, autoDiscover, ToolRegistry } from '@vinkius-core/mcp-fusion'; * * const devServer = createDevServer({ * dir: './src/tools', * setup: async (registry) => { * await autoDiscover(registry, './src/tools'); * }, * onReload: (file) => console.log(`[HMR] Reloaded: ${file}`), * }); * * await devServer.start(); * // File changes → auto-reload → LLM client gets notification * ``` */ export declare function createDevServer(config: DevServerConfig): DevServer; export {}; //# sourceMappingURL=DevServer.d.ts.map