Files
ax_hub_mcp_tool/FetchTools.java
jade e998127fa5
Some checks failed
Deploy to OCIWP / deploy (push) Failing after 1m3s
feat: implement MCI session fetching using employee number
2026-08-19 16:41:13 +09:00

55 lines
2.1 KiB
Java

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<java.io.InputStream> 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);
}
}
}
}
}
}