Skip to content

使用spring-ai-starter-mcp-client sse方式连接mcp server,重启mcp server后,以前的client不会自动重连。 #2740

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
hymmyh opened this issue Apr 15, 2025 · 8 comments
Labels

Comments

@hymmyh
Copy link

hymmyh commented Apr 15, 2025

1.0.0-M7 版本:
client 采用sse 方式连接上 mcp server,可以正常运行;这个时候重启 mcp server, client 端就不会重连 mcp server,导致一直报错
reactor.core.Exceptions$ReactiveException: java.util.concurrent.TimeoutException: Did not observe any item or terminal signal within 20000ms in 'source(MonoCreate)' (and no fallback has been configured)
at reactor.core.Exceptions.propagate(Exceptions.java:410)
at reactor.core.publisher.BlockingSingleSubscriber.blockingGet(BlockingSingleSubscriber.java:102)

怎么设置重连mcp server?

@hymmyh hymmyh changed the title 使用spring-ai-starter-mcp-client sse方式连接mcp server,重启mcp server以后以前的client不会自动重连。 使用spring-ai-starter-mcp-client sse方式连接mcp server,重启mcp server后,以前的client不会自动重连。 Apr 15, 2025
@Forest-Fairy
Copy link

应该只能重新创建一个mcpclient对象 或者重新实现一个client可以重连的

@lyxfn
Copy link

lyxfn commented Apr 15, 2025

I also encountered this problem. Every time I restarted mcp-server, I needed to restart the client to recover. If I only restarted mcp-server, a 404 error would appear. I didn't see any reconnection configuration in the official documentation.

org.springframework.web.reactive.function.client.WebClientResponseException$NotFound: 404 Not Found from POST http://localhost:9080/mcp/message
at org.springframework.web.reactive.function.client.WebClientResponseException.create(WebClientResponseException.java:324) ~[spring-webflux-6.1.14.jar:6.1.14]
Suppressed: reactor.core.publisher.FluxOnAssembly$OnAssemblyException:
Error has been observed at the following site(s):
*__checkpoint ⇢ 404 NOT_FOUND from POST http://localhost:9080/mcp/message [DefaultWebClient]

@SuperWuYou
Copy link

这都不用等服务器重启,我连着高德的MCP,等个几分钟就断开了,然后他就不连了.... 怎么办???

@hymmyh
Copy link
Author

hymmyh commented Apr 16, 2025

这都不用等服务器重启,我连着高德的MCP,等个几分钟就断开了,然后他就不连了.... 怎么办???

目前可以不用autoconfigure,自己在代码中实现 mcpClient 的初始化,用mcpClient.ping() 来判断是否正常,不正常重新实例化一个新的mcpClient。

@zhouwenjun-hub
Copy link

这都不用等服务器重启,我连着高德的MCP,等个几分钟就断开了,然后他就不连了.... 怎么办???

目前可以不用autoconfigure,自己在代码中实现 mcpClient 的初始化,用mcpClient.ping() 来判断是否正常,不正常重新实例化一个新的mcpClient。

大佬,请问有示例代码么?我尝试这个方案还是有问题,重新实例化时,mcp server会报错: session is null

@SuperWuYou
Copy link

@zhouwenjun-hub 去看看autoconfigure包是怎么写的你就会了。

@dyrnq
Copy link

dyrnq commented Apr 17, 2025

stare

@luojinggit
Copy link

luojinggit commented Apr 18, 2025

这都不用等服务器重启,我连着高德的MCP,等个几分钟就断开了,然后他就不连了.... 怎么办???

目前可以不用autoconfigure,自己在代码中实现 mcpClient 的初始化,用mcpClient.ping() 来判断是否正常,不正常重新实例化一个新的mcpClient。

麻烦您能不能贴一下关键代码,我也遇到这个问题,我重新调用mcpSyncClient.initialize(); 方法还是无法重连。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

8 participants