Use Mcp-Session-Id
Showing
1 changed file
with
12 additions
and
13 deletions
| ... | @@ -330,8 +330,11 @@ logger.info("Handling Enhanced SSE connection from ${request.remoteAddr}") | ... | @@ -330,8 +330,11 @@ logger.info("Handling Enhanced SSE connection from ${request.remoteAddr}") |
| 330 | ] | 330 | ] |
| 331 | sendSseEvent(response.writer, "connect", groovy.json.JsonOutput.toJson(connectData), 0) | 331 | sendSseEvent(response.writer, "connect", groovy.json.JsonOutput.toJson(connectData), 0) |
| 332 | 332 | ||
| 333 | // Send endpoint info for message posting | 333 | // Set MCP session ID header per specification |
| 334 | sendSseEvent(response.writer, "endpoint", "/mcp/message?sessionId=" + visit.visitId, 1) | 334 | response.setHeader("Mcp-Session-Id", visit.visitId.toString()) |
| 335 | |||
| 336 | // Send endpoint info for message posting (for compatibility) | ||
| 337 | sendSseEvent(response.writer, "endpoint", "/mcp", 1) | ||
| 335 | 338 | ||
| 336 | // Keep connection alive with periodic pings | 339 | // Keep connection alive with periodic pings |
| 337 | int pingCount = 0 | 340 | int pingCount = 0 |
| ... | @@ -539,6 +542,11 @@ logger.info("Handling Enhanced SSE connection from ${request.remoteAddr}") | ... | @@ -539,6 +542,11 @@ logger.info("Handling Enhanced SSE connection from ${request.remoteAddr}") |
| 539 | 542 | ||
| 540 | logger.info("Enhanced MCP JSON-RPC Request: ${method} ${request.requestURI} - Accept: ${acceptHeader}, Content-Type: ${contentType}") | 543 | logger.info("Enhanced MCP JSON-RPC Request: ${method} ${request.requestURI} - Accept: ${acceptHeader}, Content-Type: ${contentType}") |
| 541 | 544 | ||
| 545 | // Log request body for debugging (be careful with this in production) | ||
| 546 | if (requestBody?.length() > 0) { | ||
| 547 | logger.info("MCP JSON-RPC request body: ${requestBody}") | ||
| 548 | } | ||
| 549 | |||
| 542 | // Handle POST requests for JSON-RPC | 550 | // Handle POST requests for JSON-RPC |
| 543 | if (!"POST".equals(method)) { | 551 | if (!"POST".equals(method)) { |
| 544 | response.setStatus(HttpServletResponse.SC_METHOD_NOT_ALLOWED) | 552 | response.setStatus(HttpServletResponse.SC_METHOD_NOT_ALLOWED) |
| ... | @@ -612,17 +620,8 @@ logger.info("Handling Enhanced SSE connection from ${request.remoteAddr}") | ... | @@ -612,17 +620,8 @@ logger.info("Handling Enhanced SSE connection from ${request.remoteAddr}") |
| 612 | return | 620 | return |
| 613 | } | 621 | } |
| 614 | 622 | ||
| 615 | // Try to get session ID from cookie | 623 | // Get session ID from Mcp-Session-Id header per MCP specification |
| 616 | String sessionId = null | 624 | String sessionId = request.getHeader("Mcp-Session-Id") |
| 617 | def cookies = request.getCookies() | ||
| 618 | if (cookies) { | ||
| 619 | for (cookie in cookies) { | ||
| 620 | if ("MCP-SESSION".equals(cookie.getName())) { | ||
| 621 | sessionId = cookie.getValue() | ||
| 622 | break | ||
| 623 | } | ||
| 624 | } | ||
| 625 | } | ||
| 626 | 625 | ||
| 627 | // Process MCP method using Moqui services with session ID if available | 626 | // Process MCP method using Moqui services with session ID if available |
| 628 | def result = processMcpMethod(rpcRequest.method, rpcRequest.params, ec, sessionId) | 627 | def result = processMcpMethod(rpcRequest.method, rpcRequest.params, ec, sessionId) | ... | ... |
-
Please register or sign in to post a comment