@@ -50,7 +50,7 @@ app.post('/mcp', async (req: Request, res: Response) => {
50
50
// so responses can flow back through the same transport
51
51
await server . connect ( transport ) ;
52
52
53
- await transport . handleRequest ( req , res ) ;
53
+ await transport . handleRequest ( req , res , req . body ) ;
54
54
return ; // Already handled
55
55
} else {
56
56
// Invalid request - no session ID or not initialization request
@@ -60,14 +60,14 @@ app.post('/mcp', async (req: Request, res: Response) => {
60
60
code : - 32000 ,
61
61
message : 'Bad Request: No valid session ID provided' ,
62
62
} ,
63
- id : null ,
63
+ id : req ?. body ?. id ,
64
64
} ) ;
65
65
return ;
66
66
}
67
67
68
68
// Handle the request with existing transport - no need to reconnect
69
69
// The existing transport is already connected to the server
70
- await transport . handleRequest ( req , res ) ;
70
+ await transport . handleRequest ( req , res , req . body ) ;
71
71
} catch ( error ) {
72
72
console . error ( 'Error handling MCP request:' , error ) ;
73
73
if ( ! res . headersSent ) {
@@ -77,8 +77,9 @@ app.post('/mcp', async (req: Request, res: Response) => {
77
77
code : - 32603 ,
78
78
message : 'Internal server error' ,
79
79
} ,
80
- id : null ,
80
+ id : req ?. body ?. id ,
81
81
} ) ;
82
+ return ;
82
83
}
83
84
}
84
85
} ) ;
@@ -93,7 +94,7 @@ app.get('/mcp', async (req: Request, res: Response) => {
93
94
code : - 32000 ,
94
95
message : 'Bad Request: No valid session ID provided' ,
95
96
} ,
96
- id : null ,
97
+ id : req ?. body ?. id ,
97
98
} ) ;
98
99
return ;
99
100
}
@@ -120,7 +121,7 @@ app.delete('/mcp', async (req: Request, res: Response) => {
120
121
code : - 32000 ,
121
122
message : 'Bad Request: No valid session ID provided' ,
122
123
} ,
123
- id : null ,
124
+ id : req ?. body ?. id ,
124
125
} ) ;
125
126
return ;
126
127
}
@@ -139,8 +140,9 @@ app.delete('/mcp', async (req: Request, res: Response) => {
139
140
code : - 32603 ,
140
141
message : 'Error handling session termination' ,
141
142
} ,
142
- id : null ,
143
+ id : req ?. body ?. id ,
143
144
} ) ;
145
+ return ;
144
146
}
145
147
}
146
148
} ) ;
0 commit comments