Spring AI MCP客户端发起请求时出现"Multiple tools with the same name"错误的解决求助
Spring AI MCP客户端发起请求时出现"Multiple tools with the same name"错误的解决求助
大家好,我最近在搭建Spring AI的Model Context Protocol(MCP)客户端和服务端:客户端采用基于SSE HTTP协议的Standard MCP Client实现,服务端用的是WebMVC Server Transport。两个服务单独启动都正常,但当我通过MCP客户端发送请求时,就会触发Multiple tools with the same name found in ToolCallingChatOptions的异常。
我已经尝试过以下方案,但都没有解决问题:
- 从Spring AI自动配置中排除
SseWebFluxTransportAutoConfiguration.class和StdioTransportAutoConfiguration.class - 切换到WebFlux协议测试
- 分别使用Spring AI 1.0.0正式版和1.1.0-SNAPSHOT版本
下面是我的具体配置和错误信息,麻烦大家帮忙看看问题出在哪里,谢谢!
客户端详细配置
依赖配置(pom.xml)
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.ai</groupId> <artifactId>spring-ai-starter-mcp-client</artifactId> </dependency> <dependency> <groupId>org.springframework.ai</groupId> <artifactId>spring-ai-starter-model-ollama</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-devtools</artifactId> <scope>runtime</scope> <optional>true</optional> </dependency> <dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> <optional>true</optional> </dependency>
应用配置(application.properties)
server.port=8080 spring.ai.mcp.client.enabled=true spring.ai.mcp.client.name=mcp-client spring.ai.mcp.client.version=1.0.0 spring.ai.mcp.client.request-timeout=30s spring.ai.mcp.client.type=SYNC spring.ai.mcp.client.sse.connections.mcp-server.url=http://localhost:8082 spring.ai.mcp.client.toolcallback.enabled=true spring.ai.ollama.base-url= http://ip_address:port spring.ai.ollama.chat.options.model= model_version spring.ai.ollama.chat.temperature= 0.7 spring.ai.ollama.chat.max-tokens= 8192
启动类配置
@SpringBootApplication( exclude = { SseWebFluxTransportAutoConfiguration.class, StdioTransportAutoConfiguration.class } ) public class McpclientApplication { public static void main(String[] args) { SpringApplication.run(McpclientApplication.class, args); } }
服务端详细配置
依赖配置(pom.xml)
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.ai</groupId> <artifactId>spring-ai-starter-mcp-server-webmvc</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-devtools</artifactId> <scope>runtime</scope> <optional>true</optional> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-jdbc</artifactId> </dependency> <dependency> <groupId>org.postgresql</groupId> <artifactId>postgresql</artifactId> <scope>runtime</scope> </dependency> <dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> <optional>true</optional> </dependency>
应用配置(application.properties)
spring.application.name=mcp-server server.port=8082 spring.main.banner-mode=off logging.file.name=./logs/spring-boot-ai-mcp-server.log spring.ai.mcp.server.name=mcp-server spring.ai.mcp.server.version=0.0.1 spring.datasource.url= jdbc:postgresql://ip_address:port/db_name spring.datasource.driver-class-name=org.postgresql.Driver spring.datasource.username= spring.datasource.password=
完整错误栈
java.lang.IllegalStateException: Multiple tools with the same name (mcp_client_mcp_server_author2, mcp_client_mcp_server_PostgreSQL, mcp_client_mcp_server_author) found in ToolCallingChatOptions at org.springframework.ai.model.tool.ToolCallingChatOptions.validateToolCallbacks(ToolCallingChatOptions.java:146) ~[spring-ai-model-1.0.0.jar:1.0.0] at org.springframework.ai.chat.client.DefaultChatClientUtils.toChatClientRequest(DefaultChatClientUtils.java:106) ~[spring-ai-client-chat-1.0.0.jar:1.0.0] at org.springframework.ai.chat.client.DefaultChatClient$DefaultChatClientRequestSpec.call(DefaultChatClient.java:905) ~[spring-ai-client-chat-1.0.0.jar:1.0.0] at com.mcpclient.mcpclient.service.ChatService.askQuestion(ChatService.java:65) ~[classes/:na] at com.mcpclient.mcpclient.controller.ChatController.processPromptStreaming(ChatController.java:48) ~[classes/:na] at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103) ~[na:na] at java.base/java.lang.reflect.Method.invoke(Method.java:580) ~[na:na] at org.springframework.
从错误信息看,是有多个同名的工具(比如mcp_client_mcp_server_author相关的)被加载到了ToolCallingChatOptions中,但我并没有手动定义重复的工具。有没有同学遇到过类似的问题?或者能帮我定位下这个重复工具的来源吗?非常感谢!
内容来源于stack exchange
相关产品推荐
相关产品推荐

