@@ -186,16 +186,6 @@ export const createServer = () => {
186186 let subsUpdateInterval : NodeJS . Timeout | undefined ;
187187 let stdErrUpdateInterval : NodeJS . Timeout | undefined ;
188188
189- // Set up update interval for subscribed resources
190- subsUpdateInterval = setInterval ( ( ) => {
191- for ( const uri of subscriptions ) {
192- server . notification ( {
193- method : "notifications/resources/updated" ,
194- params : { uri } ,
195- } ) ;
196- }
197- } , 10000 ) ;
198-
199189 let logLevel : LoggingLevel = "debug" ;
200190 let logsUpdateInterval : NodeJS . Timeout | undefined ;
201191 const messages = [
@@ -215,15 +205,30 @@ export const createServer = () => {
215205 return messageLevel < currentLevel ;
216206 } ;
217207
218- // Set up update interval for random log messages
219- logsUpdateInterval = setInterval ( ( ) => {
220- let message = {
221- method : "notifications/message" ,
222- params : messages [ Math . floor ( Math . random ( ) * messages . length ) ] ,
223- } ;
224- if ( ! isMessageIgnored ( message . params . level as LoggingLevel ) )
225- server . notification ( message ) ;
226- } , 20000 ) ;
208+ // Function to start notification intervals when a client connects
209+ const startNotificationIntervals = ( ) => {
210+ if ( ! subsUpdateInterval ) {
211+ subsUpdateInterval = setInterval ( ( ) => {
212+ for ( const uri of subscriptions ) {
213+ server . notification ( {
214+ method : "notifications/resources/updated" ,
215+ params : { uri } ,
216+ } ) ;
217+ }
218+ } , 10000 ) ;
219+ }
220+
221+ if ( ! logsUpdateInterval ) {
222+ logsUpdateInterval = setInterval ( ( ) => {
223+ let message = {
224+ method : "notifications/message" ,
225+ params : messages [ Math . floor ( Math . random ( ) * messages . length ) ] ,
226+ } ;
227+ if ( ! isMessageIgnored ( message . params . level as LoggingLevel ) )
228+ server . notification ( message ) ;
229+ } , 20000 ) ;
230+ }
231+ } ;
227232
228233
229234
@@ -941,7 +946,7 @@ export const createServer = () => {
941946 if ( stdErrUpdateInterval ) clearInterval ( stdErrUpdateInterval ) ;
942947 } ;
943948
944- return { server, cleanup } ;
949+ return { server, cleanup, startNotificationIntervals } ;
945950} ;
946951
947952const MCP_TINY_IMAGE =
0 commit comments