Skip to content

Fix MCP stateless server lazy initialization#6033

Open
jewoodev wants to merge 1 commit into
spring-projects:mainfrom
jewoodev:fix/gh-5964-mcp-stateless-lazy-init
Open

Fix MCP stateless server lazy initialization#6033
jewoodev wants to merge 1 commit into
spring-projects:mainfrom
jewoodev:fix/gh-5964-mcp-stateless-lazy-init

Conversation

@jewoodev
Copy link
Copy Markdown
Contributor

@jewoodev jewoodev commented May 14, 2026

Summary

Closes #5964.

  • Why: With global lazy init, the stateless server beans become lazy, so the transport handler is never wired and stateless requests fail with MCP handler not configured.

  • Fix: Force eager creation on both stateless server bean methods. The async bean has the same failure mode as the reported sync case, so the fix is applied symmetrically.

Tests

Added regression coverage in McpStatelessServerAutoConfigurationIT for:

  • sync server eager creation under LazyInitializationBeanFactoryPostProcessor
  • async server eager creation under the same post-processor

Each test asserts beanFactory.containsSingleton(...) after refresh, verifying eager instantiation without triggering the bean by lookup.

./mvnw -pl auto-configurations/mcp/spring-ai-autoconfigure-mcp-server-common test \
    -Dtest='McpStatelessServerAutoConfigurationIT'

Scope

This PR covers the stateless path reported in #5964. The SSE / stateful path tracked in #3868 is outside this PR.

Signed-off-by: jewoodev <jewoos15@naver.com>
@jewoodev
Copy link
Copy Markdown
Contributor Author

For maintainers comparing this with #6041: the production fix is the same in both PRs (@Lazy(false) on the stateless sync/async server beans).

The only meaningful difference is the regression test. This PR asserts beanFactory.containsSingleton(...) after refresh, so it verifies eager instantiation without triggering the bean by lookup. That directly covers the handler-wiring side effect required by #5964.

Happy to align or close this PR if #6041 is preferred.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

McpStatelessSyncServer not initialized under spring.main.lazy-initialization=true, causing "MCP handler not configured" on every request

1 participant