Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package org.springframework.ai.mcp.sample.server.model;

import org.springaicommunity.mcp.annotation.McpToolParam;

public class Point {

@McpToolParam(description = "The latitude of the location", required = true)
private double latitude;
@McpToolParam(description = "The longitude of the location", required = true)
private double longitude;


public Point() {}
public Point(double latitude, double longitude) {
this.latitude = latitude;
this.longitude = longitude;
}
public double getLatitude() {
return latitude;
}
public void setLatitude(double latitude) {
this.latitude = latitude;
}
public double getLongitude() {
return longitude;
}
public void setLongitude(double longitude) {
this.longitude = longitude;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@
package org.springframework.ai.mcp.sample.server.providers;

import java.time.LocalDateTime;
import java.util.Arrays;
import java.util.List;

import org.slf4j.Logger;
import org.springaicommunity.mcp.annotation.McpTool;
import org.springaicommunity.mcp.annotation.McpToolParam;

import org.springframework.ai.mcp.sample.server.model.Point;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestClient;

Expand Down Expand Up @@ -61,4 +63,22 @@ public WeatherResponse getTemperature(@McpToolParam(description = "The location
return response;
}

@McpTool(description = "Get temperatures (in celsius) for two specific locations simultaneously")
public List<WeatherResponse> getTemperatures(@McpToolParam(description = "The first location point") Point point1,
@McpToolParam(description = "The second location point") Point point2) {

String latParam = point1.getLatitude() + "," + point2.getLatitude();
String longParam = point1.getLongitude() + "," + point2.getLongitude();

WeatherResponse[] responses = restClient
.get()
.uri("https://api.open-meteo.com/v1/forecast?latitude={lat}&longitude={long}&current=temperature_2m",
latParam, longParam)
.retrieve()
.body(WeatherResponse[].class);

logger.info("Checked 2 locations. Point1: {}, Point2: {}", point1, point2);

return responses != null ? Arrays.asList(responses) : List.of();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@
import org.springaicommunity.mcp.annotation.McpProgressToken;
import org.springaicommunity.mcp.annotation.McpTool;
import org.springaicommunity.mcp.annotation.McpToolParam;
import org.springaicommunity.mcp.context.DefaultMcpSyncRequestContext;

import org.springframework.stereotype.Service;

import io.modelcontextprotocol.server.McpSyncServerExchange;
import io.modelcontextprotocol.spec.McpSchema;
Expand Down