Please do a quick search on GitHub issues first, there might be already a duplicate issue for the one you are about to create. If the bug is trivial, just go ahead and create the issue. Otherwise, please take a few moments and fill in the following sections:
Bug description The parameter[name, value] is always null
@Tool(description = "get combo data")
public ComboDto getCombo(String name, String value) {
log.info("==>name: {},value: {}", name, value);
return new ComboDto(name, "Item." + value);
}
client Test
@Test
void getCombo() {
Map<String, Object> params = new HashMap<>();
params.put("name", "label");
params.put("value", "Root");
McpSchema.CallToolResult result = mcpSyncClients.callTool(new McpSchema.CallToolRequest("getCombo", params));
log.info("==>result: {}", JsonUtils.toJsonString(result));
}
Client config
spring:
ai:
mcp:
client:
enabled: true
name: mcp-client
version: v1.0.0
request-timeout: 10s
type: sync
sse:
connections:
server1:
url: http://localhost:18080
MethodToolCallback(Line number 138), Object rawArgument = toolInputArguments.get(parameter.getName())
is null
private Object[] buildMethodArguments(Map<String, Object> toolInputArguments, @Nullable ToolContext toolContext) {
return Stream.of(toolMethod.getParameters()).map(parameter -> {
if (parameter.getType().isAssignableFrom(ToolContext.class)) {
return toolContext;
}
Object rawArgument = toolInputArguments.get(parameter.getName());
return buildTypedArgument(rawArgument, parameter.getType());
}).toArray();
}
Environment Please provide as many details as possible: Spring AI version, Java version, which vector store you use if any, etc
<dependency>
<groupId>org.springframework.ai</groupId>
<artifactId>spring-ai-starter-mcp-server-webmvc</artifactId>
<version>1.0.0-M7</version>
</dependency>
jdk
openjdk version "17.0.11" 2024-04-16
OpenJDK Runtime Environment Temurin-17.0.11+9 (build 17.0.11+9)
OpenJDK 64-Bit Server VM Temurin-17.0.11+9 (build 17.0.11+9, mixed mode, sharing)
Steps to reproduce Steps to reproduce the issue.
Expected behavior MCP server can obtain the passed parameters normally.
Can anyone help me?
Minimal Complete Reproducible example Please provide a failing test or a minimal complete verifiable example that reproduces the issue. Bug reports that are reproducible will take priority in resolution over reports that are not reproducible.
Comment From: tzolov
@leelance, the shared information is not enough to understand the issue.
Here is an example of webmvc server with @Tools
: https://github.com/spring-projects/spring-ai-examples/tree/main/model-context-protocol/weather/starter-webmvc-server and the related manual tests: https://github.com/spring-projects/spring-ai-examples/tree/main/model-context-protocol/weather/starter-webmvc-server/src/test/java/org/springframework/ai/mcp/sample/client
Here: https://github.com/spring-projects/spring-ai-examples/tree/main/model-context-protocol/dynamic-tool-update/client and here: https://github.com/spring-projects/spring-ai-examples/tree/main/model-context-protocol/sampling/mcp-sampling-client are examples for implementing spring ai client with mcp boot starters.
Comment From: leelance
on the MCP server and define a tools method with two parameters [public ComboDto getCombo(String name, String value)]. I use the MCP client to simulate the call, but the server cannot obtain the parameter value(name/value is null). I checked the source code because when the source code reflects, it is obtained based on the parameter name [Object rawArgument=toolInputArguments. get (parameter. getName())]
Comment From: lianneli
on the MCP server and define a tools method with two parameters [public ComboDto getCombo(String name, String value)]. I use the MCP client to simulate the call, but the server cannot obtain the parameter value(name/value is null). I checked the source code because when the source code reflects, it is obtained based on the parameter name [Object rawArgument=toolInputArguments. get (parameter. getName())]
I ran into the same problem. When I used the log.info(t.getToolDefinition().inputSchema()) tool to print the mcp server function's schema information, I noticed it only showed arg0
and arg1
instead of name
andvalue
. So after changing the parameter keys to arg0
and arg1
, the arguments were passed successfully.