Skip to content

Fix MCP annotated specs with early server initialization#6542

Open
hutiefang76 wants to merge 1 commit into
spring-projects:mainfrom
hutiefang76:codex/spring-ai-6535-mcp-bpp-order
Open

Fix MCP annotated specs with early server initialization#6542
hutiefang76 wants to merge 1 commit into
spring-projects:mainfrom
hutiefang76:codex/spring-ai-6535-mcp-bpp-order

Conversation

@hutiefang76

Copy link
Copy Markdown
Contributor

Description

Fixes #6535.

When an application bean injects McpAsyncServer early, the server specification beans can be created before regular MCP annotated beans have been initialized by the annotation-scanning BeanPostProcessor. In that ordering, the specification factory snapshots an empty ServerMcpAnnotatedBeans registry and the async server starts without the annotated @McpTool methods.

This change initializes beans that declare the relevant MCP annotations before converting the registry into server specifications. The registry now also de-duplicates by bean identity while still allowing the same bean to be registered under additional annotation types later.

Testing

  • ./mvnw -Dmaven.build.cache.enabled=false -pl mcp/mcp-annotations,auto-configurations/mcp/spring-ai-autoconfigure-mcp-server-common -am -Dtest=AbstractMcpAnnotatedBeansTests,AbstractAnnotatedMethodBeanPostProcessorTests,McpServerAutoConfigurationIT#syncServerSpecificationConfiguration+asyncServerSpecificationConfiguration+asyncServerSpecificationConfigurationWithEarlyServerConsumer -Dsurefire.failIfNoSpecifiedTests=false test
  • ./mvnw -Dmaven.build.cache.enabled=false -pl mcp/mcp-annotations,auto-configurations/mcp/spring-ai-autoconfigure-mcp-server-common -am test
  • git diff --check

Signed-off-by: hutiefang76 <137664623+hutiefang76@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

@McpTool beans silently fail to register when another bean injects McpAsyncServer before BeanPostProcessor is ready (ASYNC mode)

2 participants