spring-projects/spring-ai · error · IllegalArgumentException
First parameter must be of type LoggingLevel:
Error message
First parameter must be of type LoggingLevel:
What it means
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.
Source
Thrown at mcp/mcp-annotations/src/main/java/org/springframework/ai/mcp/annotation/method/logging/AbstractMcpLoggingMethodCallback.java:113
throw new IllegalArgumentException(
"Method must have either 1 parameter (LoggingMessageNotification) or 3 parameters (LoggingLevel, String, String): "
+ method.getName() + " in " + method.getDeclaringClass().getName() + " has "
+ parameters.length + " parameters");
}
// Check parameter types
if (parameters.length == 1) {
// Single parameter must be LoggingMessageNotification
if (!LoggingMessageNotification.class.isAssignableFrom(parameters[0].getType())) {
throw new IllegalArgumentException("Single parameter must be of type LoggingMessageNotification: "
+ method.getName() + " in " + method.getDeclaringClass().getName() + " has parameter of type "
+ parameters[0].getType().getName());
}
}
else {
// Three parameters must be LoggingLevel, String, String
if (!LoggingLevel.class.isAssignableFrom(parameters[0].getType())) {
throw new IllegalArgumentException("First parameter must be of type LoggingLevel: " + method.getName()
+ " in " + method.getDeclaringClass().getName() + " has parameter of type "
+ parameters[0].getType().getName());
}
if (!String.class.isAssignableFrom(parameters[1].getType())) {
throw new IllegalArgumentException("Second parameter must be of type String: " + method.getName()
+ " in " + method.getDeclaringClass().getName() + " has parameter of type "
+ parameters[1].getType().getName());
}
if (!String.class.isAssignableFrom(parameters[2].getType())) {
throw new IllegalArgumentException("Third parameter must be of type String: " + method.getName()
+ " in " + method.getDeclaringClass().getName() + " has parameter of type "
+ parameters[2].getType().getName());
}
}
}
/**
* Builds the arguments array for invoking the method.View on GitHub (pinned to 98a7beda4f)
Solutions
- Change the first parameter to LoggingLevel
- Or use the single-parameter form taking LoggingMessageNotification
Example fix
// before
@McpLogging(clients = "client1")
public void onLog(java.util.logging.Level level, String logger, String msg) { ... }
// after
@McpLogging(clients = "client1")
public void onLog(LoggingLevel level, String logger, String msg) { ... } Defensive patterns
Strategy: validation
Validate before calling
if (m.getParameterCount() == 3
&& !LoggingLevel.class.isAssignableFrom(m.getParameterTypes()[0])) {
throw new IllegalStateException("first param must be LoggingLevel");
} Type guard
static boolean firstParamIsLoggingLevel(Method m) {
return m.getParameterCount() == 3
&& LoggingLevel.class.isAssignableFrom(m.getParameterTypes()[0]);
} Prevention
- Import LoggingLevel from the MCP SDK, not a logging framework
- Follow the exact order (LoggingLevel, String, String)
When it happens
Trigger: Registering a @McpLogging method with signature (String, String, String) or (Level, String, String) instead of (LoggingLevel, String, String).
Common situations: 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.
Understand the failure class
Background: Type mismatch errors: IllegalArgumentException, TypeError and type guards across 150 open-source libraries — this error's family across 150 libraries.
Related errors
- Single parameter must be of type LoggingMessageNotification:
- Second parameter must be of type String:
- Third parameter must be of type String:
- Parameter must be of type List<McpSchema.Resource>:
- Method must not be null
AI-assisted analysis of spring-projects/spring-ai@98a7beda4f (2026-09-11).
Data as JSON: /api/errors/8af9855854843907.
Report an issue: GitHub.