Skip to content

Commit 06cc9de

Browse files
committed
samples: replace @tool with @mcptool
Signed-off-by: Daniel Garnier-Moiroux <[email protected]>
1 parent dac7484 commit 06cc9de

File tree

6 files changed

+13
-36
lines changed

6 files changed

+13
-36
lines changed

samples/sample-mcp-server-api-key/src/main/java/org/springaicommunity/mcp/security/sample/server/apikey/McpServerConfiguration.java

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,8 @@
2222
import org.springaicommunity.mcp.security.server.apikey.ApiKeyEntityRepository;
2323
import org.springaicommunity.mcp.security.server.apikey.memory.ApiKeyEntityImpl;
2424
import org.springaicommunity.mcp.security.server.apikey.memory.InMemoryApiKeyEntityRepository;
25+
import org.springaicommunity.mcp.security.server.config.McpApiKeyConfigurer;
2526

26-
import org.springframework.ai.tool.ToolCallbackProvider;
27-
import org.springframework.ai.tool.method.MethodToolCallbackProvider;
2827
import org.springframework.context.annotation.Bean;
2928
import org.springframework.context.annotation.Configuration;
3029
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
@@ -33,7 +32,6 @@
3332
import org.springframework.web.cors.CorsConfiguration;
3433
import org.springframework.web.cors.CorsConfigurationSource;
3534
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
36-
import static org.springaicommunity.mcp.security.server.config.McpApiKeyConfigurer.mcpServerApiKey;
3735

