Repository navigation
Replies: 2 comments
|
@herbertkb enable maven compiler parameter names with |
|
The root cause is that Java bytecode does not retain method parameter names by default — only the types are preserved. Without parameter names, Spring AI's MCP framework cannot map the incoming JSON arguments to your Fix for MavenAdd <plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<parameters>true</parameters>
<source>21</source>
<target>21</target>
</configuration>
</plugin>Fix for Gradle// build.gradle
tasks.withType(JavaCompile).configureEach {
options.compilerArgs << '-parameters'
}Or in Kotlin DSL: // build.gradle.kts
tasks.withType<JavaCompile>().configureEach {
options.compilerArgs.add("-parameters")
}Fix for Spring Boot projects specificallyIf you use Why the MCP Inspector works but unit tests don'tMCP Inspector invokes your tool through the full MCP protocol stack, which includes an additional layer that resolves argument names differently. Unit tests calling Verify the fix workedAfter recompiling, you can confirm parameter names are preserved: Method method = MyTool.class.getDeclaredMethod("myToolMethod", String.class);
System.out.println(method.getParameters()[0].getName()); // prints "word" instead of "arg0"If it prints |
Uh oh!
There was an error while loading. Please reload this page.
I'm trying to create a very simple Spring AI MCP Server and am having trouble with a basic unit test.
If I run it with
mvn spring-boot:runand test it with the MCP Inspector, it works fine.But if I try to unit test it in the same way as shown in this blog
and this example,
the argument received on the server side in the tool method is
null.The reproducer repo for my problem is here: https://github.com/herbertkb/reproducer-spring-ai-mcp-server/tree/main
All reactions