{"record":{"id":"5960df2cd6da0226","repo":"alibaba/nacos","slug":"parameter-validate-error-5960df","errorCode":"PARAMETER_VALIDATE_ERROR","errorMessage":"parameter `type` should be %s or %s, but was %s","messagePattern":"parameter `type` should be (.+?) or (.+?), but was (.+?)","errorType":"exception","errorClass":"NacosApiException","httpStatus":400,"severity":"warning","filePath":"ai/src/main/java/com/alibaba/nacos/ai/remote/handler/McpServerEndpointRequestHandler.java","lineNumber":147,"sourceCode":"        Service service = Service.newService(request.getNamespaceId(), serviceRef.getGroupName(),\n            serviceRef.getServiceName(), true);\n        switch (request.getType()) {\n            case AiRemoteConstants.REGISTER_ENDPOINT:\n                LOGGER.info(\"[{}] register endpoint {}:{} version {} for mcp server: {}\",\n                    meta.getConnectionId(),\n                    request.getAddress(), request.getPort(), request.getVersion(),\n                    request.getMcpName());\n                doRegister(service, instance, meta);\n                break;\n            case AiRemoteConstants.DE_REGISTER_ENDPOINT:\n                LOGGER.info(\"[{}] de-register endpoint {}:{} version {} for mcp server: {}\",\n                    meta.getConnectionId(),\n                    request.getAddress(), request.getPort(), request.getVersion(),\n                    request.getMcpName());\n                doDeregister(service, instance, meta);\n                break;\n            default:\n                throw new NacosApiException(NacosException.INVALID_PARAM,\n                    ErrorCode.PARAMETER_VALIDATE_ERROR,\n                    String.format(\"parameter `type` should be %s or %s, but was %s\",\n                        AiRemoteConstants.REGISTER_ENDPOINT, AiRemoteConstants.DE_REGISTER_ENDPOINT,\n                        request.getType()));\n        }\n        McpServerEndpointResponse response = new McpServerEndpointResponse();\n        response.setType(request.getType());\n        return response;\n    }\n    \n    private Instance buildInstance(McpServerEndpointRequest request) throws NacosApiException {\n        Instance instance = new Instance();\n        instance.setIp(request.getAddress());\n        instance.setPort(request.getPort());\n        instance.validate();\n        if (StringUtils.isNotBlank(request.getVersion())) {\n            instance.getMetadata().put(VERSION_TAG, request.getVersion());\n        }","sourceCodeStart":129,"sourceCodeEnd":165,"githubUrl":"https://github.com/alibaba/nacos/blob/9b989acdf181d00898f2e8839257bb2b2a3cefe3/ai/src/main/java/com/alibaba/nacos/ai/remote/handler/McpServerEndpointRequestHandler.java#L129-L165","documentation":"Thrown by the default branch of the type switch in McpServerEndpointRequestHandler.doHandler() when request.getType() is neither REGISTER_ENDPOINT ('registerEndpoint') nor DE_REGISTER_ENDPOINT ('deregisterEndpoint'). Mapped to PARAMETER_VALIDATE_ERROR with an INVALID_PARAM top-level code; caught and placed into the response error info.","triggerScenarios":"A gRPC McpServerEndpointRequest whose type field is unset, null, or any string other than the two recognized constants. The message reports the actual value received.","commonSituations":"Client sets type via a raw string and mistypes it; client leaves type null expecting a default; version skew where the client uses a constant that was renamed; a BATCH_REGISTER_ENDPOINT value mistakenly sent to the single-endpoint handler.","solutions":["Set request.setType to AiRemoteConstants.REGISTER_ENDPOINT or AiRemoteConstants.DE_REGISTER_ENDPOINT.","Use the SDK's typed enum/constants rather than hand-coded strings.","Confirm you are calling the right handler (single register/deregister, not batch)."],"exampleFix":"// before\nreq.setType(\"register\"); // wrong literal\n\n// after\nreq.setType(AiRemoteConstants.REGISTER_ENDPOINT); // \"registerEndpoint\"","handlingStrategy":"validation","validationCode":"String t = request.getType();\nif (!AiRemoteConstants.REGISTER_ENDPOINT.equals(t)\n    && !AiRemoteConstants.DE_REGISTER_ENDPOINT.equals(t)) {\n    throw new IllegalArgumentException(\n        \"type must be registerEndpoint or deregisterEndpoint, was: \" + t);\n}","typeGuard":null,"tryCatchPattern":"McpServerEndpointResponse resp = handler.handle(request, meta);\nif (ErrorCode.PARAMETER_VALIDATE_ERROR.getCode() == resp.getDetailErrCode()\n    && resp.getErrMsg().contains(\"type should\")) {\n    // fix the type constant and retry\n}","preventionTips":["Use AiRemoteConstants.REGISTER_ENDPOINT / DE_REGISTER_ENDPOINT, never raw strings.","Do not send BATCH_REGISTER_ENDPOINT to the single-endpoint handler.","Unit-test request builders to assert the type is one of the two allowed values."],"tags":["ai","mcp-server","grpc","validation","endpoint","parameter"],"backgroundTag":null,"analyzedSha":"9b989acdf181d00898f2e8839257bb2b2a3cefe3","analyzedAt":"2026-08-14T07:17:31.569Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}