Skip to content

Conversation

@wilocu
Copy link
Contributor

@wilocu wilocu commented Aug 7, 2025

#4055

I believe the issue occurs because MCP server beans aren't created when Spring Boot lazy initialization is enabled, causing NPE when accessing MCP
endpoints.

Changes

  • Added @Lazy(false) to force eager initialization of MCP server beans
  • Added tests to verify lazy initialization compatibility

This seems to resolve the reported issue while maintaining existing functionality.

Test plan

  • Added lazy initialization tests
  • Verified existing tests still pass
  • Confirmed fix appears to resolve the NPE

3 files were modified:

  1. McpServerAutoConfiguration.java - Added @lazy(false) annotations to force eager initialization
  2. McpServerAutoConfigurationIT.java - Added lazy initialization tests
  3. McpWebMvcServerAutoConfigurationIT.java - Added WebMvc transport compatibility test

Signed-off-by: Mattia Pasetto [email protected]

I am still pretty new to contributions, please double check and let me know of any errors.

The issue occurred because MCP server beans (McpSyncServer/McpAsyncServer) were not
being created when Spring Boot lazy initialization was enabled. This caused:
- Missing tool registration logs
- Null sessionFactory in transport providers
- NPE when accessing MCP endpoints (/sse, /mcp/message)

Changes:
- Added @lazy(false) to McpSyncServer and McpAsyncServer beans to force eager initialization
- Added comprehensive tests for lazy initialization compatibility
- Verified existing functionality remains unchanged

The fix ensures MCP servers work correctly regardless of lazy initialization settings,
maintaining backward compatibility while resolving the reported issue.

Signed-off-by: Mattia Pasetto <[email protected]>
@markpollack markpollack added this to the 1.1.0.M4 milestone Oct 22, 2025
@markpollack
Copy link
Member

Related to #4671

@ilayaperumalg ilayaperumalg changed the title Issue 4055 fix MCP Server Lazy initialisation issue Oct 24, 2025
@ilayaperumalg ilayaperumalg modified the milestones: 1.1.0.M4, 1.1.0.RC1 Oct 30, 2025
@ilayaperumalg
Copy link
Member

@wilocu Thanks for the PR and your interest in contributing! We believe that the issue #4055 is addressed via 2a2f155 #4802 which will be part of 1.1.0-RC1. Please take a look and let us know if you see any issues.

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants