-
Notifications
You must be signed in to change notification settings - Fork 0
M3 #14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
M3 #14
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
4443788
fix an edge case
6c7c4a2
extract a helper class from DirectConnectionService
5785796
add search for multiple earliest connections between stops based on a…
4228ca2
add GET /stops with pagination support
0b35ebd
add GET /stops/routes
c13f495
small controller and service refactor
wegorz13 96de3e6
Merge pull request #12 from wegorz13/mcp-server-integration
cnuart db870fe
fix some edge cases and refactor code
000c7a0
add testing for StopService
5ec2081
integrate mcp protocol and create tools for mcp client
wegorz13 9486999
Merge pull request #13 from wegorz13/fastest-connections
cnuart 4998c55
integrate mcp protocol and create tools for mcp client
wegorz13 c547d10
small StopService refactor, more needed
wegorz13 29477d4
major StopService refactor
wegorz13 6b19a7d
rearrange package structure
wegorz13 5689952
E2E Tests
gontarsky04 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,6 +2,7 @@ HELP.md | |
| /data/* | ||
| !/data/.gitkeep | ||
| .gradle | ||
| .log | ||
|
|
||
| build/ | ||
| !gradle/wrapper/gradle-wrapper.jar | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
src/main/java/pl/agh/transit/TransitLocationApiApplication.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,13 +1,25 @@ | ||
| package pl.agh.transit; | ||
|
|
||
| import org.springframework.ai.support.ToolCallbacks; | ||
| import org.springframework.ai.tool.ToolCallback; | ||
| import org.springframework.boot.SpringApplication; | ||
| import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
| import org.springframework.context.annotation.Bean; | ||
| import org.springframework.scheduling.annotation.EnableScheduling; | ||
| import pl.agh.transit.mcp.StopMcpTools; | ||
| import pl.agh.transit.mcp.TripMcpTools; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| @EnableScheduling | ||
| @SpringBootApplication | ||
| public class TransitLocationApiApplication { | ||
| public static void main(String[] args) { | ||
| SpringApplication.run(TransitLocationApiApplication.class, args); | ||
| } | ||
|
|
||
| @Bean | ||
| public List<ToolCallback> mcpToolCallbacks(StopMcpTools stopMcpTools, TripMcpTools tripMcpTools) { | ||
| return List.of(ToolCallbacks.from(stopMcpTools, tripMcpTools)); | ||
| } | ||
| } |
3 changes: 1 addition & 2 deletions
3
.../java/pl/agh/transit/TripDataFetcher.java → .../pl/agh/transit/core/TripDataFetcher.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...n/java/pl/agh/transit/TripRepository.java → ...a/pl/agh/transit/core/TripRepository.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| package pl.agh.transit; | ||
| package pl.agh.transit.core; | ||
|
|
||
|
|
||
| import com.google.transit.realtime.GtfsRealtime; | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| package pl.agh.transit.dto; | ||
|
|
||
| import lombok.Builder; | ||
| import lombok.Data; | ||
|
|
||
| /** | ||
| * DTO representing next departure for a specific stop and route | ||
| */ | ||
| @Data | ||
| @Builder | ||
| public class NextDepartureDTO { | ||
| String departureTime; | ||
| Integer departureDelay; | ||
| String stopName; | ||
| String routeName; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| package pl.agh.transit.dto; | ||
|
|
||
| import lombok.Builder; | ||
| import lombok.Data; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| @Data | ||
| @Builder | ||
| public class PagedResponseDTO<T> { | ||
| private List<T> content; | ||
| private int pageNumber; | ||
| private int totalPages; | ||
| private long totalElements; | ||
| private int pageSize; | ||
| private boolean hasNext; | ||
| private boolean hasPrevious; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| package pl.agh.transit.dto; | ||
|
|
||
| import lombok.Builder; | ||
| import lombok.Data; | ||
|
|
||
| @Data | ||
| @Builder | ||
| public class StopDTO { | ||
| private String id; | ||
| private String name; | ||
| private double latitude; | ||
| private double longitude; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 3 additions & 2 deletions
5
src/main/java/pl/agh/transit/gtfs_static/repository/StopRepository.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,12 +1,13 @@ | ||
| package pl.agh.transit.gtfs_static.repository; | ||
|
|
||
| import org.springframework.data.repository.ListCrudRepository; | ||
| import org.springframework.data.repository.PagingAndSortingRepository; | ||
| import org.springframework.stereotype.Repository; | ||
| import pl.agh.transit.gtfs_static.model.Stop; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| @Repository | ||
| public interface StopRepository extends ListCrudRepository<Stop, String> { | ||
| public interface StopRepository extends ListCrudRepository<Stop, String>, PagingAndSortingRepository<Stop, String> { | ||
| List<Stop> findByStopName(String stopName); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| package pl.agh.transit.mcp; | ||
|
|
||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.ai.tool.annotation.Tool; | ||
| import org.springframework.ai.tool.annotation.ToolParam; | ||
| import org.springframework.stereotype.Component; | ||
| import pl.agh.transit.stop.StopService; | ||
| import pl.agh.transit.dto.NextDepartureDTO; | ||
| import pl.agh.transit.dto.PagedResponseDTO; | ||
| import pl.agh.transit.dto.StopDTO; | ||
|
|
||
| import java.time.LocalDate; | ||
| import java.time.LocalTime; | ||
| import java.util.List; | ||
|
|
||
| @Component | ||
| @RequiredArgsConstructor | ||
| public class StopMcpTools { | ||
|
|
||
| private final StopService stopService; | ||
|
|
||
| @Tool(description = "Retrieves a paginated list of all available public transport stops.") | ||
| public PagedResponseDTO<StopDTO> getAllStops( | ||
| @ToolParam(description = "Page number (starts from 0, default is 0)", required = false) Integer page, | ||
| @ToolParam(description = "Number of stops per page (default is 10, max is 100)", required = false) Integer size, | ||
| @ToolParam(description = "Field to sort by (default is 'stopName')", required = false) String sortBy | ||
| ) { | ||
| int pageNum = (page != null) ? page : 0; | ||
| int pageSize = (size != null) ? size : 10; | ||
| String sort = (sortBy != null && !sortBy.isBlank()) ? sortBy : "stopName"; | ||
|
|
||
| if (pageSize > 100) { | ||
| pageSize = 100; | ||
| } | ||
|
|
||
| return stopService.getAllStops(pageNum, pageSize, sort); | ||
| } | ||
|
|
||
| @Tool(description = "Gets the next 5 departures for a specific stop and route (line number). " + | ||
| "Includes real-time delay information if available.") | ||
| public List<NextDepartureDTO> getNextDepartures( | ||
| @ToolParam(description = "Name of the stop (e.g., 'Teatr Bagatela')") String stopName, | ||
| @ToolParam(description = "Route name or line number (e.g., '52', '179')") String routeName, | ||
| @ToolParam(description = "Date to check schedule for (YYYY-MM-DD). If omitted, defaults to today.", required = false) LocalDate date, | ||
| @ToolParam(description = "Time to check schedule for (HH:mm). If omitted, defaults to right now.", required = false) LocalTime time | ||
| ) { | ||
| if (date != null && time != null) { | ||
| return stopService.getNextDeparturesForStopAndRoute(stopName, routeName, date, time, 5); | ||
| } | ||
| else{ | ||
| return stopService.getNextDeparturesForStopAndRoute(stopName, routeName,5); | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| package pl.agh.transit.mcp; | ||
|
|
||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.ai.tool.annotation.Tool; | ||
| import org.springframework.ai.tool.annotation.ToolParam; | ||
| import org.springframework.stereotype.Component; | ||
| import pl.agh.transit.trip.DirectConnectionService; | ||
| import pl.agh.transit.dto.TransportTypeDTO; | ||
|
|
||
| import java.time.LocalDate; | ||
| import java.time.LocalTime; | ||
| import java.util.List; | ||
|
|
||
| @Component | ||
| @RequiredArgsConstructor | ||
| public class TripMcpTools { | ||
|
|
||
| private final DirectConnectionService directConnectionService; | ||
|
|
||
| @Tool(description = "Finds the 3 fastest direct public transport connections between two stops. " + | ||
| "If date and time are not provided, it defaults to the current time.") | ||
| public List<TransportTypeDTO> getFastestConnections( | ||
| @ToolParam(description = "Name of the starting stop (origin)") String from, | ||
| @ToolParam(description = "Name of the destination stop") String to, | ||
| @ToolParam(description = "Travel date in YYYY-MM-DD format (optional)", required = false) LocalDate travelDate, | ||
| @ToolParam(description = "Travel time in HH:mm format (optional)", required = false) LocalTime travelTime | ||
| ) { | ||
| if (travelDate != null && travelTime != null) { | ||
| return directConnectionService.findFastestDirectConnections(from, to, travelDate, travelTime, 3); | ||
| } else { | ||
| return directConnectionService.findFastestDirectConnections(from, to, 3); | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.