Skip to content

@McpTool annotated beans are not registered in MCP server (spring-ai 1.1.0-M1) despite annotation scanner property enabled #4392

@oburgosm

Description

@oburgosm

Bug description
When implementing an MCP server using Spring AI 1.1.0-M1 and annotating beans with @McpTool, the tools are not registered at server startup, even though the property spring.ai.mcp.server.annotation-scanner.enabled is explicitly set to true. The documentation (https://docs.spring.io/spring-ai/reference/1.1/api/mcp/mcp-server-boot-starter-docs.html) suggests that this should work without manual registration.

As a workaround, tools are registered if I annotate beans with @Tool and create a bean of type ToolCallbackProvider that manually passes the beans (e.g., via MethodToolCallbackProvider.builder().toolObjects(productService, timeService).build()). This workaround was standard in 1.0.x, but the documentation for 1.1.x indicates that @McpTool with annotation scanning should suffice.

This points to a problem either in the property spring.ai.mcp.server.annotation-scanner.enabled or the annotation scanning functionality for MCP tools in 1.1.x.

Environment

  • Spring AI version: 1.1.0-M1
  • Java version: 21
  • MCP server transport: HTTP Streamable
  • Property set: spring.ai.mcp.server.annotation-scanner.enabled=true
  • Beans annotated with @McpTool

Steps to reproduce

  1. Create a Spring Boot MCP server with Spring AI 1.1.0-M1.
  2. Annotate beans with @McpTool and define tool methods.
  3. Set spring.ai.mcp.server.annotation-scanner.enabled=true.
  4. Start the server.
  5. Observe that tools are not registered.
  6. Switch to @Tool annotation and manually register beans via a ToolCallbackProvider bean; tools are registered as expected.

Expected behavior
Beans annotated with @McpTool should be automatically registered as tools when the annotation scanner is enabled, per documentation, without requiring manual registration.

Minimal Complete Reproducible example

@Bean
ToolCallbackProvider productTools(ProductService productService, TimeService timeService) {
  return MethodToolCallbackProvider.builder()
      .toolObjects(productService, timeService)
      .build();
}

But this should not be necessary when using @McpTool and the annotation scanner property.


Please advise if there is a known issue or if a fix is planned for future releases.

Metadata

Metadata

Labels

MCPbugSomething isn't working

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions