@@ -169,16 +169,6 @@ export const createServer = () => {
169169 let subsUpdateInterval : NodeJS . Timeout | undefined ;
170170 let stdErrUpdateInterval : NodeJS . Timeout | undefined ;
171171
172- // Set up update interval for subscribed resources
173- subsUpdateInterval = setInterval ( ( ) => {
174- for ( const uri of subscriptions ) {
175- server . notification ( {
176- method : "notifications/resources/updated" ,
177- params : { uri } ,
178- } ) ;
179- }
180- } , 10000 ) ;
181-
182172 let logLevel : LoggingLevel = "debug" ;
183173 let logsUpdateInterval : NodeJS . Timeout | undefined ;
184174 const messages = [
@@ -198,15 +188,30 @@ export const createServer = () => {
198188 return messageLevel < currentLevel ;
199189 } ;
200190
201- // Set up update interval for random log messages
202- logsUpdateInterval = setInterval ( ( ) => {
203- let message = {
204- method : "notifications/message" ,
205- params : messages [ Math . floor ( Math . random ( ) * messages . length ) ] ,
206- } ;
207- if ( ! isMessageIgnored ( message . params . level as LoggingLevel ) )
208- server . notification ( message ) ;
209- } , 20000 ) ;
191+ // Function to start notification intervals when a client connects
192+ const startNotificationIntervals = ( ) => {
193+ if ( ! subsUpdateInterval ) {
194+ subsUpdateInterval = setInterval ( ( ) => {
195+ for ( const uri of subscriptions ) {
196+ server . notification ( {
197+ method : "notifications/resources/updated" ,
198+ params : { uri } ,
199+ } ) ;
200+ }
201+ } , 10000 ) ;
202+ }
203+
204+ if ( ! logsUpdateInterval ) {
205+ logsUpdateInterval = setInterval ( ( ) => {
206+ let message = {
207+ method : "notifications/message" ,
208+ params : messages [ Math . floor ( Math . random ( ) * messages . length ) ] ,
209+ } ;
210+ if ( ! isMessageIgnored ( message . params . level as LoggingLevel ) )
211+ server . notification ( message ) ;
212+ } , 20000 ) ;
213+ }
214+ } ;
210215
211216
212217
@@ -874,7 +879,7 @@ export const createServer = () => {
874879 if ( stdErrUpdateInterval ) clearInterval ( stdErrUpdateInterval ) ;
875880 } ;
876881
877- return { server, cleanup } ;
882+ return { server, cleanup, startNotificationIntervals } ;
878883} ;
879884
880885const MCP_TINY_IMAGE =
0 commit comments