Bug description

There is a special case in MCP tools, where excluding the ToolCallingAutoConfiguration would be desirable. In a regular Boot application, this would be achieved through:

@SpringBootApplication(exclude = { ToolCallingAutoConfiguration.class })
public class SampleMcpClientWebfluxApplication {

//...

}

However, this does exclude the configuration, because, in my application, I use Anthropic and AnthropicChatAutoConfiguration. But that auto-configuration pulls in ToolCallingAutoConfiguration (source), which cannot be excluded independently anymore.

Environment

Spring AI 1.0.x and 1.1.x are affected.

Expected behavior

It is possible to work around this specific case, but it requires diving into the auto-configurations and figuring their dependencies. I think using @ImportAutoConfiguration on auto-configuration classes is an anti-pattern, because it breaks the "exclusion" part of the auto-configuration contract.

What should really happen in this case is that: 1. Conditions for ToolCallingAutoConfiguration are fulfilled, so it is actiaved. 1. Conditions for AnthropicChatAutoConfiguration are fulfilled, so it is activated. 1. Anthropic is marked @AutoConfiguration(after = {ToolCallingAutoConfiguration.class}), so the ordering is taking care of for me.

By doing so, it becomes possible for users to disable auto-configurations.

Problematic classes

  • [ ] ZhiPuAiChatAutoConfiguration
  • [ ] MistralAiChatAutoConfiguration
  • [ ] MistralAiOcrAutoConfiguration
  • [ ] MistralAiEmbeddingAutoConfiguration
  • [ ] MistralAiModerationAutoConfiguration
  • [ ] JdbcChatMemoryRepositoryHsqldbAutoConfigurationIT
  • [ ] ElevenLabsAutoConfiguration
  • [ ] OpenAiChatAutoConfiguration
  • [ ] OpenAiModerationAutoConfiguration
  • [ ] OpenAiAudioTranscriptionAutoConfiguration
  • [ ] OpenAiAudioSpeechAutoConfiguration
  • [ ] OpenAiImageAutoConfiguration
  • [ ] OpenAiEmbeddingAutoConfiguration
  • [ ] OCIGenAiChatAutoConfiguration
  • [ ] OCIGenAiEmbeddingAutoConfiguration
  • [ ] GoogleGenAiChatAutoConfiguration
  • [ ] GoogleGenAiTextEmbeddingAutoConfiguration
  • [ ] MiniMaxChatAutoConfiguration
  • [x] OllamaEmbeddingAutoConfiguration (#4495)
  • [x] OllamaApiAutoConfiguration (#4495)
  • [x] OllamaChatAutoConfiguration (#4495)
  • [ ] AzureOpenAiChatAutoConfiguration
  • [ ] AnthropicChatAutoConfiguration
  • [ ] VertexAiGeminiChatAutoConfiguration
  • [ ] VertexAiMultiModalEmbeddingAutoConfiguration
  • [ ] VertexAiTextEmbeddingAutoConfiguration
  • [ ] BedrockConverseProxyChatAutoConfiguration
  • [ ] DeepSeekChatAutoConfiguration

Each of those can be fixed independently, see #4495 for Ollama.

Fix

All @ImportAutoConfiguration should be removed. I don't know of any project who uses that annotation (if you'd like to check, their starters are in Boot directly).

This might break existing behavior, and would require thinking about the auto-configuration of excluded classes.

Comment From: tzolov

If you consider helping with this issue, please contribute a single model auto-configuration at at time. You can use the #4495 as a reference.