Skip to content

Commit f2f7c47

Browse files
Apply Gemini review findings — C3 MCP Resources cleanup
Remove two redundant null checks flagged as LOW by Gemini review: - axisConfig.getServices() returns a non-null ConcurrentHashMap (initialized at construction) so the `if (services != null)` guard was unnecessary - service.getOperations() returns a non-null Iterator so the `opIter != null` check in the while-loop condition was unnecessary Also fixes indentation inside the for loop (was over-indented after the if-block removal). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent b89b2a3 commit f2f7c47

1 file changed

Lines changed: 48 additions & 50 deletions

File tree

modules/openapi/src/main/java/org/apache/axis2/openapi/OpenApiSpecGenerator.java

Lines changed: 48 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -945,60 +945,58 @@ public String generateMcpResourcesJson(HttpServletRequest request) {
945945
com.fasterxml.jackson.databind.node.ArrayNode resources = root.putArray("resources");
946946

947947
java.util.Map<String, AxisService> services = axisConfig.getServices();
948-
if (services != null) {
949-
for (AxisService service : services.values()) {
950-
String svcName = service.getName();
951-
if (isSystemService(svcName)) continue;
952-
953-
// URI: logical identifier for the resource in the MCP protocol.
954-
// Uses the "axis2://" scheme so clients can distinguish these
955-
// resources from generic HTTP URLs.
956-
String uri = "axis2://services/" + svcName;
957-
958-
// Human-readable description: service-level mcpDescription param
959-
// or auto-generated fallback.
960-
String description = getMcpStringParam(null, service, "mcpDescription",
961-
"Axis2 service: " + svcName);
962-
963-
com.fasterxml.jackson.databind.node.ObjectNode resource =
964-
resources.addObject();
965-
resource.put("uri", uri);
966-
resource.put("name", svcName);
967-
resource.put("description", description);
968-
resource.put("mimeType", "application/json");
969-
970-
// metadata sub-object: service-specific details for MCP clients
971-
// that want to introspect available operations before calling.
972-
com.fasterxml.jackson.databind.node.ObjectNode metadata =
973-
resource.putObject("metadata");
974-
metadata.put("wsdlUrl", "GET /services/" + svcName + "?wsdl");
975-
976-
// List all non-system operation names.
977-
com.fasterxml.jackson.databind.node.ArrayNode ops = metadata.putArray("operations");
978-
java.util.Iterator<AxisOperation> opIter = service.getOperations();
979-
while (opIter != null && opIter.hasNext()) {
980-
AxisOperation op = opIter.next();
981-
if (op != null && op.getName() != null) {
982-
String opName = op.getName().getLocalPart();
983-
if (opName != null && !opName.startsWith("__")) {
984-
ops.add(opName);
985-
}
948+
for (AxisService service : services.values()) {
949+
String svcName = service.getName();
950+
if (isSystemService(svcName)) continue;
951+
952+
// URI: logical identifier for the resource in the MCP protocol.
953+
// Uses the "axis2://" scheme so clients can distinguish these
954+
// resources from generic HTTP URLs.
955+
String uri = "axis2://services/" + svcName;
956+
957+
// Human-readable description: service-level mcpDescription param
958+
// or auto-generated fallback.
959+
String description = getMcpStringParam(null, service, "mcpDescription",
960+
"Axis2 service: " + svcName);
961+
962+
com.fasterxml.jackson.databind.node.ObjectNode resource =
963+
resources.addObject();
964+
resource.put("uri", uri);
965+
resource.put("name", svcName);
966+
resource.put("description", description);
967+
resource.put("mimeType", "application/json");
968+
969+
// metadata sub-object: service-specific details for MCP clients
970+
// that want to introspect available operations before calling.
971+
com.fasterxml.jackson.databind.node.ObjectNode metadata =
972+
resource.putObject("metadata");
973+
metadata.put("wsdlUrl", "GET /services/" + svcName + "?wsdl");
974+
975+
// List all non-system operation names.
976+
com.fasterxml.jackson.databind.node.ArrayNode ops = metadata.putArray("operations");
977+
java.util.Iterator<AxisOperation> opIter = service.getOperations();
978+
while (opIter.hasNext()) {
979+
AxisOperation op = opIter.next();
980+
if (op != null && op.getName() != null) {
981+
String opName = op.getName().getLocalPart();
982+
if (opName != null && !opName.startsWith("__")) {
983+
ops.add(opName);
986984
}
987985
}
986+
}
988987

989-
// Auth requirement mirrors the tool catalog heuristic.
990-
String svcLower = svcName.toLowerCase(java.util.Locale.ROOT);
991-
boolean requiresAuth;
992-
String mcpRequiresAuthParam = getMcpStringParam(null, service,
993-
"mcpRequiresAuth", null);
994-
if (mcpRequiresAuthParam != null) {
995-
requiresAuth = !"false".equalsIgnoreCase(mcpRequiresAuthParam);
996-
} else {
997-
requiresAuth = !svcLower.equals("loginservice")
998-
&& !svcLower.equals("adminconsole");
999-
}
1000-
metadata.put("requiresAuth", requiresAuth);
988+
// Auth requirement mirrors the tool catalog heuristic.
989+
String svcLower = svcName.toLowerCase(java.util.Locale.ROOT);
990+
boolean requiresAuth;
991+
String mcpRequiresAuthParam = getMcpStringParam(null, service,
992+
"mcpRequiresAuth", null);
993+
if (mcpRequiresAuthParam != null) {
994+
requiresAuth = !"false".equalsIgnoreCase(mcpRequiresAuthParam);
995+
} else {
996+
requiresAuth = !svcLower.equals("loginservice")
997+
&& !svcLower.equals("adminconsole");
1001998
}
999+
metadata.put("requiresAuth", requiresAuth);
10021000
}
10031001

10041002
log.debug("Generated MCP resources JSON ({} services)", resources.size());

0 commit comments

Comments
 (0)