From d91319b0580099a86ca90608d9400f492a56a7a8 Mon Sep 17 00:00:00 2001 From: domparise Date: Thu, 26 Feb 2026 09:31:28 -0500 Subject: [PATCH] cursor claude connection working --- pom.xml | 2 +- src/main/java/net/experimentalworks/App.java | 14 +- .../experimentalworks/SteamGamesServer.java | 149 ++++++++---------- 3 files changed, 82 insertions(+), 83 deletions(-) diff --git a/pom.xml b/pom.xml index 49194d5..5486b4e 100644 --- a/pom.xml +++ b/pom.xml @@ -22,7 +22,7 @@ io.modelcontextprotocol.sdk mcp - 0.7.0 + 1.0.0 io.projectreactor diff --git a/src/main/java/net/experimentalworks/App.java b/src/main/java/net/experimentalworks/App.java index 4465a68..6ccc5de 100644 --- a/src/main/java/net/experimentalworks/App.java +++ b/src/main/java/net/experimentalworks/App.java @@ -1,12 +1,20 @@ package net.experimentalworks; -import io.modelcontextprotocol.server.transport.StdioServerTransport; +import io.modelcontextprotocol.json.McpJsonMapper; +import io.modelcontextprotocol.json.McpJsonMapperSupplier; +import io.modelcontextprotocol.server.transport.StdioServerTransportProvider; +import java.util.ServiceLoader; -/** Hello world! */ public class App { public static void main(String[] args) { - var server = new SteamGamesServer(new StdioServerTransport()); + McpJsonMapper jsonMapper = + ServiceLoader.load(McpJsonMapperSupplier.class) + .findFirst() + .orElseThrow(() -> new IllegalStateException("No McpJsonMapperSupplier found on classpath")) + .get(); + var transportProvider = new StdioServerTransportProvider(jsonMapper); + var server = new SteamGamesServer(transportProvider); server.run().block(); } } diff --git a/src/main/java/net/experimentalworks/SteamGamesServer.java b/src/main/java/net/experimentalworks/SteamGamesServer.java index 4d81f7a..c287782 100644 --- a/src/main/java/net/experimentalworks/SteamGamesServer.java +++ b/src/main/java/net/experimentalworks/SteamGamesServer.java @@ -9,18 +9,21 @@ import io.modelcontextprotocol.server.McpAsyncServer; import io.modelcontextprotocol.server.McpServer; import io.modelcontextprotocol.server.McpServerFeatures; +import io.modelcontextprotocol.spec.McpSchema; import io.modelcontextprotocol.spec.McpSchema.CallToolResult; import io.modelcontextprotocol.spec.McpSchema.ServerCapabilities; -import io.modelcontextprotocol.spec.McpSchema.TextContent; import io.modelcontextprotocol.spec.McpSchema.Tool; -import io.modelcontextprotocol.spec.ServerMcpTransport; +import io.modelcontextprotocol.spec.McpServerTransportProvider; import reactor.core.publisher.Mono; public class SteamGamesServer { private static final String STEAM_API_KEY = System.getenv("STEAM_API_KEY"); private static final String STEAM_ID = System.getenv("STEAM_ID"); - private static final String TOOL_PREFIX = SteamGamesServer.getenvOrDefault("TOOL_PREFIX", ""); + private static final String TOOL_PREFIX = getenvOrDefault("TOOL_PREFIX", ""); + + private static final McpSchema.JsonSchema EMPTY_SCHEMA = + new McpSchema.JsonSchema("object", Map.of(), null, null, null, null); private final McpAsyncServer server; @@ -29,13 +32,13 @@ private static String getenvOrDefault(String key, String defaultValue) { return value != null ? value : defaultValue; } - public SteamGamesServer(ServerMcpTransport transport) { + public SteamGamesServer(McpServerTransportProvider transportProvider) { String version = getClass().getPackage().getImplementationVersion(); if (version == null) { - version = "1.0.0"; // Fallback version if not found + version = "1.0.0"; } this.server = - McpServer.async(transport) + McpServer.async(transportProvider) .serverInfo("steam-games", version) .capabilities(ServerCapabilities.builder().tools(true).logging().build()) .build(); @@ -48,84 +51,72 @@ public Mono run() { .then(Mono.never()); } - private static McpServerFeatures.AsyncToolRegistration createGetGamesTool() { - var schema = - """ - { - "type": "object", - "properties": {} - } - """; - + private McpServerFeatures.AsyncToolSpecification createGetGamesTool() { var tool = - new Tool( - TOOL_PREFIX + "get-games", - """ - Get a comprehensive list of all games owned by the specified Steam user, including their total playtime in minutes. - This includes all games in their Steam library, both installed and uninstalled, free and purchased. For each game, - returns details like the game name, AppID, total playtime, and whether they've played it recently. The data comes - directly from Steam's official API using the provided Steam ID. - NOTE: playtime is sent in minutes. - """, - schema); - - return new McpServerFeatures.AsyncToolRegistration(tool, args -> handleGetGames(args)); - } - - private static Mono handleGetGames(Map args) { - return Mono.fromCallable( - () -> { - var steamGames = new SteamGames(STEAM_API_KEY); - var games = steamGames.getGames(STEAM_ID); - - var json = - new JSONObject() - .put("owner", STEAM_ID) - .put("description", "Played games by the given steam id") - .put("all_games", new JSONArray(games)); + Tool.builder() + .name(TOOL_PREFIX + "get-games") + .description( + """ + Get a comprehensive list of all games owned by the specified Steam user, including their total playtime in minutes. + This includes all games in their Steam library, both installed and uninstalled, free and purchased. For each game, + returns details like the game name, AppID, total playtime, and whether they've played it recently. The data comes + directly from Steam's official API using the provided Steam ID. + NOTE: playtime is sent in minutes. + """) + .inputSchema(EMPTY_SCHEMA) + .build(); - return new CallToolResult(List.of(new TextContent(json.toString())), false); - }); + return new McpServerFeatures.AsyncToolSpecification( + tool, + (exchange, request) -> + Mono.fromCallable( + () -> { + var steamGames = new SteamGames(STEAM_API_KEY); + var games = steamGames.getGames(STEAM_ID); + var json = + new JSONObject() + .put("owner", STEAM_ID) + .put("description", "Played games by the given steam id") + .put("all_games", new JSONArray(games)); + return CallToolResult.builder() + .content(List.of(new McpSchema.TextContent(json.toString()))) + .isError(false) + .build(); + })); } - private static McpServerFeatures.AsyncToolRegistration createGetRecentGamesTool() { - var schema = - """ - { - "type": "object", - "properties": {} - } - """; - + private McpServerFeatures.AsyncToolSpecification createGetRecentGamesTool() { var tool = - new Tool( - TOOL_PREFIX + "get-recent-games", - """ - Retrieve a list of recently played games for the specified Steam user, including playtime - details from the last 2 weeks. This tool fetches data directly from Steam's API using the - provided Steam ID and returns information like game names, AppIDs, and recent playtime - statistics in minutes. The results only include games that have been played in the recent time period, - making it useful for tracking current gaming activity and habits. - NOTE: playtime is sent in minutes. - """, - schema); - - return new McpServerFeatures.AsyncToolRegistration(tool, args -> handleGetRecentGames(args)); - } - - private static Mono handleGetRecentGames(Map args) { - return Mono.fromCallable( - () -> { - var steamGames = new SteamGames(STEAM_API_KEY); - var games = steamGames.getRecentlyGames(STEAM_ID); - - var json = - new JSONObject() - .put("owner", STEAM_ID) - .put("description", "Recently played games by the given steam id") - .put("recent_games", new JSONArray(games)); + Tool.builder() + .name(TOOL_PREFIX + "get-recent-games") + .description( + """ + Retrieve a list of recently played games for the specified Steam user, including playtime + details from the last 2 weeks. This tool fetches data directly from Steam's API using the + provided Steam ID and returns information like game names, AppIDs, and recent playtime + statistics in minutes. The results only include games that have been played in the recent time period, + making it useful for tracking current gaming activity and habits. + NOTE: playtime is sent in minutes. + """) + .inputSchema(EMPTY_SCHEMA) + .build(); - return new CallToolResult(List.of(new TextContent(json.toString())), false); - }); + return new McpServerFeatures.AsyncToolSpecification( + tool, + (exchange, request) -> + Mono.fromCallable( + () -> { + var steamGames = new SteamGames(STEAM_API_KEY); + var games = steamGames.getRecentlyGames(STEAM_ID); + var json = + new JSONObject() + .put("owner", STEAM_ID) + .put("description", "Recently played games by the given steam id") + .put("recent_games", new JSONArray(games)); + return CallToolResult.builder() + .content(List.of(new McpSchema.TextContent(json.toString()))) + .isError(false) + .build(); + })); } }