spring-projects / spring-projects/spring-ai
@McpTool annotated suspending functions are ignored in ASYNC server mode
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 9.5k
- Forks
- 2.9k
- Avg merge
- 1d 7h
- Merged PRs (30d)
- 6
Description
Bug description
Similar to https://github.com/spring-projects/spring-ai/issues/4392. Only @McpTool functions that return Mono, etc, are used in ASYNC mode. This should also include Kotlin suspend functions (as well as ideally Flow returning functions).
I've categorized it as a bug, but if Kotlin isn't officially supported (i.e. https://github.com/spring-projects/spring-ai/issues/3718) it may fit better as a feature request.
Environment
Java 24, Kotlin 2.2.10, Spring AI 1.1.0-M2
Steps to reproduce
Have a @McpTool method that returns Mono that works with an async server.
Change it to not return Mono but be suspend.
Expected behavior
The function is still detected.
Minimal Complete Reproducible example
@SpringBootApplication
class Application {
companion object {
@JvmStatic
fun main(args: Array<String>) {
runApplication<Application>(*args)
}
}
@McpTool
fun testTool(): Mono<String> {
return Mono.just("test")
}
@McpTool
suspend fun testTool2(): String {
return "test"
}
}
testTool is registered, testTool2 is not. Config:
spring:
ai:
mcp:
server:
type: ASYNC
annotation-scanner:
enabled: true
capabilities:
tool: true
resource: true
prompt: true
completion: true
stdio: false
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the @McpTool annotation scanner in ASYNC server mode and reproduce the difference between the Mono-returning testTool and suspend testTool2 from the issue. Trace why suspend functions are omitted, then verify that the suspend tool is detected and registered while the existing Mono case remains working.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, kotlin
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100