Fix MCP initialize response to follow specification
- Remove sessionId field from initialize response body (not in MCP spec) - Set Mcp-Session-Id header in initialize response using visit ID - Maintain proper header setting for other methods that return sessionId - Ensure MCP protocol compliance for initialization flow
Showing
2 changed files
with
8 additions
and
5 deletions
| ... | @@ -107,8 +107,7 @@ | ... | @@ -107,8 +107,7 @@ |
| 107 | protocolVersion: "2025-06-18", | 107 | protocolVersion: "2025-06-18", |
| 108 | capabilities: serverCapabilities, | 108 | capabilities: serverCapabilities, |
| 109 | serverInfo: serverInfo, | 109 | serverInfo: serverInfo, |
| 110 | instructions: "This server provides access to Moqui ERP through MCP. For common business queries: Use screen_PopCommerce_screen_PopCommerceAdmin.Catalog for product catalog, screen_PopCommerce_screen_PopCommerceAdmin_Order.FindOrder for order status, screen_PopCommerce_screen_PopCommerceRoot.Customer for customer management, and screen_PopCommerce_screen_PopCommerceAdmin.QuickSearch for general searches. All screens support parameterized queries for filtering results.", | 110 | instructions: "This server provides access to Moqui ERP through MCP. For common business queries: Use screen_PopCommerce_screen_PopCommerceAdmin.Catalog for product catalog, screen_PopCommerce_screen_PopCommerceAdmin_Order.FindOrder for order status, screen_PopCommerce_screen_PopCommerceRoot.Customer for customer management, and screen_PopCommerce_screen_PopCommerceAdmin.QuickSearch for general searches. All screens support parameterized queries for filtering results." |
| 111 | sessionId: visit.visitId | ||
| 112 | ] | 111 | ] |
| 113 | 112 | ||
| 114 | ec.logger.info("MCP Initialize for user ${userId} (session ${sessionId}): capabilities negotiated") | 113 | ec.logger.info("MCP Initialize for user ${userId} (session ${sessionId}): capabilities negotiated") | ... | ... |
| ... | @@ -812,8 +812,11 @@ logger.info("Handling Enhanced SSE connection from ${request.remoteAddr}") | ... | @@ -812,8 +812,11 @@ logger.info("Handling Enhanced SSE connection from ${request.remoteAddr}") |
| 812 | } | 812 | } |
| 813 | 813 | ||
| 814 | // Set Mcp-Session-Id header BEFORE any response data (per MCP 2025-06-18 spec) | 814 | // Set Mcp-Session-Id header BEFORE any response data (per MCP 2025-06-18 spec) |
| 815 | if (result?.sessionId) { | 815 | // For initialize method, always use sessionId we have (from visit or header) |
| 816 | response.setHeader("Mcp-Session-Id", result.sessionId) | 816 | if (rpcRequest.method == "initialize" && sessionId) { |
| 817 | response.setHeader("Mcp-Session-Id", sessionId.toString()) | ||
| 818 | } else if (result?.sessionId) { | ||
| 819 | response.setHeader("Mcp-Session-Id", result.sessionId.toString()) | ||
| 817 | } | 820 | } |
| 818 | 821 | ||
| 819 | // Build JSON-RPC response for regular requests | 822 | // Build JSON-RPC response for regular requests |
| ... | @@ -868,7 +871,8 @@ logger.info("Handling Enhanced SSE connection from ${request.remoteAddr}") | ... | @@ -868,7 +871,8 @@ logger.info("Handling Enhanced SSE connection from ${request.remoteAddr}") |
| 868 | } | 871 | } |
| 869 | params.actualUserId = ec.user.userId | 872 | params.actualUserId = ec.user.userId |
| 870 | logger.info("Initialize - actualUserId: ${params.actualUserId}, sessionId: ${params.sessionId}") | 873 | logger.info("Initialize - actualUserId: ${params.actualUserId}, sessionId: ${params.sessionId}") |
| 871 | return callMcpService("mcp#Initialize", params, ec) | 874 | def serviceResult = callMcpService("mcp#Initialize", params, ec) |
| 875 | return serviceResult | ||
| 872 | case "ping": | 876 | case "ping": |
| 873 | // Simple ping for testing - bypass service for now | 877 | // Simple ping for testing - bypass service for now |
| 874 | return [pong: System.currentTimeMillis(), sessionId: visit?.visitId, user: ec.user.username] | 878 | return [pong: System.currentTimeMillis(), sessionId: visit?.visitId, user: ec.user.username] | ... | ... |
-
Please register or sign in to post a comment