ref: cleanup
This commit is contained in:
parent
ace5c2a8dd
commit
03e9a7be0d
2 changed files with 28 additions and 5 deletions
|
|
@ -171,6 +171,8 @@ Optionally, you can add it to a file called `.vscode/mcp.json` in your workspace
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
```
|
||||||
|
|
||||||
## Run with [HTTP+SSE Transport](https://modelcontextprotocol.io/specification/2024-11-05/basic/transports#http-with-sse) (deprecated as of [2025-03-26](https://modelcontextprotocol.io/specification/2025-03-26/basic/transports))
|
## Run with [HTTP+SSE Transport](https://modelcontextprotocol.io/specification/2024-11-05/basic/transports#http-with-sse) (deprecated as of [2025-03-26](https://modelcontextprotocol.io/specification/2025-03-26/basic/transports))
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
|
|
|
||||||
|
|
@ -50,7 +50,7 @@ app.post('/mcp', async (req: Request, res: Response) => {
|
||||||
// so responses can flow back through the same transport
|
// so responses can flow back through the same transport
|
||||||
await server.connect(transport);
|
await server.connect(transport);
|
||||||
|
|
||||||
await transport.handleRequest(req, res, req.body);
|
await transport.handleRequest(req, res);
|
||||||
return; // Already handled
|
return; // Already handled
|
||||||
} else {
|
} else {
|
||||||
// Invalid request - no session ID or not initialization request
|
// Invalid request - no session ID or not initialization request
|
||||||
|
|
@ -67,7 +67,7 @@ app.post('/mcp', async (req: Request, res: Response) => {
|
||||||
|
|
||||||
// Handle the request with existing transport - no need to reconnect
|
// Handle the request with existing transport - no need to reconnect
|
||||||
// The existing transport is already connected to the server
|
// The existing transport is already connected to the server
|
||||||
await transport.handleRequest(req, res, req.body);
|
await transport.handleRequest(req, res);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error handling MCP request:', error);
|
console.error('Error handling MCP request:', error);
|
||||||
if (!res.headersSent) {
|
if (!res.headersSent) {
|
||||||
|
|
@ -87,7 +87,14 @@ app.post('/mcp', async (req: Request, res: Response) => {
|
||||||
app.get('/mcp', async (req: Request, res: Response) => {
|
app.get('/mcp', async (req: Request, res: Response) => {
|
||||||
const sessionId = req.headers['mcp-session-id'] as string | undefined;
|
const sessionId = req.headers['mcp-session-id'] as string | undefined;
|
||||||
if (!sessionId || !transports[sessionId]) {
|
if (!sessionId || !transports[sessionId]) {
|
||||||
res.status(400).send('Invalid or missing session ID');
|
res.status(400).json({
|
||||||
|
jsonrpc: '2.0',
|
||||||
|
error: {
|
||||||
|
code: -32000,
|
||||||
|
message: 'Bad Request: No valid session ID provided',
|
||||||
|
},
|
||||||
|
id: null,
|
||||||
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -107,7 +114,14 @@ app.get('/mcp', async (req: Request, res: Response) => {
|
||||||
app.delete('/mcp', async (req: Request, res: Response) => {
|
app.delete('/mcp', async (req: Request, res: Response) => {
|
||||||
const sessionId = req.headers['mcp-session-id'] as string | undefined;
|
const sessionId = req.headers['mcp-session-id'] as string | undefined;
|
||||||
if (!sessionId || !transports[sessionId]) {
|
if (!sessionId || !transports[sessionId]) {
|
||||||
res.status(400).send('Invalid or missing session ID');
|
res.status(400).json({
|
||||||
|
jsonrpc: '2.0',
|
||||||
|
error: {
|
||||||
|
code: -32000,
|
||||||
|
message: 'Bad Request: No valid session ID provided',
|
||||||
|
},
|
||||||
|
id: null,
|
||||||
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -119,7 +133,14 @@ app.delete('/mcp', async (req: Request, res: Response) => {
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error handling session termination:', error);
|
console.error('Error handling session termination:', error);
|
||||||
if (!res.headersSent) {
|
if (!res.headersSent) {
|
||||||
res.status(500).send('Error processing session termination');
|
res.status(500).json({
|
||||||
|
jsonrpc: '2.0',
|
||||||
|
error: {
|
||||||
|
code: -32603,
|
||||||
|
message: 'Error handling session termination',
|
||||||
|
},
|
||||||
|
id: null,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue