{"record":{"id":"8af9855854843907","repo":"spring-projects/spring-ai","slug":"first-parameter-must-be-of-type-logginglevel","errorCode":null,"errorMessage":"First parameter must be of type LoggingLevel: ","messagePattern":"First parameter must be of type LoggingLevel: ","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"mcp/mcp-annotations/src/main/java/org/springframework/ai/mcp/annotation/method/logging/AbstractMcpLoggingMethodCallback.java","lineNumber":113,"sourceCode":"\t\t\tthrow new IllegalArgumentException(\n\t\t\t\t\t\"Method must have either 1 parameter (LoggingMessageNotification) or 3 parameters (LoggingLevel, String, String): \"\n\t\t\t\t\t\t\t+ method.getName() + \" in \" + method.getDeclaringClass().getName() + \" has \"\n\t\t\t\t\t\t\t+ parameters.length + \" parameters\");\n\t\t}\n\n\t\t// Check parameter types\n\t\tif (parameters.length == 1) {\n\t\t\t// Single parameter must be LoggingMessageNotification\n\t\t\tif (!LoggingMessageNotification.class.isAssignableFrom(parameters[0].getType())) {\n\t\t\t\tthrow new IllegalArgumentException(\"Single parameter must be of type LoggingMessageNotification: \"\n\t\t\t\t\t\t+ method.getName() + \" in \" + method.getDeclaringClass().getName() + \" has parameter of type \"\n\t\t\t\t\t\t+ parameters[0].getType().getName());\n\t\t\t}\n\t\t}\n\t\telse {\n\t\t\t// Three parameters must be LoggingLevel, String, String\n\t\t\tif (!LoggingLevel.class.isAssignableFrom(parameters[0].getType())) {\n\t\t\t\tthrow new IllegalArgumentException(\"First parameter must be of type LoggingLevel: \" + method.getName()\n\t\t\t\t\t\t+ \" in \" + method.getDeclaringClass().getName() + \" has parameter of type \"\n\t\t\t\t\t\t+ parameters[0].getType().getName());\n\t\t\t}\n\t\t\tif (!String.class.isAssignableFrom(parameters[1].getType())) {\n\t\t\t\tthrow new IllegalArgumentException(\"Second parameter must be of type String: \" + method.getName()\n\t\t\t\t\t\t+ \" in \" + method.getDeclaringClass().getName() + \" has parameter of type \"\n\t\t\t\t\t\t+ parameters[1].getType().getName());\n\t\t\t}\n\t\t\tif (!String.class.isAssignableFrom(parameters[2].getType())) {\n\t\t\t\tthrow new IllegalArgumentException(\"Third parameter must be of type String: \" + method.getName()\n\t\t\t\t\t\t+ \" in \" + method.getDeclaringClass().getName() + \" has parameter of type \"\n\t\t\t\t\t\t+ parameters[2].getType().getName());\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Builds the arguments array for invoking the method.","sourceCodeStart":95,"sourceCodeEnd":131,"githubUrl":"https://github.com/spring-projects/spring-ai/blob/98a7beda4f29d80a71c5837eb4053b03a93a46f7/mcp/mcp-annotations/src/main/java/org/springframework/ai/mcp/annotation/method/logging/AbstractMcpLoggingMethodCallback.java#L95-L131","documentation":"Parameter validation in AbstractMcpLoggingMethodCallback.validateParameters for a 3-parameter logging handler: parameters[0] is not a LoggingLevel, so the (LoggingLevel, String, String) signature convention is violated.","triggerScenarios":"Registering a @McpLogging method with signature (String, String, String) or (Level, String, String) instead of (LoggingLevel, String, String).","commonSituations":"Developer uses java.util.logging.Level or a custom severity enum instead of the MCP SDK's LoggingLevel; parameter order confused with (message, level, logger) conventions from other logging frameworks.","solutions":["Change the first parameter to LoggingLevel","Or use the single-parameter form taking LoggingMessageNotification"],"exampleFix":"// before\n@McpLogging(clients = \"client1\")\npublic void onLog(java.util.logging.Level level, String logger, String msg) { ... }\n// after\n@McpLogging(clients = \"client1\")\npublic void onLog(LoggingLevel level, String logger, String msg) { ... }","handlingStrategy":"validation","validationCode":"if (m.getParameterCount() == 3\n        && !LoggingLevel.class.isAssignableFrom(m.getParameterTypes()[0])) {\n    throw new IllegalStateException(\"first param must be LoggingLevel\");\n}","typeGuard":"static boolean firstParamIsLoggingLevel(Method m) {\n    return m.getParameterCount() == 3\n        && LoggingLevel.class.isAssignableFrom(m.getParameterTypes()[0]);\n}","tryCatchPattern":null,"preventionTips":["Import LoggingLevel from the MCP SDK, not a logging framework","Follow the exact order (LoggingLevel, String, String)"],"tags":["mcp","logging","parameter-type","java"],"backgroundTag":"type-mismatch","analyzedSha":"98a7beda4f29d80a71c5837eb4053b03a93a46f7","analyzedAt":"2026-09-11T14:15:49.441Z","contentChangedAt":"2026-09-11T14:15:49.441Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}