@@ -20,21 +20,13 @@ export class HttpStreamTransport extends AbstractTransport {
2020 private _serverConfig : any ;
2121 private _serverSetupCallback ?: ( server : McpServer ) => Promise < void > ;
2222
23- private _pingInterval ?: NodeJS . Timeout ;
24- private _pingTimeouts : Map < string | number , NodeJS . Timeout > = new Map ( ) ;
25- private _pingFrequency : number ;
26- private _pingTimeout : number ;
27-
2823 constructor ( config : HttpStreamTransportConfig = { } ) {
2924 super ( ) ;
3025
3126 this . _port = config . port || 8080 ;
3227 this . _endpoint = config . endpoint || '/mcp' ;
3328 this . _enableJsonResponse = config . responseMode === 'batch' ;
3429
35- this . _pingFrequency = config . ping ?. frequency ?? 30000 ;
36- this . _pingTimeout = config . ping ?. timeout ?? 10000 ;
37-
3830 logger . debug (
3931 `HttpStreamTransport configured with: ${ JSON . stringify ( {
4032 port : this . _port ,
@@ -44,10 +36,6 @@ export class HttpStreamTransport extends AbstractTransport {
4436 maxMessageSize : config . maxMessageSize ,
4537 auth : config . auth ? true : false ,
4638 cors : config . cors ? true : false ,
47- ping : {
48- frequency : this . _pingFrequency ,
49- timeout : this . _pingTimeout ,
50- } ,
5139 } ) } `
5240 ) ;
5341 }
@@ -97,7 +85,6 @@ export class HttpStreamTransport extends AbstractTransport {
9785 this . _server . listen ( this . _port , ( ) => {
9886 logger . info ( `HTTP server listening on port ${ this . _port } , endpoint ${ this . _endpoint } ` ) ;
9987 this . _isRunning = true ;
100- this . startPingInterval ( ) ;
10188 resolve ( ) ;
10289 } ) ;
10390 } ) ;
@@ -202,52 +189,10 @@ export class HttpStreamTransport extends AbstractTransport {
202189 ) ;
203190 }
204191
205- private startPingInterval ( ) : void {
206- if ( this . _pingFrequency > 0 ) {
207- logger . debug (
208- `Starting ping interval with frequency ${ this . _pingFrequency } ms and timeout ${ this . _pingTimeout } ms`
209- ) ;
210- this . _pingInterval = setInterval ( ( ) => this . sendPing ( ) , this . _pingFrequency ) ;
211- }
212- }
213-
214- private async sendPing ( ) : Promise < void > {
215- if ( ! this . _isRunning || Object . keys ( this . _transports ) . length === 0 ) {
216- return ;
217- }
218-
219- const pingId = `ping-${ Date . now ( ) } ` ;
220- const pingRequest : JSONRPCMessage = {
221- jsonrpc : '2.0' as const ,
222- id : pingId ,
223- method : 'ping' ,
224- } ;
225-
226- logger . debug (
227- `Broadcasting ping to ${ Object . keys ( this . _transports ) . length } sessions: ${ JSON . stringify ( pingRequest ) } `
228- ) ;
229-
230- for ( const [ sessionId , transport ] of Object . entries ( this . _transports ) ) {
231- try {
232- await transport . send ( pingRequest ) ;
233-
234- const timeoutId = setTimeout ( ( ) => {
235- logger . warn ( `Ping timeout for session ${ sessionId } ` ) ;
236- delete this . _transports [ sessionId ] ;
237- this . _pingTimeouts . delete ( pingId ) ;
238- } , this . _pingTimeout ) ;
239-
240- this . _pingTimeouts . set ( pingId , timeoutId ) ;
241- } catch ( error ) {
242- logger . error ( `Error sending ping to session ${ sessionId } : ${ error } ` ) ;
243- delete this . _transports [ sessionId ] ;
244- }
245- }
246- }
247-
248192 async send ( message : JSONRPCMessage ) : Promise < void > {
249193 if ( ! this . _isRunning ) {
250- throw new Error ( 'HttpStreamTransport not running' ) ;
194+ logger . warn ( 'Attempted to send message, but HTTP transport is not running' ) ;
195+ return ;
251196 }
252197
253198 const activeSessions = Object . entries ( this . _transports ) ;
@@ -282,16 +227,6 @@ export class HttpStreamTransport extends AbstractTransport {
282227 return ;
283228 }
284229
285- if ( this . _pingInterval ) {
286- clearInterval ( this . _pingInterval ) ;
287- this . _pingInterval = undefined ;
288- }
289-
290- for ( const timeout of this . _pingTimeouts . values ( ) ) {
291- clearTimeout ( timeout ) ;
292- }
293- this . _pingTimeouts . clear ( ) ;
294-
295230 for ( const transport of Object . values ( this . _transports ) ) {
296231 try {
297232 await transport . close ( ) ;
0 commit comments