{"record":{"id":"4ce6eb1a96710656","repo":"alibaba/nacos","slug":"failed-to-parse-response-body","errorCode":null,"errorMessage":"Failed to parse response body","messagePattern":"Failed to parse response body","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"ai/src/main/java/com/alibaba/nacos/ai/service/McpExternalDataAdaptor.java","lineNumber":198,"sourceCode":"        int code = resp.statusCode();\n        if (!isSuccessStatus(code)) {\n            throw new IllegalStateException(\"HTTP \" + code + \" when fetching \" + pageUrl);\n        }\n        List<McpServerDetailInfo> servers = null;\n        String next = null;\n        try {\n            McpRegistryServerList listPage =\n                JacksonUtils.toObj(resp.body(), McpRegistryServerList.class);\n            if (listPage != null && listPage.getServers() != null) {\n                servers = listPage.getServers().stream()\n                    .map(this::adaptOfficialMcpServerFromResponse)\n                    .collect(Collectors.toList());\n            }\n            if (listPage != null && listPage.getMetadata() != null) {\n                next = listPage.getMetadata().getNextCursor();\n            }\n        } catch (Exception e) {\n            throw new IllegalStateException(\"Failed to parse response body\", e);\n        }\n        return new UrlPageResult(servers, next);\n    }\n    \n    private List<McpServerDetailInfo> fetchUrlServersAll(String urlData, String search)\n        throws Exception {\n        List<McpServerDetailInfo> collected = new ArrayList<>();\n        String cursor = null;\n        int pages = 0;\n        while (pages < MAX_PAGES_GUARD) {\n            pages++;\n            UrlPageResult page = fetchUrlPage(urlData, cursor, 30, search);\n            if (CollectionUtils.isNotEmpty(page.getServers())) {\n                collected.addAll(page.getServers());\n            }\n            String next = page.getNextCursor();\n            if (next == null) {\n                break;","sourceCodeStart":180,"sourceCodeEnd":216,"githubUrl":"https://github.com/alibaba/nacos/blob/9b989acdf181d00898f2e8839257bb2b2a3cefe3/ai/src/main/java/com/alibaba/nacos/ai/service/McpExternalDataAdaptor.java#L180-L216","documentation":"Thrown by McpExternalDataAdaptor.fetchUrlPage when the HTTP body from the registry cannot be deserialized into McpRegistryServerList. The response was 2xx but its JSON shape did not match the expected schema. It is an IllegalStateException wrapping the original parse exception.","triggerScenarios":"The endpoint returned valid JSON but not the McpRegistryServerList shape (missing 'servers'/'metadata'); the endpoint returned HTML (e.g. a login page or error page) with a 200 status; a registry API version change altered the payload contract.","commonSituations":"Pointing the URL import at a non-registry JSON endpoint; registry API contract drift after an upgrade; a transparent proxy returning an HTML interstitial with 200.","solutions":["Confirm the URL points to an endpoint implementing the official MCP registry openapi contract.","Fetch the URL manually and inspect the body to confirm it is the expected JSON shape.","Update the adaptor/SDK if the registry schema changed, or pin to a compatible registry version."],"exampleFix":"// before\n// url returns {\"items\": [...]} instead of {\"servers\": [...]} -> parse error\nString url = \"https://example.com/api/items\";\n\n// after\n// use an endpoint conforming to McpRegistryServerList schema\nString url = \"https://registry.modelcontextprotocol.org/v0/servers\";","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try { adaptor.fetchOfficialRegistryPage(url, c, l, s); }\ncatch (IllegalStateException e) { if (e.getMessage().contains(\"parse\")) reportSchemaMismatch(url); }","preventionTips":["Point URL imports only at endpoints implementing the official MCP registry openapi.","Inspect a raw response sample when integrating a new registry source."],"tags":["mcp","registry","serialization","illegal-state"],"backgroundTag":null,"analyzedSha":"9b989acdf181d00898f2e8839257bb2b2a3cefe3","analyzedAt":"2026-08-14T07:17:31.569Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}