Fix #1557: close MCP SSE connections before Tomcat graceful shutdown… - #1766
Merged
Merged
Conversation
… to prevent 30s stall on exit
|
igordayen
requested review from
alexheifetz,
azanux,
jamesward,
jasperblues,
johnsonr and
joshlong
and removed request for
jamesward
July 7, 2026 02:39
Contributor
Author
|
@fctg-stevendoolan confirmed the fix is working properly. |
alexheifetz
approved these changes
Jul 7, 2026
Contributor
Author
|
https://github.com/fctg-stevendoolan - please be aware of PR: #2071 , Mifration to Streamable HTTP. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Summary
Adds McpSseShutdownConfiguration to embabel-agent-mcpserver to fix a 30-second shutdown stall when using the MCP
server starter.
Closes: #1557
WebMvcSseServerTransportProvider keeps SSE connections open after MCP calls complete — by design, as SSE is a
persistent connection. On shutdown, Tomcat counts these as active requests and waits up to 30 seconds before
force-closing them. This fix listens for ContextClosedEvent (which fires before Tomcat's graceful shutdown phase) and
calls closeGracefully() to close all active sessions within a 5-second timeout.
Root cause
WebMvcSseServerTransportProvider.closeGracefully() exists in the MCP Java SDK but is not wired into the Spring
lifecycle by either the MCP Java SDK or Spring AI's autoconfiguration. The following upstream issues have been open
since late 2025 with no fix shipped:
Versions affected: spring-ai-starter-mcp-server-webmvc 1.1.7 / MCP Java SDK 0.18.2.
Design notes
registers the transport bean and always resolves to false. Optional injection defers the check until after all beans
are created.
provider iterates an empty session map.