3836
/**
3937
* @author Daniel Garnier-Moiroux
@@ -42,15 +40,10 @@
4240
@EnableWebSecurity
4341
class McpServerConfiguration {
4442

45-
@Bean
46-
ToolCallbackProvider toolCallbackProvider(WeatherService weatherService) {
47-
return MethodToolCallbackProvider.builder().toolObjects(weatherService).build();
48-
}
49-
5043
@Bean
5144
SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
5245
return http.authorizeHttpRequests(authz -> authz.anyRequest().authenticated())
53-
.with(mcpServerApiKey(), (apiKey) -> apiKey.apiKeyRepository(buildApiKeyRepository()))
46+
.with(McpApiKeyConfigurer.mcpServerApiKey(), (apiKey) -> apiKey.apiKeyRepository(buildApiKeyRepository()))
5447
.cors(cors -> cors.configurationSource(corsConfigurationSource()))
5548
.build();
5649
}

samples/sample-mcp-server-api-key/src/main/java/org/springaicommunity/mcp/security/sample/server/apikey/WeatherService.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818

1919
import java.time.LocalDateTime;
2020

21-
import org.springframework.ai.tool.annotation.Tool;
21+
import org.springaicommunity.mcp.annotation.McpTool;
22+
2223
import org.springframework.ai.tool.annotation.ToolParam;
2324
import org.springframework.security.access.prepost.PreAuthorize;
2425
import org.springframework.stereotype.Service;
@@ -45,7 +46,7 @@ public record Current(LocalDateTime time, int interval, double temperature_2m) {
4546
}
4647

4748
@PreAuthorize("isAuthenticated()")
48-
@Tool(name = "current-temperature",
49+
@McpTool(name = "current-temperature",
4950
description = "Get the current temperature (in celsius) for a specific location")
5051
public WeatherResponse getTemperature(@ToolParam(description = "The location latitude") double latitude,
5152
@ToolParam(description = "The location longitude") double longitude) {

samples/sample-mcp-server-secured-tools/src/main/java/org/springaicommunity/mcp/security/sample/server/securedtools/McpServerConfiguration.java

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@
1818

1919
import java.util.List;
2020

21-
import org.springframework.ai.tool.ToolCallbackProvider;
22-
import org.springframework.ai.tool.method.MethodToolCallbackProvider;
2321
import org.springframework.beans.factory.annotation.Value;
2422
import org.springframework.context.annotation.Bean;
2523
import org.springframework.context.annotation.Configuration;
@@ -39,11 +37,6 @@
3937
@EnableMethodSecurity
4038
class McpServerConfiguration {
4139

42-
@Bean
43-
ToolCallbackProvider toolCallbackProvider(WeatherService weatherService) {
44-
return MethodToolCallbackProvider.builder().toolObjects(weatherService).build();
45-
}
46-
4740
@Bean
4841
SecurityFilterChain securityFilterChain(HttpSecurity http,
4942
@Value("${spring.security.oauth2.resourceserver.jwt.issuer-uri}") String issuerUrl) throws Exception {

samples/sample-mcp-server-secured-tools/src/main/java/org/springaicommunity/mcp/security/sample/server/securedtools/WeatherService.java

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818

1919
import java.time.LocalDateTime;
2020

21-
import org.springframework.ai.chat.model.ToolContext;
22-
import org.springframework.ai.tool.annotation.Tool;
21+
import org.springaicommunity.mcp.annotation.McpTool;
22+
2323
import org.springframework.ai.tool.annotation.ToolParam;
2424
import org.springframework.security.access.prepost.PreAuthorize;
2525
import org.springframework.stereotype.Service;
@@ -46,19 +46,16 @@ public record Current(LocalDateTime time, int interval, double temperature_2m) {
4646
}
4747

4848
@PreAuthorize("isAuthenticated()")
49-
@Tool(name = "current-temperature",
49+
@McpTool(name = "current-temperature",
5050
description = "Get the current temperature (in celsius) for a specific location")
5151
public WeatherResponse getTemperature(@ToolParam(description = "The location latitude") double latitude,
52-
@ToolParam(description = "The location longitude") double longitude, ToolContext toolContext) {
53-
54-
WeatherResponse weatherResponse = restClient.get()
52+
@ToolParam(description = "The location longitude") double longitude) {
53+
return restClient.get()
5554
.uri("https://api.open-meteo.com/v1/forecast?latitude={latitude}&longitude={longitude}&current=temperature_2m",
5655
latitude, longitude)
5756
.retrieve()
5857
.body(WeatherResponse.class);
5958

60-
return weatherResponse;
61-
6259
}
6360

6461
}

samples/sample-mcp-server/src/main/java/org/springaicommunity/mcp/security/sample/server/streamable/HistoricalWeatherService.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222
import java.util.Map;
2323
import java.util.stream.IntStream;
2424

25-
import org.springframework.ai.chat.model.ToolContext;
26-
import org.springframework.ai.tool.annotation.Tool;
25+
import org.springaicommunity.mcp.annotation.McpTool;
26+
2727
import org.springframework.ai.tool.annotation.ToolParam;
2828
import org.springframework.stereotype.Service;
2929
import org.springframework.web.client.RestClient;
@@ -53,7 +53,7 @@ public record DailyTemperatures(String date, double minTemperature, double maxTe
5353
}
5454
}
5555

56-
@Tool(name = "temperature-history",
56+
@McpTool(name = "temperature-history",
5757
description = "Get 5-year historical temperature data (in Celsius), including daily min and daily max temperatures, for a specific location")
5858
public ToolResponse getHistoricalWeatherData(@ToolParam(description = "The location latitude") double latitude,
5959
@ToolParam(description = "The location longitude") double longitude) {

samples/sample-mcp-server/src/main/java/org/springaicommunity/mcp/security/sample/server/streamable/McpServerConfiguration.java

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@
1818

1919
import java.util.List;
2020

21-
import org.springframework.ai.tool.ToolCallbackProvider;
22-
import org.springframework.ai.tool.method.MethodToolCallbackProvider;
2321
import org.springframework.beans.factory.annotation.Value;
2422
import org.springframework.context.annotation.Bean;
2523
import org.springframework.context.annotation.Configuration;
@@ -37,11 +35,6 @@
3735
@Configuration
3836
class McpServerConfiguration {
3937

40-
@Bean
41-
ToolCallbackProvider toolCallbackProvider(HistoricalWeatherService weatherService) {
42-
return MethodToolCallbackProvider.builder().toolObjects(weatherService).build();
43-
}
44-
4538
@Bean
4639
SecurityFilterChain securityFilterChain(HttpSecurity http,
4740
@Value("${spring.security.oauth2.resourceserver.jwt.issuer-uri}") String issuerUrl) throws Exception {

0 commit comments

Comments
 (0)