{"record":{"id":"31444f8ae3e02c82","repo":"spring-projects/spring-ai","slug":"second-parameter-must-be-of-type-string","errorCode":null,"errorMessage":"Second parameter must be of type String: ","messagePattern":"Second parameter must be of type String: ","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":118,"sourceCode":"\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.\n\t * <p>\n\t * This method constructs an array of arguments based on the method's parameter types\n\t * and the available values (exchange, notification).\n\t * @param method The method to build arguments for\n\t * @param exchange The server exchange","sourceCodeStart":100,"sourceCodeEnd":136,"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#L100-L136","documentation":"Thrown during parameter validation of an @McpLogging method callback when the callback declares multiple parameters and its second parameter's type is not assignable to String. The multi-parameter callback signature must be (LoggingLevel, String, String); this guard fires at method-registration time (not runtime message handling) because the second parameter carries the logger name and something else was declared. It is a fail-fast configuration error: the offending Method can never receive a valid logging notification.","triggerScenarios":"Registering a @McpLogging method like (LoggingLevel, Logger, String) or (LoggingLevel, Integer, String).","commonSituations":"Developer passes a Logger/LoggerName object instead of the plain logger-name String; misordered parameters from another framework's handler signature.","solutions":["Change the second parameter to String (the log message)"],"exampleFix":"// before\n@McpLogging(clients = \"client1\")\npublic void onLog(LoggingLevel level, Logger logger, String msg) { ... }\n// after\n@McpLogging(clients = \"client1\")\npublic void onLog(LoggingLevel level, String loggerName, String msg) { ... }","handlingStrategy":"validation","validationCode":"if (m.getParameterCount() == 3\n        && !String.class.isAssignableFrom(m.getParameterTypes()[1])) {\n    throw new IllegalStateException(\"second param must be String\");\n}","typeGuard":"static boolean secondParamIsString(Method m) {\n    return m.getParameterCount() == 3\n        && String.class.isAssignableFrom(m.getParameterTypes()[1]);\n}","tryCatchPattern":null,"preventionTips":["Second parameter is the logger name as a plain String","Do not pass Logger objects; obtain them inside the method"],"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-14T00:17:10.932Z"}