Skip to content

Commit 9507ddd

Browse files
committed
ref: cleanup
1 parent ea6e777 commit 9507ddd

File tree

1 file changed

+26
-5
lines changed

1 file changed

+26
-5
lines changed

src/everything/streamableHttp.ts

+26-5
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ app.post('/mcp', async (req: Request, res: Response) => {
5050
// so responses can flow back through the same transport
5151
await server.connect(transport);
5252

53-
await transport.handleRequest(req, res, req.body);
53+
await transport.handleRequest(req, res);
5454
return; // Already handled
5555
} else {
5656
// Invalid request - no session ID or not initialization request
@@ -67,7 +67,7 @@ app.post('/mcp', async (req: Request, res: Response) => {
6767

6868
// Handle the request with existing transport - no need to reconnect
6969
// The existing transport is already connected to the server
70-
await transport.handleRequest(req, res, req.body);
70+
await transport.handleRequest(req, res);
7171
} catch (error) {
7272
console.error('Error handling MCP request:', error);
7373
if (!res.headersSent) {
@@ -87,7 +87,14 @@ app.post('/mcp', async (req: Request, res: Response) => {
8787
app.get('/mcp', async (req: Request, res: Response) => {
8888
const sessionId = req.headers['mcp-session-id'] as string | undefined;
8989
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+
});
9198
return;
9299
}
93100

@@ -107,7 +114,14 @@ app.get('/mcp', async (req: Request, res: Response) => {
107114
app.delete('/mcp', async (req: Request, res: Response) => {
108115
const sessionId = req.headers['mcp-session-id'] as string | undefined;
109116
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+
});
111125
return;
112126
}
113127

@@ -119,7 +133,14 @@ app.delete('/mcp', async (req: Request, res: Response) => {
119133
} catch (error) {
120134
console.error('Error handling session termination:', error);
121135
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+
});
123144
}
124145
}
125146
});

0 commit comments

Comments
 (0)