diff --git a/apps/mini-runtime/src/main/java/com/akto/hybrid_parsers/HttpCallParser.java b/apps/mini-runtime/src/main/java/com/akto/hybrid_parsers/HttpCallParser.java index be67c4f7e2..c5478a3b16 100644 --- a/apps/mini-runtime/src/main/java/com/akto/hybrid_parsers/HttpCallParser.java +++ b/apps/mini-runtime/src/main/java/com/akto/hybrid_parsers/HttpCallParser.java @@ -509,12 +509,15 @@ private static void sendTrafficMetricsToTelemetry(BasicDBObject metricsData) { } public static boolean useHostCondition(String hostName, HttpResponseParams.Source source) { - List whiteListSource = Arrays.asList(HttpResponseParams.Source.MIRRORING); + List whiteListSource = Arrays.asList(HttpResponseParams.Source.MIRRORING, HttpResponseParams.Source.MCP_RECON); boolean hostNameCondition; if (hostName == null) { hostNameCondition = false; - } else { - hostNameCondition = ! ( hostName.toLowerCase().equals(hostName.toUpperCase()) ); + } else if (source.equals(HttpResponseParams.Source.MCP_RECON)) { + hostNameCondition = true; + } + else { + hostNameCondition = ! ( hostName.toLowerCase().equals(hostName.toUpperCase()) ); } return whiteListSource.contains(source) && hostNameCondition && ApiCollection.useHost; } @@ -760,7 +763,7 @@ public List filterHttpResponseParams(List> executorNodesMap = ParseAndExecute.createExecutorNodeMap(apiCatalogSync.advancedFilterMap); for (HttpResponseParams httpResponseParam: httpResponseParamsList) { - if (httpResponseParam.getSource().equals(HttpResponseParams.Source.MIRRORING)) { + if (httpResponseParam.getSource().equals(HttpResponseParams.Source.MIRRORING) || httpResponseParam.getSource().equals(HttpResponseParams.Source.MCP_RECON)) { TrafficMetrics.Key totalRequestsKey = getTrafficMetricsKey(httpResponseParam, TrafficMetrics.Name.TOTAL_REQUESTS_RUNTIME); incTrafficMetrics(totalRequestsKey,1); } @@ -879,7 +882,7 @@ public List filterHttpResponseParams(List { diff --git a/apps/mini-runtime/src/main/java/com/akto/hybrid_runtime/McpReconScanner.java b/apps/mini-runtime/src/main/java/com/akto/hybrid_runtime/McpReconScanner.java index 051c8cbee4..93f65893a1 100644 --- a/apps/mini-runtime/src/main/java/com/akto/hybrid_runtime/McpReconScanner.java +++ b/apps/mini-runtime/src/main/java/com/akto/hybrid_runtime/McpReconScanner.java @@ -340,59 +340,26 @@ private void cleanFailedIpCache() { * Optimized MCP verification using CompletableFuture with timeout management */ private List verifyMcpBatch(List openTargets) { - // Use CompletableFuture for better control - List> futures = new ArrayList<>(openTargets.size()); + logger.info(String.format("Starting MCP verification for %d targets", openTargets.size())); + List results = new ArrayList<>(); for (IpPortPair target : openTargets) { - CompletableFuture future = CompletableFuture - .supplyAsync(() -> { - try { - semaphore.acquire(); - try { - return verifySingleMcp(target.ip, target.port); - } finally { - semaphore.release(); - } - } catch (InterruptedException e) { - Thread.currentThread().interrupt(); - return null; - } - }, executorService); - - // Add timeout using Java 8 compatible approach - final CompletableFuture timeoutFuture = new CompletableFuture<>(); - executorService.submit(() -> { - try { - Thread.sleep(timeout * 2); - timeoutFuture.complete(null); - } catch (InterruptedException e) { - // Ignore + try { + logger.debug(String.format("Checking MCP at %s:%d", target.ip, target.port)); + McpServer result = verifySingleMcp(target.ip, target.port); + if (result != null) { + logger.info(String.format("MCP server found at %s:%d", target.ip, target.port)); + results.add(result); + } else { + logger.debug(String.format("No MCP server at %s:%d", target.ip, target.port)); } - }); - - CompletableFuture resultFuture = future - .applyToEither(timeoutFuture, result -> result) - .exceptionally(ex -> { - logger.debug("Verification timeout for " + target.ip + ":" + target.port); - return null; - }); - - futures.add(resultFuture); - } - - // Wait for all completions or timeout - try { - CompletableFuture.allOf(futures.toArray(new CompletableFuture[0])) - .get(timeout * 3, TimeUnit.MILLISECONDS); - } catch (Exception e) { - // Continue with completed futures + } catch (Exception e) { + logger.debug("Verification error for " + target.ip + ":" + target.port + ": " + e.getMessage()); + } } - // Collect non-null results - return futures.stream() - .map(future -> future.getNow(null)) - .filter(Objects::nonNull) - .collect(Collectors.toList()); + logger.info(String.format("MCP verification completed. Found %d servers out of %d targets", results.size(), openTargets.size())); + return results; } /** @@ -443,9 +410,6 @@ private McpServer checkSseEndpoint(String baseUrl, String ip, int port) { if (response.getStatusCode() == 200) { String contentType = response.getHeaders().getOrDefault("Content-Type", Collections.singletonList("")).get(0); if (contentType != null && contentType.contains("text/event-stream")) { - String content = response.getBody() != null ? response.getBody().toLowerCase() : ""; - for (String indicator : McpConstants.MCP_INDICATORS) { - if (content.contains(indicator.toLowerCase())) { McpServer server = new McpServer(); server.setIp(ip); server.setPort(port); @@ -456,8 +420,6 @@ private McpServer checkSseEndpoint(String baseUrl, String ip, int port) { server.setType("SSE"); server.setEndpoint(endpoint); return server; - } - } } } } catch (Exception e) { @@ -539,8 +501,7 @@ private McpServer checkHttpEndpoints(String baseUrl, String ip, int port) { Map> headers = new HashMap<>(); OriginalHttpRequest request = new OriginalHttpRequest(url, "", "GET", null, headers, ""); OriginalHttpResponse response = ApiExecutor.sendRequest(request, true, null, false, new ArrayList<>()); - String content = response.getBody(); - if (isLikelyMcp(content)) { + if(response.getStatusCode() == 200) { McpServer server = new McpServer(); server.setIp(ip); server.setPort(port); @@ -549,7 +510,7 @@ private McpServer checkHttpEndpoints(String baseUrl, String ip, int port) { server.setDetectionMethod("HTTP"); server.setTimestamp(new Date().toString()); server.setEndpoint(endpoint); - List detectedIndicators = getDetectedIndicators(content); + List detectedIndicators = getDetectedIndicators("HTTP"); Map serverInfo = new HashMap<>(); serverInfo.put("detectedIndicators", detectedIndicators); server.setServerInfo(serverInfo); diff --git a/apps/mini-runtime/src/main/java/com/akto/hybrid_runtime/McpReconSyncJobExecutor.java b/apps/mini-runtime/src/main/java/com/akto/hybrid_runtime/McpReconSyncJobExecutor.java index ae3fff308e..bbcee7f4da 100644 --- a/apps/mini-runtime/src/main/java/com/akto/hybrid_runtime/McpReconSyncJobExecutor.java +++ b/apps/mini-runtime/src/main/java/com/akto/hybrid_runtime/McpReconSyncJobExecutor.java @@ -321,11 +321,23 @@ private void processScanResults(List scanResults, APIConfig apiC // Add to batch serverBatch.add(mcpReconResult); - List toolsResponseList = toolsDiscovery(server); - List resourcesResponseList = resourcesDiscovery(server); + + List toolsResponseList = new ArrayList<>(); + List resourcesResponseList = new ArrayList<>(); + List endpointsResponseList = new ArrayList<>(); + if(server.getTools() != null) { + toolsResponseList = McpToolsSyncJobExecutor.INSTANCE.handleMcpToolsDiscovery(null, new HashSet<>(), true, server); + } + if(server.getResources() != null) { + resourcesResponseList = McpToolsSyncJobExecutor.INSTANCE.handleMcpResourceDiscovery(null, new HashSet<>(), true, server); + } + if(server.getEndpoint() != null && !server.getEndpoint().isEmpty()){ + endpointsResponseList = handleMcpRequestDiscovery(server); + } List responseParamsToProcess = new ArrayList<>(); responseParamsToProcess.addAll(toolsResponseList); responseParamsToProcess.addAll(resourcesResponseList); + responseParamsToProcess.addAll(endpointsResponseList); McpToolsSyncJobExecutor.processResponseParams(apiConfig, responseParamsToProcess); // Insert when batch is full @@ -494,73 +506,45 @@ private static class ScanCacheEntry { } } + public List handleMcpRequestDiscovery(McpServer mcpServer) { - private List toolsDiscovery(McpServer mcpServer) { - String host = mcpServer.getUrl(); + String host = mcpServer.getIp() + ":" + mcpServer.getPort(); ObjectMapper mapper = new ObjectMapper(); - List responseParamsList = new ArrayList<>(); - try { - int id = 1; - String toolsCallRequestHeaders = buildHeaders(host); - for (McpSchema.Tool tool : mcpServer.getTools()) { + try { + String requestHeaders = buildHeaders(host); McpSchema.JSONRPCRequest request = new McpSchema.JSONRPCRequest( - McpSchema.JSONRPC_VERSION, - McpSchema.METHOD_TOOLS_CALL, - id++, - new McpSchema.CallToolRequest(tool.getName(), McpToolsSyncJobExecutor.generateExampleArguments(tool.getInputSchema())) - ); - - HttpResponseParams toolsCallHttpResponseParams = McpToolsSyncJobExecutor.convertToAktoFormat(0, - mcpServer.getUrl(), - toolsCallRequestHeaders, - HttpMethod.POST.name(), - mapper.writeValueAsString(request), - new OriginalHttpResponse("", Collections.emptyMap(), HttpStatus.SC_OK)); - - if (toolsCallHttpResponseParams != null) { - responseParamsList.add(toolsCallHttpResponseParams); - } - } - } catch (Exception e) { - logger.error("Error while discovering mcp tools for hostname: {}", host, e); - } - return responseParamsList; - } - - - private List resourcesDiscovery(McpServer mcpServer) { - String host = mcpServer.getUrl(); - ObjectMapper mapper = new ObjectMapper(); - - List responseParamsList = new ArrayList<>(); - try { - int id = 1; - String resourceCallRequestHeaders = buildHeaders(host); - for (McpSchema.Resource resource : mcpServer.getResources()) { - McpSchema.JSONRPCRequest request = new McpSchema.JSONRPCRequest( - McpSchema.JSONRPC_VERSION, - McpSchema.METHOD_RESOURCES_READ, - id++, - new McpSchema.ReadResourceRequest(resource.getUri()) - ); - - HttpResponseParams readResourceHttpResponseParams = McpToolsSyncJobExecutor.convertToAktoFormat(0, - mcpServer.getUrl(), - resourceCallRequestHeaders, - HttpMethod.POST.name(), - mapper.writeValueAsString(request), - new OriginalHttpResponse("", Collections.emptyMap(), HttpStatus.SC_OK)); + McpSchema.JSONRPC_VERSION, + McpSchema.METHOD_PING, + String.valueOf(1), + new McpSchema.InitializeRequest( + McpSchema.LATEST_PROTOCOL_VERSION, + new McpSchema.ClientCapabilities( + null, + null, + null + ), + new McpSchema.Implementation("akto-api-recon-scan", "1.0.0") + ) + ); + + HttpResponseParams requestHttpResponseParams = McpToolsSyncJobExecutor.convertToAktoFormat(0, + mcpServer.getUrl(), + requestHeaders, + HttpMethod.GET.name(), + mapper.writeValueAsString(request), + new OriginalHttpResponse("", Collections.emptyMap(), HttpStatus.SC_OK)); + + if (requestHttpResponseParams != null) { + requestHttpResponseParams.setSource(HttpResponseParams.Source.MCP_RECON); + responseParamsList.add(requestHttpResponseParams); + } - if (readResourceHttpResponseParams != null) { - responseParamsList.add(readResourceHttpResponseParams); - } + } catch (Exception e) { + logger.error("Error while discovering mcp resources for hostname: {}", host, e); } - } catch (Exception e) { - logger.error("Error while discovering mcp resources for hostname: {}", host, e); + return responseParamsList; } - return responseParamsList; - } private String buildHeaders(String host) { return "{\"Content-Type\":\"application/json\",\"Accept\":\"*/*\",\"host\":\"" + host + "\"}"; diff --git a/apps/mini-runtime/src/main/java/com/akto/hybrid_runtime/McpToolsSyncJobExecutor.java b/apps/mini-runtime/src/main/java/com/akto/hybrid_runtime/McpToolsSyncJobExecutor.java index 644e8aba50..46f58fe7e2 100644 --- a/apps/mini-runtime/src/main/java/com/akto/hybrid_runtime/McpToolsSyncJobExecutor.java +++ b/apps/mini-runtime/src/main/java/com/akto/hybrid_runtime/McpToolsSyncJobExecutor.java @@ -33,6 +33,7 @@ import com.akto.util.Constants; import com.akto.util.JSONUtils; import com.akto.util.Pair; +import com.akto.utils.McpServer; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.module.SimpleModule; import io.swagger.oas.inflector.examples.ExampleBuilder; @@ -102,9 +103,9 @@ public void runJob(APIConfig apiConfig) { List initResponseList = initializeMcpServerCapabilities(apiCollection, normalizedSampleDataSet); List toolsResponseList = handleMcpToolsDiscovery(apiCollection, - normalizedSampleDataSet); + normalizedSampleDataSet, false, null); List resourcesResponseList = handleMcpResourceDiscovery(apiCollection, - normalizedSampleDataSet); + normalizedSampleDataSet, false, null); List responseParamsToProcess = new ArrayList<>(); responseParamsToProcess.addAll(initResponseList); responseParamsToProcess.addAll(toolsResponseList); @@ -153,123 +154,190 @@ private List initializeMcpServerCapabilities(ApiCollection a return responseParamsList; } - private List handleMcpToolsDiscovery(ApiCollection apiCollection, - Set normalizedSampleDataSet) { - String host = apiCollection.getHostName(); + public List handleMcpToolsDiscovery(ApiCollection apiCollection, + Set normalizedSampleDataSet, boolean isRecon, McpServer mcpServer) { + String host =""; List responseParamsList = new ArrayList<>(); - try { - if (mcpServerCapabilities != null && mcpServerCapabilities.getTools() == null) { - logger.debug("Skipping tools discovery as MCP server capabilities do not support tools."); - return responseParamsList; - } - - Pair toolsListResponsePair = getMcpMethodResponse( - host, McpSchema.METHOD_TOOLS_LIST, MCP_TOOLS_LIST_REQUEST_JSON, apiCollection); + if(isRecon) { + host = mcpServer.getIp() + ":" + mcpServer.getPort(); - if (toolsListResponsePair.getSecond() != null && !normalizedSampleDataSet.contains( - McpSchema.METHOD_TOOLS_LIST)) { - responseParamsList.add(toolsListResponsePair.getSecond()); - } - logger.debug("Received tools/list response. Processing tools....."); - - ListToolsResult toolsResult = JSONUtils.fromJson(toolsListResponsePair.getFirst().getResult(), - ListToolsResult.class); - - if (toolsResult != null && !CollectionUtils.isEmpty(toolsResult.getTools())) { - int id = 2; - String urlWithQueryParams = toolsListResponsePair.getSecond().getRequestParams().getURL(); + try { + int id = 1; String toolsCallRequestHeaders = buildHeaders(host); - - for (Tool tool : toolsResult.getTools()) { - if (normalizedSampleDataSet.contains(McpSchema.METHOD_TOOLS_CALL + "/" + tool.getName())) { - logger.debug("Skipping tool {} as it is already present in the db.", tool.getName()); - continue; - } - JSONRPCRequest request = new JSONRPCRequest( - McpSchema.JSONRPC_VERSION, - McpSchema.METHOD_TOOLS_CALL, - id++, - new CallToolRequest(tool.getName(), generateExampleArguments(tool.getInputSchema())) + for (McpSchema.Tool tool : mcpServer.getTools()) { + McpSchema.JSONRPCRequest request = new McpSchema.JSONRPCRequest( + McpSchema.JSONRPC_VERSION, + McpSchema.METHOD_TOOLS_CALL, + id++, + new McpSchema.CallToolRequest(tool.getName(), McpToolsSyncJobExecutor.generateExampleArguments(tool.getInputSchema())) ); - HttpResponseParams toolsCallHttpResponseParams = convertToAktoFormat(apiCollection.getId(), - urlWithQueryParams, - toolsCallRequestHeaders, - HttpMethod.POST.name(), - mapper.writeValueAsString(request), - new OriginalHttpResponse("", Collections.emptyMap(), HttpStatus.SC_OK)); + HttpResponseParams toolsCallHttpResponseParams = McpToolsSyncJobExecutor.convertToAktoFormat(0, + mcpServer.getUrl(), + toolsCallRequestHeaders, + HttpMethod.POST.name(), + mapper.writeValueAsString(request), + new OriginalHttpResponse("", Collections.emptyMap(), HttpStatus.SC_OK)); if (toolsCallHttpResponseParams != null) { + toolsCallHttpResponseParams.setSource(Source.MCP_RECON); responseParamsList.add(toolsCallHttpResponseParams); } } - } else { - logger.debug("Skipping as List Tools Result is null or Tools are empty"); + } catch (Exception e) { + logger.error("Error while discovering mcp tools for hostname: {}", host, e); } - } catch (Exception e) { - logger.error("Error while discovering mcp tools for hostname: {}", host, e); + return responseParamsList; } - return responseParamsList; - } - - private List handleMcpResourceDiscovery(ApiCollection apiCollection, - Set normalizedSampleDataSet) { - String host = apiCollection.getHostName(); + else { + host = apiCollection.getHostName(); + try { + if (mcpServerCapabilities != null && mcpServerCapabilities.getTools() == null) { + logger.debug("Skipping tools discovery as MCP server capabilities do not support tools."); + return responseParamsList; + } - List responseParamsList = new ArrayList<>(); - try { - if (mcpServerCapabilities != null && mcpServerCapabilities.getResources() == null) { - logger.debug("Skipping resources discovery as MCP server capabilities do not support resources."); - return responseParamsList; - } - Pair resourcesListResponsePair = getMcpMethodResponse( - host, McpSchema.METHOD_RESOURCES_LIST, MCP_RESOURCE_LIST_REQUEST_JSON, apiCollection); + Pair toolsListResponsePair = getMcpMethodResponse( + host, McpSchema.METHOD_TOOLS_LIST, MCP_TOOLS_LIST_REQUEST_JSON, apiCollection); - if (resourcesListResponsePair.getSecond() != null && !normalizedSampleDataSet.contains( - McpSchema.METHOD_RESOURCES_LIST)) { - responseParamsList.add(resourcesListResponsePair.getSecond()); + if (toolsListResponsePair.getSecond() != null && !normalizedSampleDataSet.contains( + McpSchema.METHOD_TOOLS_LIST)) { + responseParamsList.add(toolsListResponsePair.getSecond()); + } + logger.debug("Received tools/list response. Processing tools....."); + + ListToolsResult toolsResult = JSONUtils.fromJson(toolsListResponsePair.getFirst().getResult(), + ListToolsResult.class); + + if (toolsResult != null && !CollectionUtils.isEmpty(toolsResult.getTools())) { + int id = 2; + String urlWithQueryParams = toolsListResponsePair.getSecond().getRequestParams().getURL(); + String toolsCallRequestHeaders = buildHeaders(host); + + for (Tool tool : toolsResult.getTools()) { + if (normalizedSampleDataSet.contains(McpSchema.METHOD_TOOLS_CALL + "/" + tool.getName())) { + logger.debug("Skipping tool {} as it is already present in the db.", tool.getName()); + continue; + } + JSONRPCRequest request = new JSONRPCRequest( + McpSchema.JSONRPC_VERSION, + McpSchema.METHOD_TOOLS_CALL, + id++, + new CallToolRequest(tool.getName(), generateExampleArguments(tool.getInputSchema())) + ); + + HttpResponseParams toolsCallHttpResponseParams = convertToAktoFormat(apiCollection.getId(), + urlWithQueryParams, + toolsCallRequestHeaders, + HttpMethod.POST.name(), + mapper.writeValueAsString(request), + new OriginalHttpResponse("", Collections.emptyMap(), HttpStatus.SC_OK)); + + if (toolsCallHttpResponseParams != null) { + responseParamsList.add(toolsCallHttpResponseParams); + } + } + } else { + logger.debug("Skipping as List Tools Result is null or Tools are empty"); + } + } catch (Exception e) { + logger.error("Error while discovering mcp tools for hostname: {}", host, e); } - logger.debug("Received resources/list response. Processing resources....."); + return responseParamsList; + } + } - ListResourcesResult resourcesResult = JSONUtils.fromJson(resourcesListResponsePair.getFirst().getResult(), - ListResourcesResult.class); + public List handleMcpResourceDiscovery(ApiCollection apiCollection, + Set normalizedSampleDataSet, boolean isRecon, McpServer mcpServer) { - if (resourcesResult != null && !CollectionUtils.isEmpty(resourcesResult.getResources())) { - int id = 2; - String urlWithQueryParams = resourcesListResponsePair.getSecond().getRequestParams().getURL(); - String toolsCallRequestHeaders = buildHeaders(host); + String host =""; + List responseParamsList = new ArrayList<>(); - for (Resource resource : resourcesResult.getResources()) { - if (normalizedSampleDataSet.contains(McpSchema.METHOD_RESOURCES_READ + "/" + resource.getUri())) { - logger.debug("Skipping resource {} as it is already present in the db.", resource.getUri()); - continue; - } - JSONRPCRequest request = new JSONRPCRequest( - McpSchema.JSONRPC_VERSION, - McpSchema.METHOD_RESOURCES_READ, - id++, - new ReadResourceRequest(resource.getUri()) + if(isRecon) { + try { + int id = 1; + String resourceCallRequestHeaders = buildHeaders(host); + for (McpSchema.Resource resource : mcpServer.getResources()) { + McpSchema.JSONRPCRequest request = new McpSchema.JSONRPCRequest( + McpSchema.JSONRPC_VERSION, + McpSchema.METHOD_RESOURCES_READ, + id++, + new McpSchema.ReadResourceRequest(resource.getUri()) ); - HttpResponseParams readResourceHttpResponseParams = convertToAktoFormat(apiCollection.getId(), - urlWithQueryParams, - toolsCallRequestHeaders, - HttpMethod.POST.name(), - mapper.writeValueAsString(request), - new OriginalHttpResponse("", Collections.emptyMap(), HttpStatus.SC_OK)); + HttpResponseParams readResourceHttpResponseParams = McpToolsSyncJobExecutor.convertToAktoFormat(0, + mcpServer.getUrl(), + resourceCallRequestHeaders, + HttpMethod.POST.name(), + mapper.writeValueAsString(request), + new OriginalHttpResponse("", Collections.emptyMap(), HttpStatus.SC_OK)); if (readResourceHttpResponseParams != null) { + readResourceHttpResponseParams.setSource(Source.MCP_RECON); responseParamsList.add(readResourceHttpResponseParams); } } - } else { - logger.debug("Skipping as List Resource Result is null or Resources are empty"); + } catch (Exception e) { + logger.error("Error while discovering mcp resources for hostname: {}", host, e); + } + return responseParamsList; + } + else { + host = apiCollection.getHostName(); + try { + if (mcpServerCapabilities != null && mcpServerCapabilities.getResources() == null) { + logger.debug("Skipping resources discovery as MCP server capabilities do not support resources."); + return responseParamsList; + } + Pair resourcesListResponsePair = getMcpMethodResponse( + host, McpSchema.METHOD_RESOURCES_LIST, MCP_RESOURCE_LIST_REQUEST_JSON, apiCollection); + + if (resourcesListResponsePair.getSecond() != null && !normalizedSampleDataSet.contains( + McpSchema.METHOD_RESOURCES_LIST)) { + responseParamsList.add(resourcesListResponsePair.getSecond()); + } + logger.debug("Received resources/list response. Processing resources....."); + + ListResourcesResult resourcesResult = JSONUtils.fromJson(resourcesListResponsePair.getFirst().getResult(), + ListResourcesResult.class); + + if (resourcesResult != null && !CollectionUtils.isEmpty(resourcesResult.getResources())) { + int id = 2; + String urlWithQueryParams = resourcesListResponsePair.getSecond().getRequestParams().getURL(); + String toolsCallRequestHeaders = buildHeaders(host); + + for (Resource resource : resourcesResult.getResources()) { + if (normalizedSampleDataSet.contains(McpSchema.METHOD_RESOURCES_READ + "/" + resource.getUri())) { + logger.debug("Skipping resource {} as it is already present in the db.", resource.getUri()); + continue; + } + JSONRPCRequest request = new JSONRPCRequest( + McpSchema.JSONRPC_VERSION, + McpSchema.METHOD_RESOURCES_READ, + id++, + new ReadResourceRequest(resource.getUri()) + ); + + HttpResponseParams readResourceHttpResponseParams = convertToAktoFormat(apiCollection.getId(), + urlWithQueryParams, + toolsCallRequestHeaders, + HttpMethod.POST.name(), + mapper.writeValueAsString(request), + new OriginalHttpResponse("", Collections.emptyMap(), HttpStatus.SC_OK)); + + if (readResourceHttpResponseParams != null) { + responseParamsList.add(readResourceHttpResponseParams); + } + } + } else { + logger.debug("Skipping as List Resource Result is null or Resources are empty"); + } + } catch (Exception e) { + logger.error("Error while discovering mcp resources for hostname: {}", host, e); } - } catch (Exception e) { - logger.error("Error while discovering mcp resources for hostname: {}", host, e); + return responseParamsList; } - return responseParamsList; } public static void processResponseParams(APIConfig apiConfig, List responseParamsList) { diff --git a/libs/dao/src/main/java/com/akto/dto/HttpResponseParams.java b/libs/dao/src/main/java/com/akto/dto/HttpResponseParams.java index b74289d368..a1a88aee84 100644 --- a/libs/dao/src/main/java/com/akto/dto/HttpResponseParams.java +++ b/libs/dao/src/main/java/com/akto/dto/HttpResponseParams.java @@ -11,7 +11,7 @@ public class HttpResponseParams { public enum Source { - HAR, PCAP, MIRRORING, SDK, OTHER, POSTMAN + HAR, PCAP, MIRRORING, SDK, OTHER, POSTMAN, MCP_RECON } public String accountId;