Skip to content

Commit 2dd005b

Browse files
committed
Enable MCP tool callback by default
- Change the default value of `toolcallback.enabled` property to `true` in both configuration and documentation. - Update `McpClientCommonProperties.Toolcallback` to default `enabled` to `true` and refactor from record to class. - Adjust `@ConditionalOnProperty` in `McpToolCallbackAutoConfiguration` to `matchIfMissing = true` for tool callback. - Update tests to reflect new default behavior: tool callback is now enabled by default when the property is missing. - Update documentation to indicate the new default value for `toolcallback.enabled` is `true`. Signed-off-by: Christian Tzolov <[email protected]>
1 parent b5c3216 commit 2dd005b

File tree

5 files changed

+27
-26
lines changed

5 files changed

+27
-26
lines changed

auto-configurations/mcp/spring-ai-autoconfigure-mcp-client/src/main/java/org/springframework/ai/mcp/client/autoconfigure/McpToolCallbackAutoConfiguration.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ static class McpAutoConfigEnabled {
7777
}
7878

7979
@ConditionalOnProperty(prefix = McpClientCommonProperties.CONFIG_PREFIX + ".toolcallback", name = "enabled",
80-
havingValue = "true", matchIfMissing = false)
80+
havingValue = "true", matchIfMissing = true)
8181
static class ToolCallbackProviderEnabled {
8282

8383
}

auto-configurations/mcp/spring-ai-autoconfigure-mcp-client/src/main/java/org/springframework/ai/mcp/client/autoconfigure/properties/McpClientCommonProperties.java

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,6 @@
1818

1919
import java.time.Duration;
2020

21-
import com.fasterxml.jackson.annotation.JsonInclude;
22-
import com.fasterxml.jackson.annotation.JsonProperty;
23-
2421
import org.springframework.boot.context.properties.ConfigurationProperties;
2522

2623
/**
@@ -110,7 +107,7 @@ public enum ClientType {
110107
* <p>
111108
* This configuration is used to enable or disable tool callbacks in the MCP client.
112109
*/
113-
private Toolcallback toolcallback = new Toolcallback(false);
110+
private Toolcallback toolcallback = new Toolcallback();
114111

115112
/**
116113
* Represents a callback configuration for tools.
@@ -121,14 +118,22 @@ public enum ClientType {
121118
* @param enabled A boolean flag indicating whether the tool callback is enabled. If
122119
* true, the tool callback is active; otherwise, it is disabled.
123120
*/
124-
@JsonInclude(JsonInclude.Include.NON_ABSENT)
125-
public record Toolcallback(
126-
127-
/**
128-
* A boolean flag indicating whether the tool callback is enabled. If true,
129-
* the tool callback is active; otherwise, it is disabled.
130-
*/
131-
@JsonProperty("enabled") boolean enabled) {
121+
public static class Toolcallback {
122+
123+
/**
124+
* A boolean flag indicating whether the tool callback is enabled. If true, the
125+
* tool callback is active; otherwise, it is disabled.
126+
*/
127+
private boolean enabled = true;
128+
129+
public void setEnabled(boolean enabled) {
130+
this.enabled = enabled;
131+
}
132+
133+
public boolean isEnabled() {
134+
return this.enabled;
135+
}
136+
132137
}
133138

134139
public boolean isEnabled() {

auto-configurations/mcp/spring-ai-autoconfigure-mcp-client/src/test/java/org/springframework/ai/mcp/client/autoconfigure/McpToolCallbackAutoConfigurationConditionTests.java

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -63,18 +63,14 @@ void doesNotMatchWhenBothPropertiesAreDisabled() {
6363
}
6464

6565
@Test
66-
void doesNotMatchWhenToolCallbackPropertyIsMissing() {
67-
// McpClientEnabled is true by default if missing, but ToolCallbackEnabled is
68-
// false by default if missing
66+
void doesMatchWhenToolCallbackPropertyIsMissing() {
6967
this.contextRunner.withPropertyValues("spring.ai.mcp.client.enabled=true")
70-
.run(context -> assertThat(context).doesNotHaveBean("testBean"));
68+
.run(context -> assertThat(context).hasBean("testBean"));
7169
}
7270

7371
@Test
74-
void doesNotMatchWhenBothPropertiesAreMissing() {
75-
// McpClientEnabled is true by default if missing, but ToolCallbackEnabled is
76-
// false by default if missing
77-
this.contextRunner.run(context -> assertThat(context).doesNotHaveBean("testBean"));
72+
void doesMatchWhenBothPropertiesAreMissing() {
73+
this.contextRunner.run(context -> assertThat(context).hasBean("testBean"));
7874
}
7975

8076
@Configuration

auto-configurations/mcp/spring-ai-autoconfigure-mcp-client/src/test/java/org/springframework/ai/mcp/client/autoconfigure/McpToolCallbackAutoConfigurationTests.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,25 +29,25 @@ public class McpToolCallbackAutoConfigurationTests {
2929
.withConfiguration(AutoConfigurations.of(McpToolCallbackAutoConfiguration.class));
3030

3131
@Test
32-
void disabledByDefault() {
32+
void enableddByDefault() {
3333

3434
this.applicationContext.run(context -> {
35-
assertThat(context).doesNotHaveBean("mcpToolCallbacks");
35+
assertThat(context).hasBean("mcpToolCallbacks");
3636
assertThat(context).doesNotHaveBean("mcpAsyncToolCallbacks");
3737
});
3838

3939
this.applicationContext
4040
.withPropertyValues("spring.ai.mcp.client.enabled=true", "spring.ai.mcp.client.type=SYNC")
4141
.run(context -> {
42-
assertThat(context).doesNotHaveBean("mcpToolCallbacks");
42+
assertThat(context).hasBean("mcpToolCallbacks");
4343
assertThat(context).doesNotHaveBean("mcpAsyncToolCallbacks");
4444
});
4545

4646
this.applicationContext
4747
.withPropertyValues("spring.ai.mcp.client.enabled=true", "spring.ai.mcp.client.type=ASYNC")
4848
.run(context -> {
4949
assertThat(context).doesNotHaveBean("mcpToolCallbacks");
50-
assertThat(context).doesNotHaveBean("mcpAsyncToolCallbacks");
50+
assertThat(context).hasBean("mcpAsyncToolCallbacks");
5151
});
5252
}
5353

spring-ai-docs/src/main/antora/modules/ROOT/pages/api/mcp/mcp-client-boot-starter-docs.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ The common properties are prefixed with `spring.ai.mcp.client`:
8787

8888
|`toolcallback.enabled`
8989
|Enable/disable the MCP tool callback integration with Spring AI's tool execution framework
90-
|`false`
90+
|`true`
9191
|===
9292

9393
=== Stdio Transport Properties

0 commit comments

Comments
 (0)