@@ -61,8 +61,9 @@ app.prepare().then(() => {
6161 res . write ( ':\n\n' )
6262
6363 // Force flush the written data
64- if ( typeof res . flush === 'function' ) {
65- res . flush ( ) ;
64+ const response = res as unknown as { flush ?: ( ) => void } ;
65+ if ( typeof response . flush === 'function' ) {
66+ response . flush ( ) ;
6667 }
6768
6869 // Create client object
@@ -71,8 +72,9 @@ app.prepare().then(() => {
7172 try {
7273 console . log ( 'Sending message to client:' , data . substring ( 0 , 100 ) )
7374 res . write ( `data: ${ data } \n\n` )
74- if ( typeof res . flush === 'function' ) {
75- res . flush ( ) ;
75+ const response = res as unknown as { flush ?: ( ) => void } ;
76+ if ( typeof response . flush === 'function' ) {
77+ response . flush ( ) ;
7678 }
7779 } catch ( error ) {
7880 console . error ( 'Error sending message:' , error )
@@ -89,8 +91,9 @@ app.prepare().then(() => {
8991 const keepAlive = setInterval ( ( ) => {
9092 try {
9193 res . write ( ':\n\n' )
92- if ( typeof res . flush === 'function' ) {
93- res . flush ( ) ;
94+ const response = res as unknown as { flush ?: ( ) => void } ;
95+ if ( typeof response . flush === 'function' ) {
96+ response . flush ( ) ;
9497 }
9598 } catch ( error ) {
9699 console . error ( 'Error sending heartbeat:' , error )
@@ -154,13 +157,7 @@ app.prepare().then(() => {
154157 }
155158 } else {
156159 // Forward message to MCPServer
157- await mcpServer . handleMessage ( JSON . stringify ( message ) , {
158- send : ( response ) => {
159- for ( const client of sseClients ) {
160- client . send ( response ) ;
161- }
162- }
163- } ) ;
160+ await mcpServer . handleMessage ( JSON . stringify ( message ) ) ;
164161 }
165162
166163 // Send HTTP response
@@ -186,11 +183,7 @@ app.prepare().then(() => {
186183 req . on ( 'end' , async ( ) => {
187184 try {
188185 const message : JSONRPCMessage = JSON . parse ( body )
189- await mcpServer . handleMessage ( JSON . stringify ( message ) , {
190- send : ( response ) => {
191- sseClients . forEach ( client => client . send ( response ) )
192- }
193- } ) ;
186+ await mcpServer . handleMessage ( JSON . stringify ( message ) ) ;
194187 res . writeHead ( 200 )
195188 res . end ( )
196189 } catch ( error ) {
0 commit comments