fix(mcp sampling): Disable MCP tool callbacks to prevent cyclic dependencies

- Add note in documentation about preventing cyclic dependencies
- Disable mcp tool callback auto-configuration:  spring.ai.mcp.client.toolcallback.enabled=false

Signed-off-by: Christian Tzolov <christian.tzolov@broadcom.com>
This commit is contained in:
Christian Tzolov
2025-05-13 17:50:06 +02:00
parent ffd8def9eb
commit 21c661eda7
5 changed files with 20 additions and 8 deletions

View File

@@ -140,6 +140,8 @@ McpSyncClientCustomizer samplingCustomizer(Map<String, ChatClient> chatClients)
}
```
NOTE: To prevent cyclic dependencies you have to disable MCP tool callbacks auto-configuration: `spring.ai.mcp.client.toolcallback.enabled=false`
## Running the Examples
### Prerequisites

View File

@@ -120,8 +120,8 @@ spring.ai.mcp.client.sse.connections.server1.url=http://localhost:8080
logging.level.io.modelcontextprotocol.client=WARN
logging.level.io.modelcontextprotocol.spec=WARN
# Uncomment to disable MCP tool callbacks
# spring.ai.mcp.client.toolcallback.enabled=false
#Disable MCP tool callbacks
spring.ai.mcp.client.toolcallback.enabled=false
```
## How It Works

View File

@@ -31,19 +31,18 @@ import org.springframework.ai.openai.OpenAiChatModel;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Bean;
@SpringBootApplication
public class McpClientApplication {
public static void main(String[] args) {
SpringApplication.run(McpClientApplication.class, args);
SpringApplication.run(McpClientApplication.class, args).close();;
}
@Bean
public CommandLineRunner predefinedQuestions(OpenAiChatModel openAiChatModel,
ConfigurableApplicationContext context, List<McpSyncClient> mcpClients) {
List<McpSyncClient> mcpClients) {
return args -> {
@@ -59,8 +58,6 @@ public class McpClientApplication {
System.out.println("> USER: " + userQuestion);
System.out.println("> ASSISTANT: " + chatClient.prompt(userQuestion).call().content());
context.close();
};
}

View File

@@ -13,4 +13,4 @@ logging.level.io.modelcontextprotocol.client=WARN
logging.level.io.modelcontextprotocol.spec=WARN
# spring.ai.mcp.client.toolcallback.enabled=false
spring.ai.mcp.client.toolcallback.enabled=false