// tools/tool-registry.ts — Local registry that tracks registered MCP tools.
// Replaces fragile access to SDK-internal `_registeredTools` property.
// Uses a Proxy to transparently intercept registerTool/tool calls on McpServer.
/** Module-level store of tool name -> RegisteredTool (ToolSlot interface). */
const registeredTools = new Map();
/**
 * Returns the map of all registered tools captured via `withToolTracking()`.
 * Each entry maps tool name -> { enable(), disable(), enabled }.
 */
export function getRegisteredTools() {
    return registeredTools;
}
/**
 * Wraps an McpServer instance with a Proxy that intercepts `registerTool` and
 * `tool` calls to capture the returned RegisteredTool into the local registry.
 * The returned server behaves identically to the original for all other operations.
 */
export function withToolTracking(server) {
    return new Proxy(server, {
        get(target, prop, receiver) {
            if (prop === 'registerTool' || prop === 'tool') {
                // Return a wrapper function that calls the original method and captures the result
                return (...args) => {
                    const name = args[0];
                    const originalMethod = Reflect.get(target, prop, receiver);
                    const registered = originalMethod.apply(target, args);
                    registeredTools.set(name, registered);
                    return registered;
                };
            }
            // eslint-disable-next-line @typescript-eslint/no-unsafe-return
            return Reflect.get(target, prop, receiver);
        },
    });
}
//# sourceMappingURL=tool-registry.js.map