@@ -245,7 +245,7 @@ export class Client<
245245 private _cachedKnownTaskTools : Set < string > = new Set ( ) ;
246246 private _cachedRequiredTaskTools : Set < string > = new Set ( ) ;
247247 private _experimental ?: { tasks : ExperimentalClientTasks < RequestT , NotificationT , ResultT > } ;
248- private _toolListChangedOptions : ToolListChangedOptions | null = null ;
248+ private _toolListChangedOptions ? : ToolListChangedOptions ;
249249 private _toolListChangedDebounceTimer ?: ReturnType < typeof setTimeout > ;
250250
251251 /**
@@ -822,7 +822,7 @@ export class Client<
822822 const refreshToolList = async ( ) => {
823823 // If autoRefresh is false, call the callback for the notification, but without tools data
824824 if ( ! toolListChangedOptions . autoRefresh ) {
825- toolListChangedOptions . onToolListChanged ?. ( null , null ) ;
825+ toolListChangedOptions . onToolListChanged ( null , null ) ;
826826 return ;
827827 }
828828
@@ -834,7 +834,7 @@ export class Client<
834834 } catch ( e ) {
835835 error = e instanceof Error ? e : new Error ( String ( e ) ) ;
836836 }
837- toolListChangedOptions . onToolListChanged ?. ( error , tools ) ;
837+ toolListChangedOptions . onToolListChanged ( error , tools ) ;
838838 } ;
839839
840840 this . setNotificationHandler ( ToolListChangedNotificationSchema , ( ) => {
@@ -854,15 +854,19 @@ export class Client<
854854 }
855855 // Reset tool list changed options and remove notification handler
856856 else {
857- this . _toolListChangedOptions = null ;
857+ this . _toolListChangedOptions = undefined ;
858858 this . removeNotificationHandler ( ToolListChangedNotificationSchema . shape . method . value ) ;
859+ if ( this . _toolListChangedDebounceTimer ) {
860+ clearTimeout ( this . _toolListChangedDebounceTimer ) ;
861+ this . _toolListChangedDebounceTimer = undefined ;
862+ }
859863 }
860864 }
861865
862866 /**
863867 * Gets the current tool list changed options
864868 */
865- public getToolListChangedOptions ( ) : ToolListChangedOptions | null {
869+ public getToolListChangedOptions ( ) : ToolListChangedOptions | undefined {
866870 return this . _toolListChangedOptions ;
867871 }
868872
0 commit comments