@@ -14,7 +14,7 @@ const JSON_RPC_ERROR_CODE_SESSION_ID_INVALID = -32002;
14
14
const JSON_RPC_ERROR_CODE_SESSION_NOT_FOUND = - 32003 ;
15
15
const JSON_RPC_ERROR_CODE_INVALID_REQUEST = - 32004 ;
16
16
17
- function promiseHandler (
17
+ function withErrorHandling (
18
18
fn : ( req : express . Request , res : express . Response , next : express . NextFunction ) => Promise < void >
19
19
) {
20
20
return ( req : express . Request , res : express . Response , next : express . NextFunction ) => {
@@ -50,7 +50,7 @@ export class StreamableHttpRunner extends TransportRunnerBase {
50
50
app . enable ( "trust proxy" ) ; // needed for reverse proxy support
51
51
app . use ( express . json ( ) ) ;
52
52
53
- const handleRequest = async ( req : express . Request , res : express . Response ) => {
53
+ const handleSessionRequest = async ( req : express . Request , res : express . Response ) => {
54
54
const sessionId = req . headers [ "mcp-session-id" ] ;
55
55
if ( ! sessionId ) {
56
56
res . status ( 400 ) . json ( {
@@ -88,10 +88,10 @@ export class StreamableHttpRunner extends TransportRunnerBase {
88
88
89
89
app . post (
90
90
"/mcp" ,
91
- promiseHandler ( async ( req : express . Request , res : express . Response ) => {
91
+ withErrorHandling ( async ( req : express . Request , res : express . Response ) => {
92
92
const sessionId = req . headers [ "mcp-session-id" ] ;
93
93
if ( sessionId ) {
94
- await handleRequest ( req , res ) ;
94
+ await handleSessionRequest ( req , res ) ;
95
95
return ;
96
96
}
97
97
@@ -141,8 +141,8 @@ export class StreamableHttpRunner extends TransportRunnerBase {
141
141
} )
142
142
) ;
143
143
144
- app . get ( "/mcp" , promiseHandler ( handleRequest ) ) ;
145
- app . delete ( "/mcp" , promiseHandler ( handleRequest ) ) ;
144
+ app . get ( "/mcp" , withErrorHandling ( handleSessionRequest ) ) ;
145
+ app . delete ( "/mcp" , withErrorHandling ( handleSessionRequest ) ) ;
146
146
147
147
this . httpServer = await new Promise < http . Server > ( ( resolve , reject ) => {
148
148
const result = app . listen ( this . userConfig . httpPort , this . userConfig . httpHost , ( err ?: Error ) => {
0 commit comments