@@ -14,7 +14,7 @@ const JSON_RPC_ERROR_CODE_SESSION_ID_INVALID = -32002;
1414const JSON_RPC_ERROR_CODE_SESSION_NOT_FOUND = - 32003 ;
1515const JSON_RPC_ERROR_CODE_INVALID_REQUEST = - 32004 ;
1616
17- function promiseHandler (
17+ function withErrorHandling (
1818 fn : ( req : express . Request , res : express . Response , next : express . NextFunction ) => Promise < void >
1919) {
2020 return ( req : express . Request , res : express . Response , next : express . NextFunction ) => {
@@ -50,7 +50,7 @@ export class StreamableHttpRunner extends TransportRunnerBase {
5050 app . enable ( "trust proxy" ) ; // needed for reverse proxy support
5151 app . use ( express . json ( ) ) ;
5252
53- const handleRequest = async ( req : express . Request , res : express . Response ) => {
53+ const handleSessionRequest = async ( req : express . Request , res : express . Response ) => {
5454 const sessionId = req . headers [ "mcp-session-id" ] ;
5555 if ( ! sessionId ) {
5656 res . status ( 400 ) . json ( {
@@ -88,10 +88,10 @@ export class StreamableHttpRunner extends TransportRunnerBase {
8888
8989 app . post (
9090 "/mcp" ,
91- promiseHandler ( async ( req : express . Request , res : express . Response ) => {
91+ withErrorHandling ( async ( req : express . Request , res : express . Response ) => {
9292 const sessionId = req . headers [ "mcp-session-id" ] ;
9393 if ( sessionId ) {
94- await handleRequest ( req , res ) ;
94+ await handleSessionRequest ( req , res ) ;
9595 return ;
9696 }
9797
@@ -141,8 +141,8 @@ export class StreamableHttpRunner extends TransportRunnerBase {
141141 } )
142142 ) ;
143143
144- app . get ( "/mcp" , promiseHandler ( handleRequest ) ) ;
145- app . delete ( "/mcp" , promiseHandler ( handleRequest ) ) ;
144+ app . get ( "/mcp" , withErrorHandling ( handleSessionRequest ) ) ;
145+ app . delete ( "/mcp" , withErrorHandling ( handleSessionRequest ) ) ;
146146
147147 this . httpServer = await new Promise < http . Server > ( ( resolve , reject ) => {
148148 const result = app . listen ( this . userConfig . httpPort , this . userConfig . httpHost , ( err ?: Error ) => {
0 commit comments