Bug description When connecting or reconnecting multiple MCP clients, the heap size increases until it reaches the maximum limit. Just to clarify, the MCP server works well when only one client is connected.

Please keep in mind that the MCP server is protected by OAuth 2.0, as defined in the MCP specification [1], and therefore it acts as an OAuth 2.0 resource server [2]. Typically, a short-lived access token is used, making client reconnection a common scenario.

[1] https://modelcontextprotocol.io/specification/2025-03-26 [2] https://docs.spring.io/spring-security/reference/servlet/oauth2/resource-server/jwt.html

Environment

<properties>
    <java.version>21</java.version>
     <spring-ai.version>1.0.0</spring-ai.version>
</properties>

Steps to reproduce 1. Launch a sample MCP Server. 2. Simulate the connection of multiple MCP clients. - In my case, I just use the official MCP inspector: npm exec @modelcontextprotocol/inspector - Click the reconnect button multiple times. Each time you do, you'll see the heap size increase indefinitely (simulating multiple client connections or reconnections). Image

  1. You will how the heap is increasing and the the error:
ERROR 59459 --- [nio-8080-exec-5] o.a.coyote.http11.Http11NioProtocol      : Failed to complete processing of a request
java.lang.OutOfMemoryError: Java heap space
  • And in Java VisualVM, the heap increases until it reaches the maximum.

Image

Expected behavior I would like a way to configure or close idle connections, or at least prevent the heap size from increasing, since this is just the reconnection of the MCP client—no operations are being performed.