/** * Resource subscription management with file watching. * * Tracks client subscriptions to resource URIs and watches underlying files * using chokidar. When files change, sends notifications/resources/updated * to subscribed clients. * * URI patterns supported (SEP-2640): * - skill://index.json → Watch every SKILL.md (any skill change re-fires) * - skill:///SKILL.md → Watch that skill's SKILL.md * - skill:/// → Watch a specific file inside the skill directory */ import { FSWatcher } from "chokidar"; import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js"; import { SkillState } from "./skill-tool.js"; /** * Manages active subscriptions and their associated file watchers. */ export interface SubscriptionManager { /** URI -> Set of file paths being watched for this URI */ uriToFilePaths: Map>; /** File path -> Set of URIs that depend on this file */ filePathToUris: Map>; /** File path -> chokidar watcher instance */ watchers: Map; /** Pending notification timeouts for debouncing (URI -> timeout) */ pendingNotifications: Map; } /** * Create a new subscription manager. */ export declare function createSubscriptionManager(): SubscriptionManager; /** * Resolve a skill:// URI to the file paths it depends on. * * @param uri - The resource URI * @param skillState - Current skill state for lookups * @returns Array of absolute file paths to watch */ export declare function resolveUriToFilePaths(uri: string, skillState: SkillState): string[]; /** * Add a subscription for a URI. * * @param manager - The subscription manager * @param uri - The resource URI to subscribe to * @param skillState - Current skill state for resolving URIs * @param onNotify - Callback to send notification when file changes * @returns True if subscription was added, false if URI couldn't be resolved */ export declare function subscribe(manager: SubscriptionManager, uri: string, skillState: SkillState, onNotify: (uri: string) => void): boolean; /** * Remove a subscription for a URI. * * @param manager - The subscription manager * @param uri - The resource URI to unsubscribe from */ export declare function unsubscribe(manager: SubscriptionManager, uri: string): void; /** * Update subscriptions when skills change. * * Re-resolves all existing URIs with the new skill state and updates * watchers accordingly. Sends notifications for any URIs whose underlying * files have changed. * * @param manager - The subscription manager * @param skillState - Updated skill state * @param onNotify - Callback to send notification */ export declare function refreshSubscriptions(manager: SubscriptionManager, skillState: SkillState, onNotify: (uri: string) => void): void; /** * Register subscribe/unsubscribe request handlers with the server. * * @param server - The MCP server instance * @param skillState - Shared skill state * @param manager - The subscription manager */ export declare function registerSubscriptionHandlers(server: McpServer, skillState: SkillState, manager: SubscriptionManager): void;