mirror of
https://github.com/samanhappy/mcphub.git
synced 2025-12-23 18:29:21 -05:00
fix: refine sessionId handling in handleMcpPostRequest for initialization requests (#138)
Co-authored-by: samanhappy@qq.com <my6051199>
This commit is contained in:
@@ -54,9 +54,8 @@ export const initMiddlewares = (app: express.Application): void => {
|
||||
// Only apply JSON parsing for API and auth routes, not for SSE or message endpoints
|
||||
if (
|
||||
req.path !== `${basePath}/sse` &&
|
||||
req.path !== `${basePath}/messages` &&
|
||||
!req.path.startsWith(`${basePath}/sse/`) &&
|
||||
!req.path.startsWith(`${basePath}/mcp/`)
|
||||
req.path !== `${basePath}/messages`
|
||||
) {
|
||||
express.json()(req, res, next);
|
||||
} else {
|
||||
|
||||
@@ -129,7 +129,7 @@ export const handleMcpPostRequest = async (req: Request, res: Response): Promise
|
||||
if (sessionId && transports[sessionId]) {
|
||||
console.log(`Reusing existing transport for sessionId: ${sessionId}`);
|
||||
transport = transports[sessionId].transport as StreamableHTTPServerTransport;
|
||||
} else if (!sessionId) {
|
||||
} else if (!sessionId && isInitializeRequest(req.body)) {
|
||||
transport = new StreamableHTTPServerTransport({
|
||||
sessionIdGenerator: () => randomUUID(),
|
||||
onsessioninitialized: (sessionId) => {
|
||||
|
||||
Reference in New Issue
Block a user