Bug description Integrating and calling an MCP Tool with an existing Spring AI application that uses a ToolContext will result in an UnsupportedOperationException.
Environment Spring AI 1.0.0-M6
Steps to reproduce
- Integrate https://github.com/modelcontextprotocol/servers/tree/main/src/everything into a Spring AI application using https://docs.spring.io/spring-ai/reference/api/mcp/mcp-client-boot-starter-docs.html
- Set the ToolContext in your Spring AI application
- Call one of the tools provided by the everything MCP server, e.g. printEnv
- Observe "UnsupportedOperationException: Tool context is not supported!" for SyncMcpToolCallback
Exception is raised here: https://github.com/spring-projects/spring-ai/blob/2394ac82ad1229ffefa70e6a338d249890df24b7/spring-ai-core/src/main/java/org/springframework/ai/tool/ToolCallback.java#L57
Expected behavior The MCP printEnv tool is called, ignoring the ToolContext (assuming this concept is not supported in MCP).
Comment From: tzolov
Thanks @henningSaulCM , I believe this is a know issue and should have been resolved by the https://github.com/spring-projects/spring-ai/commit/82d98b6b485a8d98caf7c9dd17ba0b9f2ab011bd Can you test with 1.0.0-SNAPSHOT please?
Comment From: tzolov
Likely the same as https://github.com/spring-projects/spring-ai/issues/2337
Comment From: henningSaulCM
Hi @tzolov, thanks for chiming in.
I just tried with 1.0.0-SNAPSHOT (spring-ai-core-1.0.0-20250307.123602-1325.jar) and it seems I'm still getting the UnsupportedOperationException.
Stacktrace (excerpt):
java.lang.UnsupportedOperationException: Tool context is not supported!
at org.springframework.ai.tool.ToolCallback.call(ToolCallback.java:57)
at org.springframework.ai.model.tool.DefaultToolCallingManager.executeToolCall(DefaultToolCallingManager.java:226)
at org.springframework.ai.model.tool.DefaultToolCallingManager.executeToolCalls(DefaultToolCallingManager.java:138)
at org.springframework.ai.openai.OpenAiChatModel.lambda$internalStream$10(OpenAiChatModel.java:442)
at reactor.core.publisher.FluxFlatMap$FlatMapMain.onNext(FluxFlatMap.java:388)
...
Any thoughts?