import java.net.URI; import java.net.http.HttpClient; import java.net.http.HttpRequest; import java.net.http.HttpResponse; import java.io.BufferedReader; import java.io.InputStreamReader; import java.nio.charset.StandardCharsets; public class FetchTools { public static void main(String[] args) throws Exception { HttpClient client = HttpClient.newBuilder().build(); HttpRequest sseReq = HttpRequest.newBuilder() .uri(URI.create("https://axhubmcp.devjun.net/mcp/custom/cmm")) .GET() .build(); HttpResponse sseRes = client.send(sseReq, HttpResponse.BodyHandlers.ofInputStream()); BufferedReader reader = new BufferedReader(new InputStreamReader(sseRes.body(), StandardCharsets.UTF_8)); String line; String postUrl = null; while ((line = reader.readLine()) != null) { if (line.startsWith("event:endpoint")) { String dataLine = reader.readLine(); // data:http... postUrl = dataLine.substring(5).trim(); break; } } if (postUrl != null) { String payload = "{\"jsonrpc\":\"2.0\",\"id\":1,\"method\":\"tools/list\"}"; HttpRequest postReq = HttpRequest.newBuilder() .uri(URI.create(postUrl)) .header("Content-Type", "application/json") .POST(HttpRequest.BodyPublishers.ofString(payload)) .build(); client.send(postReq, HttpResponse.BodyHandlers.discarding()); // Now read the rest of SSE while ((line = reader.readLine()) != null) { if (line.startsWith("event:message")) { String dataLine = reader.readLine(); if (dataLine.startsWith("data:")) { String json = dataLine.substring(5).trim(); System.out.println(json); System.exit(0); } } } } } }