{"record":{"id":"3d6efa9288ac4fcc","repo":"apache/shenyu","slug":"failed-to-extract-session-id-from-mcp-exchange-this-may","errorCode":null,"errorMessage":"Failed to extract session ID from MCP exchange. This may indicate an SDK compatibility issue. Tested SDK version: ${McpSessionHelper.getSupportedSdkVersion()}. Original error: ${e.getMessage()}","messagePattern":"Failed to extract session ID from MCP exchange\\. This may indicate an SDK compatibility issue\\. Tested SDK version: (.+?)\\. Original error: (.+?)","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"shenyu-plugin/shenyu-plugin-mcp-server/src/main/java/org/apache/shenyu/plugin/mcp/server/callback/ShenyuToolCallback.java","lineNumber":786,"sourceCode":"     * @return the session ID\n     * @throws IllegalStateException if the session ID is blank or an SDK compatibility issue blocks extraction\n     * @throws IllegalArgumentException if the exchange is missing required session state\n     */\n    private String extractSessionId(final McpSyncServerExchange mcpExchange) {\n        try {\n            final String sessionId = McpSessionHelper.getSessionId(mcpExchange);\n            if (StringUtils.hasText(sessionId)) {\n                LOG.debug(\"Extracted session ID: {}\", sessionId);\n                return sessionId;\n            }\n            throw new IllegalStateException(\"Session ID is empty – it should have been set earlier by handleMessageEndpoint\");\n        } catch (RuntimeException e) {\n            if (!isSdkCompatibilityError(e)) {\n                throw e;\n            }\n\n            // Re-throw SDK compatibility errors with additional context.\n            throw new IllegalStateException(\n                    \"Failed to extract session ID from MCP exchange. \"\n                    + \"This may indicate an SDK compatibility issue. \"\n                    + \"Tested SDK version: \" + McpSessionHelper.getSupportedSdkVersion() + \". \"\n                    + \"Original error: \" + e.getMessage(), e);\n        }\n    }\n\n    private boolean isSdkCompatibilityError(final RuntimeException exception) {\n        return exception instanceof IllegalStateException\n                && StringUtils.hasText(exception.getMessage())\n                && exception.getMessage().startsWith(SDK_COMPATIBILITY_ERROR_PREFIX);\n    }\n\n    /**\n     * Gets the origin ServerWebExchange for the given session ID.\n     *\n     * @param sessionId the session ID\n     * @return the origin ServerWebExchange","sourceCodeStart":768,"sourceCodeEnd":804,"githubUrl":"https://github.com/apache/shenyu/blob/567142e07261b3e615ae8850b30f4421f455cc5d/shenyu-plugin/shenyu-plugin-mcp-server/src/main/java/org/apache/shenyu/plugin/mcp/server/callback/ShenyuToolCallback.java#L768-L804","documentation":"Wrapper IllegalStateException thrown by ShenyuToolCallback.extractSessionId when the original RuntimeException is detected (via isSdkCompatibilityError, message prefixed 'SDK COMPATIBILITY ERROR') as an MCP SDK compatibility failure. It rethrows the underlying session-extraction error with the tested SDK version and the original message so the developer can identify a version mismatch between the io.modelcontextprotocol MCP SDK and what ShenYu supports (0.17.0).","triggerScenarios":"During extractSessionId, McpSessionHelper throws an SDK COMPATIBILITY ERROR IllegalStateException — i.e. reflection fields (McpSyncServerExchange.exchange / McpAsyncServerExchange.session) failed to resolve or an IllegalAccessException occurred — because the runtime MCP SDK version differs from 0.17.0 or blocks reflection.","commonSituations":"Dependency-management (BOM/Spring AI) upgrades pulling a newer MCP SDK; a security manager or JPMS module restrictions blocking setAccessible; snapshot dependency drift between admin and gateway modules.","solutions":["Pin the MCP SDK (io.modelcontextprotocol:mcp) to 0.17.0 / the version McpSessionHelper.SUPPORTED_SDK_VERSION reports and rebuild","Check startup logs for 'SDK COMPATIBILITY ERROR: Failed to resolve reflection fields' to see the missing field, then upgrade or downgrade ShenYu's mcp-server plugin to match the SDK","Remove the security manager or add JPMS --add-opens for io.modelcontextprotocol classes if reflection is blocked","Keep Spring AI (tested 1.1.2) and MCP SDK versions aligned via one BOM to avoid transitive drift"],"exampleFix":"// before (pom.xml)\n<dependency><groupId>io.modelcontextprotocol.sdk</groupId><artifactId>mcp</artifactId><version>0.99.0</version></dependency>\n// after\n<dependency><groupId>io.modelcontextprotocol.sdk</groupId><artifactId>mcp</artifactId><version>0.17.0</version></dependency>","handlingStrategy":"try-catch","validationCode":"if (!McpSessionHelper.isReflectionAvailable()) {\n    throw new IllegalStateException(\"MCP SDK incompatible; tested version: \" + McpSessionHelper.getSupportedSdkVersion());\n}","typeGuard":null,"tryCatchPattern":"try {\n    String sessionId = McpSessionHelper.getSessionId(mcpExchange);\n} catch (IllegalStateException e) {\n    if (e.getMessage().startsWith(\"SDK COMPATIBILITY ERROR\")\n            || e.getMessage().contains(\"Failed to extract session ID\")) {\n        LOG.error(\"MCP SDK version mismatch; tested: \" + McpSessionHelper.getSupportedSdkVersion(), e);\n    } else { throw e; }\n}","preventionTips":["Pin io.modelcontextprotocol:mcp and Spring AI to the tested versions via dependencyManagement","Fail fast at startup when McpSessionHelper.isReflectionAvailable() is false","Watch transitive dependency upgrades (Spring AI BOM) that silently bump the MCP SDK"],"tags":["mcp","sdk-compatibility","reflection","version-mismatch"],"backgroundTag":"incompatible-source-type","analyzedSha":"567142e07261b3e615ae8850b30f4421f455cc5d","analyzedAt":"2026-09-12T10:08:21.293Z","contentChangedAt":"2026-09-12T10:08:21.293Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}