@@ -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 , req . body ) ;
53
+ await transport . handleRequest ( req , res ) ;
54
54
return ; // Already handled
55
55
} else {
56
56
// Invalid request - no session ID or not initialization request
@@ -67,7 +67,7 @@ app.post('/mcp', async (req: Request, res: Response) => {
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 , req . body ) ;
70
+ await transport . handleRequest ( req , res ) ;
71
71
} catch ( error ) {
72
72
console . error ( 'Error handling MCP request:' , error ) ;
73
73
if ( ! res . headersSent ) {
@@ -87,7 +87,14 @@ app.post('/mcp', async (req: Request, res: Response) => {
87
87
app . get ( '/mcp' , async ( req : Request , res : Response ) => {
88
88
const sessionId = req . headers [ 'mcp-session-id' ] as string | undefined ;
89
89
if ( ! sessionId || ! transports [ sessionId ] ) {
90
- res . status ( 400 ) . send ( 'Invalid or missing session ID' ) ;
90
+ res . status ( 400 ) . json ( {
91
+ jsonrpc : '2.0' ,
92
+ error : {
93
+ code : - 32000 ,
94
+ message : 'Bad Request: No valid session ID provided' ,
95
+ } ,
96
+ id : null ,
97
+ } ) ;
91
98
return ;
92
99
}
93
100
@@ -107,7 +114,14 @@ app.get('/mcp', async (req: Request, res: Response) => {
107
114
app . delete ( '/mcp' , async ( req : Request , res : Response ) => {
108
115
const sessionId = req . headers [ 'mcp-session-id' ] as string | undefined ;
109
116
if ( ! sessionId || ! transports [ sessionId ] ) {
110
- res . status ( 400 ) . send ( 'Invalid or missing session ID' ) ;
117
+ res . status ( 400 ) . json ( {
118
+ jsonrpc : '2.0' ,
119
+ error : {
120
+ code : - 32000 ,
121
+ message : 'Bad Request: No valid session ID provided' ,
122
+ } ,
123
+ id : null ,
124
+ } ) ;
111
125
return ;
112
126
}
113
127
@@ -119,7 +133,14 @@ app.delete('/mcp', async (req: Request, res: Response) => {
119
133
} catch ( error ) {
120
134
console . error ( 'Error handling session termination:' , error ) ;
121
135
if ( ! res . headersSent ) {
122
- res . status ( 500 ) . send ( 'Error processing session termination' ) ;
136
+ res . status ( 500 ) . json ( {
137
+ jsonrpc : '2.0' ,
138
+ error : {
139
+ code : - 32603 ,
140
+ message : 'Error handling session termination' ,
141
+ } ,
142
+ id : null ,
143
+ } ) ;
123
144
}
124
145
}
125
146
} ) ;
0 commit comments