spring-projects / spring-projects/spring-ai

spring-ai-starter-mcp-server-webmvc:1.1.0 McpTool cannot found in StatelessServerSpecificationFactoryAutoConfiguration#toolSpecs

Open
#4,882 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

status: waiting-for-triage
Dominant language
Java
Stars
9.5k
Forks
2.9k
Avg merge
1d 7h
Merged PRs (30d)
6

Description

Hi,
My configuration is:
spring-ai-starter-mcp-server-webmvc:1.1.0
spring.ai.mcp.server.protocol = STATELESS
spring.ai.mcp.server.type= SYNC

McpTool was not scanned in case of AOP.

Example:

@Service
public class CaseMcpTool
{

@Tool(description = "{Get balance of case reference . Balance of case reference . Method load balance of the case reference.")
@McpTool(description = "Get balance of case reference . Balance of case reference . Method load balance of the case reference.")
public String findBalanceByCaseReference(@McpToolParam(description = "Case reference .") String reference)
{
return "1000";
}
}

In AbstractAnnotatedMethodBeanPostProcessor#postProcessAfterInitialization the bean "caseMcpTool" is found and register.
But in StatelessServerSpecificationFactoryAutoConfiguration#toolSpecs -> SyncStatelessMcpToolProvider.getToolSpecifications there is an issue here:
public List getToolSpecifications() {

	List<SyncToolSpecification> toolSpecs = this.toolObjects.stream()
		.map(toolObject -> Stream.of(this.doGetClassMethods(toolObject))
			.filter(method -> **method.isAnnotationPresent(McpTool.class)**)

method.isAnnotationPresent(McpTool.class)) cannot find McpTool annotation in case of AOP .

Maybe you have to use AopUtils.isAopProxy(toolObject)

When I add this ToolCallbackProvider , all is Ok:

@Bean
public ToolCallbackProvider imxTools() {
return MethodToolCallbackProvider.builder().toolObjects(new CaseMcpTool()).build();
}

Without ToolCallbackProvider , McpTool didn't work.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with StatelessServerSpecificationFactoryAutoConfiguration#toolSpecs and SyncStatelessMcpToolProvider#getToolSpecifications, then trace how AbstractAnnotatedMethodBeanPostProcessor registers the AOP-proxied bean. Reproduce the configuration with CaseMcpTool and verify that its @McpTool method is discovered without manually defining a ToolCallbackProvider; preserve coverage for the proxied case.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, spring
Domain
api, backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.