Skip to content

Commit 21c661e

Browse files
committed
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 <[email protected]>
1 parent ffd8def commit 21c661e

File tree

5 files changed

+20
-8
lines changed

5 files changed

+20
-8
lines changed

mcp.weather.log

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
2025-05-13T17:39:30.096+02:00 INFO 33839 --- [main] o.s.a.m.s.server.McpServerApplication : Starting McpServerApplication using Java 17.0.12 with PID 33839 (/Users/christiantzolov/Dev/projects/spring-ai-examples/model-context-protocol/weather/manual-webflux-server/target/classes started by christiantzolov in /Users/christiantzolov/Dev/projects/spring-ai-examples)
2+
2025-05-13T17:39:30.098+02:00 INFO 33839 --- [main] o.s.a.m.s.server.McpServerApplication : No active profile set, falling back to 1 default profile: "default"
3+
2025-05-13T17:39:30.658+02:00 INFO 33839 --- [main] o.s.b.web.embedded.netty.NettyWebServer : Netty started on port 8080 (http)
4+
2025-05-13T17:39:30.666+02:00 INFO 33839 --- [main] o.s.a.m.s.server.McpServerApplication : Started McpServerApplication in 0.745 seconds (process running for 0.868)
5+
2025-05-13T17:39:44.284+02:00 INFO 33839 --- [reactor-http-nio-3] i.m.server.McpAsyncServer : Client initialize request - Protocol: 2024-11-05, Capabilities: ClientCapabilities[experimental=null, roots=null, sampling=null], Info: Implementation[name=Java SDK MCP Client, version=1.0.0]
6+
2025-05-13T17:39:44.458+02:00 ERROR 33839 --- [boundedElastic-1] i.n.r.d.DnsServerAddressStreamProviders : Unable to load io.netty.resolver.dns.macos.MacOSDnsServerAddressStreamProvider, fallback to system defaults. This may result in incorrect DNS resolutions on MacOS. Check whether you have a dependency on 'io.netty:netty-resolver-dns-native-macos'. Use DEBUG level to see the full stack: java.lang.UnsatisfiedLinkError: failed to load the required native library
7+
2025-05-13T17:39:48.448+02:00 INFO 33839 --- [SpringApplicationShutdownHook] o.s.b.w.embedded.netty.GracefulShutdown : Commencing graceful shutdown. Waiting for active requests to complete
8+
2025-05-13T17:39:48.450+02:00 INFO 33839 --- [netty-shutdown] o.s.b.w.embedded.netty.GracefulShutdown : Graceful shutdown complete
9+
2025-05-13T17:40:18.064+02:00 INFO 34836 --- [main] o.s.a.m.s.server.McpServerApplication : Starting McpServerApplication v0.0.1-SNAPSHOT using Java 23.0.1 with PID 34836 (/Users/christiantzolov/Dev/projects/spring-ai-examples/model-context-protocol/weather/manual-webflux-server/target/mcp-weather-server-0.0.1-SNAPSHOT.jar started by christiantzolov in /Users/christiantzolov/Dev/projects/spring-ai-examples)
10+
2025-05-13T17:40:18.065+02:00 INFO 34836 --- [main] o.s.a.m.s.server.McpServerApplication : No active profile set, falling back to 1 default profile: "default"
11+
2025-05-13T17:40:18.543+02:00 INFO 34836 --- [pool-2-thread-1] i.m.server.McpAsyncServer : Client initialize request - Protocol: 2024-11-05, Capabilities: ClientCapabilities[experimental=null, roots=null, sampling=null], Info: Implementation[name=Java SDK MCP Client, version=1.0.0]
12+
2025-05-13T17:40:18.630+02:00 INFO 34836 --- [main] o.s.a.m.s.server.McpServerApplication : Started McpServerApplication in 0.772 seconds (process running for 1.003)
13+
2025-05-13T17:40:18.761+02:00 ERROR 34836 --- [boundedElastic-1] i.n.r.d.DnsServerAddressStreamProviders : Unable to load io.netty.resolver.dns.macos.MacOSDnsServerAddressStreamProvider, fallback to system defaults. This may result in incorrect DNS resolutions on MacOS. Check whether you have a dependency on 'io.netty:netty-resolver-dns-native-macos'. Use DEBUG level to see the full stack: java.lang.UnsatisfiedLinkError: failed to load the required native library

model-context-protocol/sampling/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,8 @@ McpSyncClientCustomizer samplingCustomizer(Map<String, ChatClient> chatClients)
140140
}
141141
```
142142

143+
NOTE: To prevent cyclic dependencies you have to disable MCP tool callbacks auto-configuration: `spring.ai.mcp.client.toolcallback.enabled=false`
144+
143145
## Running the Examples
144146

145147
### Prerequisites

model-context-protocol/sampling/mcp-sampling-client/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,8 @@ spring.ai.mcp.client.sse.connections.server1.url=http://localhost:8080
120120
logging.level.io.modelcontextprotocol.client=WARN
121121
logging.level.io.modelcontextprotocol.spec=WARN
122122

123-
# Uncomment to disable MCP tool callbacks
124-
# spring.ai.mcp.client.toolcallback.enabled=false
123+
#Disable MCP tool callbacks
124+
spring.ai.mcp.client.toolcallback.enabled=false
125125
```
126126

127127
## How It Works

model-context-protocol/sampling/mcp-sampling-client/src/main/java/org/springframework/ai/mcp/samples/client/McpClientApplication.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,19 +31,18 @@
3131
import org.springframework.boot.CommandLineRunner;
3232
import org.springframework.boot.SpringApplication;
3333
import org.springframework.boot.autoconfigure.SpringBootApplication;
34-
import org.springframework.context.ConfigurableApplicationContext;
3534
import org.springframework.context.annotation.Bean;
3635

3736
@SpringBootApplication
3837
public class McpClientApplication {
3938

4039
public static void main(String[] args) {
41-
SpringApplication.run(McpClientApplication.class, args);
40+
SpringApplication.run(McpClientApplication.class, args).close();;
4241
}
4342

4443
@Bean
4544
public CommandLineRunner predefinedQuestions(OpenAiChatModel openAiChatModel,
46-
ConfigurableApplicationContext context, List<McpSyncClient> mcpClients) {
45+
List<McpSyncClient> mcpClients) {
4746

4847
return args -> {
4948

@@ -59,8 +58,6 @@ public CommandLineRunner predefinedQuestions(OpenAiChatModel openAiChatModel,
5958

6059
System.out.println("> USER: " + userQuestion);
6160
System.out.println("> ASSISTANT: " + chatClient.prompt(userQuestion).call().content());
62-
63-
context.close();
6461
};
6562
}
6663

model-context-protocol/sampling/mcp-sampling-client/src/main/resources/application.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@ logging.level.io.modelcontextprotocol.client=WARN
1313
logging.level.io.modelcontextprotocol.spec=WARN
1414

1515

16-
# spring.ai.mcp.client.toolcallback.enabled=false
16+
spring.ai.mcp.client.toolcallback.enabled=false

0 commit comments

Comments
 (0)