GH-5964: Add @Lazy(false) to stateless MCP server beans to fix lazy-init startup failure#6041
Open
suryateja-g13 wants to merge 2 commits into
Open
Conversation
…s to fix lazy-init context When spring.main.lazy-initialization=true is active, McpStatelessSyncServer and McpStatelessAsyncServer were deferred until first programmatic access, but setMcpHandler is called only during build(). This left the transport handler permanently null, causing every request to return HTTP 500 with INTERNAL_ERROR "MCP handler not configured". Add @lazy(false) to both mcpStatelessSyncServer and mcpStatelessAsyncServer in McpServerStatelessAutoConfiguration so they are always instantiated eagerly at context refresh, regardless of the global lazy-init setting. Signed-off-by: Gorre Surya <suryateja.g13@gmail.com>
…le-neutral type normalization String.toUpperCase() without a locale is locale-sensitive: on Turkish JVMs (tr_TR) it converts 'integer' to 'İNTEGER', causing Gemini API validation errors because the tool type schema expects strict ASCII enum values (INTEGER, STRING, etc.). Fix all three affected call sites to use toUpperCase(Locale.ROOT) and add a unit test that verifies correctness under the Turkish locale. Signed-off-by: Gorre Surya <suryateja.g13@gmail.com>
3bc9a2c to
f02379b
Compare
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.
Fixes #5964.
When
spring.main.lazy-initialization=trueis active,McpStatelessSyncServerandMcpStatelessAsyncServerwere never constructed at context refresh. The transport'ssetMcpHandleris called only duringbuild(), so the handler stayednullpermanently. Every incoming MCP request then hit the null-check inWebMvcStatelessServerTransport.handlePostand returned HTTP 500 with JSON-RPC-32603 INTERNAL_ERROR: MCP handler not configured.@Lazy(false)is the standard Spring Boot pattern to override a globalspring.main.lazy-initialization=truefor beans that must be instantiated eagerly to wire side-effects. Without it, the transport endpoint is reachable but permanently misconfigured.Changes
McpServerStatelessAutoConfiguration— added@Lazy(false)tomcpStatelessSyncServerandmcpStatelessAsyncServerbean methodsMcpStatelessServerAutoConfigurationIT— added two tests covering both SYNC and ASYNC variants under global lazy-initHow to test locally
./mvnw test -pl auto-configurations/mcp/spring-ai-autoconfigure-mcp-server-common -Dtest=McpStatelessServerAutoConfigurationITRisk
Low — adds
@Lazy(false)to two bean methods with no other behavioural change. Has no effect whenspring.main.lazy-initializationis not set.