Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ public class DbAction extends ActionSupport {
Account account;
int vxlanId;
String name;
String registryStatus;
List<String> cidrList;
List<BasicDBObject> apiInfoList;
List<BulkUpdates> writesForFilterSampleData;
Expand Down Expand Up @@ -305,6 +306,15 @@ public String updateApiCollectionNameForVxlan() {
return Action.SUCCESS.toUpperCase();
}

public String updateApiCollectionRegistryStatus() {
try {
DbLayer.updateApiCollectionRegistryStatus(apiCollectionId, registryStatus);
} catch (Exception e) {
return Action.ERROR.toUpperCase();
}
return Action.SUCCESS.toUpperCase();
}

public String updateCidrList() {
try {
DbLayer.updateCidrList(cidrList);
Expand Down
11 changes: 11 additions & 0 deletions apps/database-abstractor/src/main/resources/struts.xml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,17 @@
</result>
</action>

<action name="api/updateApiCollectionRegistryStatus" class="com.akto.action.DbAction" method="updateApiCollectionRegistryStatus">
<interceptor-ref name="json"/>
<interceptor-ref name="defaultStack" />
<result name="SUCCESS" type="json"/>
<result name="ERROR" type="json">
<param name="statusCode">422</param>
<param name="ignoreHierarchy">false</param>
<param name="includeProperties">^actionErrors.*</param>
</result>
</action>

<action name="api/updateCidrList" class="com.akto.action.DbAction" method="updateCidrList">
<interceptor-ref name="json"/>
<interceptor-ref name="defaultStack" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import com.akto.hybrid_parsers.HttpCallParser;
import com.akto.log.LoggerMaker;
import com.akto.log.LoggerMaker.LogDb;
import com.akto.mcp.McpRegistryUtils;
import com.akto.mcp.McpSchema;
import com.akto.mcp.McpSchema.CallToolRequest;
import com.akto.mcp.McpSchema.ClientCapabilities;
Expand Down Expand Up @@ -64,6 +65,13 @@ public class McpToolsSyncJobExecutor {
public static final String LOCAL_IP = "127.0.0.1";
private ServerCapabilities mcpServerCapabilities = null;

// Configuration for MCP Registry integration
private static final String ENV_ENABLE_REGISTRY_CHECK = "ENABLE_MCP_REGISTRY_CHECK";
private static final boolean ENABLE_REGISTRY_CHECK_DEFAULT = true;
private static final boolean enableRegistryCheck = Boolean.parseBoolean(
System.getenv().getOrDefault(ENV_ENABLE_REGISTRY_CHECK, String.valueOf(ENABLE_REGISTRY_CHECK_DEFAULT))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add try catch or normal simple check of value.equals(true) and use boolean so there is no chance of null value

);

public static final McpToolsSyncJobExecutor INSTANCE = new McpToolsSyncJobExecutor();

public McpToolsSyncJobExecutor() {
Expand Down Expand Up @@ -98,9 +106,20 @@ public void runJob(APIConfig apiConfig) {
logger.info("Starting MCP sync for apiCollectionId: {} and hostname: {}", apiCollection.getId(),
apiCollection.getHostName());
try {
// Check if server is listed in official MCP Registry (if enabled)


Set<String> normalizedSampleDataSet = getNormalizedSampleData(apiCollection.getId());
List<HttpResponseParams> initResponseList = initializeMcpServerCapabilities(apiCollection,
normalizedSampleDataSet);

if (!initResponseList.isEmpty()) {
String registryStatus = McpRegistryUtils.checkAndLogRegistryStatus(apiCollection.getHostName(),
apiCollection.getDisplayName());
// Update the API collection with registry status using DataActor (cyborg)
DataActorFactory.fetchInstance().updateApiCollectionRegistryStatus(
apiCollection.getId(), registryStatus);
}
List<HttpResponseParams> toolsResponseList = handleMcpToolsDiscovery(apiCollection,
normalizedSampleDataSet);
List<HttpResponseParams> resourcesResponseList = handleMcpResourceDiscovery(apiCollection,
Expand Down Expand Up @@ -413,5 +432,6 @@ private static Set<String> getNormalizedSampleData(int apiCollectionId) {
});
return result;
}

}

11 changes: 11 additions & 0 deletions libs/dao/src/main/java/com/akto/dto/ApiCollection.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ public enum ENV_TYPE {
List<CollectionTags> tagsList;
public static final String TAGS_STRING = "tagsList";

private String registryStatus; // "available" if listed in MCP Registry, null otherwise
public static final String REGISTRY_STATUS = "registryStatus";

private static final List<String> ENV_KEYWORDS_WITH_DOT = Arrays.asList(
"staging", "preprod", "qa", "demo", "dev", "test", "svc",
"localhost", "local", "intranet", "lan", "example", "invalid",
Expand Down Expand Up @@ -389,4 +392,12 @@ public boolean isGenAICollection() {
return false;
}

public String getRegistryStatus() {
return registryStatus;
}

public void setRegistryStatus(String registryStatus) {
this.registryStatus = registryStatus;
}

}
18 changes: 18 additions & 0 deletions libs/utils/src/main/java/com/akto/data_actor/ClientActor.java
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,24 @@ public void updateApiCollectionNameForVxlan(int vxlanId, String name) {
}
}

public void updateApiCollectionRegistryStatus(int apiCollectionId, String registryStatus) {
Map<String, List<String>> headers = buildHeaders();
BasicDBObject obj = new BasicDBObject();
obj.put("apiCollectionId", apiCollectionId);
obj.put("registryStatus", registryStatus);
OriginalHttpRequest request = new OriginalHttpRequest(url + "/updateApiCollectionRegistryStatus", "", "POST", obj.toString(), headers, "");
try {
OriginalHttpResponse response = ApiExecutor.sendRequestBackOff(request, true, null, false, null);
if (response.getStatusCode() != 200) {
loggerMaker.errorAndAddToDb("non 2xx response in updateApiCollectionRegistryStatus", LoggerMaker.LogDb.RUNTIME);
return;
}
} catch (Exception e) {
loggerMaker.errorAndAddToDb("error updating api collection registry status" + e + " apiCollectionId " + apiCollectionId
+ " registryStatus " + registryStatus, LoggerMaker.LogDb.RUNTIME);
}
}

@Override
public void updateModuleInfo(ModuleInfo moduleInfo) {
Map<String, List<String>> headers = buildHeaders();
Expand Down
2 changes: 2 additions & 0 deletions libs/utils/src/main/java/com/akto/data_actor/DataActor.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ public abstract class DataActor {

public abstract void updateApiCollectionNameForVxlan(int vxlanId, String name);

public abstract void updateApiCollectionRegistryStatus(int apiCollectionId, String registryStatus);

public abstract APIConfig fetchApiConfig(String configName);

public abstract void bulkWriteSingleTypeInfo(List<Object> writesForApiInfo);
Expand Down
4 changes: 4 additions & 0 deletions libs/utils/src/main/java/com/akto/data_actor/DbActor.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ public void updateApiCollectionNameForVxlan(int vxlanId, String name) {
DbLayer.updateApiCollectionName(vxlanId, name);
}

public void updateApiCollectionRegistryStatus(int apiCollectionId, String registryStatus) {
DbLayer.updateApiCollectionRegistryStatus(apiCollectionId, registryStatus);
}

public APIConfig fetchApiConfig(String configName) {
return DbLayer.fetchApiconfig(configName);
}
Expand Down
7 changes: 7 additions & 0 deletions libs/utils/src/main/java/com/akto/data_actor/DbLayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,13 @@ public static void updateApiCollectionName(int vxlanId, String name) {
);
}

public static void updateApiCollectionRegistryStatus(int apiCollectionId, String registryStatus) {
ApiCollectionsDao.instance.getMCollection().updateOne(
Filters.eq(ApiCollection.ID, apiCollectionId),
Updates.set(ApiCollection.REGISTRY_STATUS, registryStatus)
);
}

public static void updateCidrList(List<String> cidrList) {
AccountSettingsDao.instance.getMCollection().updateOne(
AccountSettingsDao.generateFilter(), Updates.addEachToSet("privateCidrList", cidrList),
Expand Down
Loading
Loading