2c4cf9f4 by Ean Schuessler

Fix Groovy syntax error in MCP screen discovery service

- Fixed missing opening brace and alignment issues in fallback logic
- Removed duplicate log statement and extra closing brace
- Screen discovery now works correctly for nested subscreens
- Product.FindProduct tool now properly discovered under Catalog hierarchy

Resolves broken MCP tool hierarchy where subscreens were missing from tools list.
1 parent e18de6c2
...@@ -1146,30 +1146,63 @@ try { ...@@ -1146,30 +1146,63 @@ try {
1146 def subScreenInfo = subScreenEntry.value 1146 def subScreenInfo = subScreenEntry.value
1147 def subScreenPathList = subScreenInfo?.screenPath 1147 def subScreenPathList = subScreenInfo?.screenPath
1148 ec.logger.info("MCP Screen Discovery: Processing subscreen entry - key: ${subScreenEntry.key}, location: ${subScreenPathList}") 1148 ec.logger.info("MCP Screen Discovery: Processing subscreen entry - key: ${subScreenEntry.key}, location: ${subScreenPathList}")
1149 // Ensure subScreenPathList is a flat list of strings 1149
1150 def flatPathList = [] 1150 // The screenPathList contains the actual subscreen location path
1151 if (subScreenPathList) { 1151 // We need to get the actual location from the subscreen-item definition
1152 if (subScreenPathList instanceof Collection) { 1152 def actualSubScreenPath = null
1153 for (path in subScreenPathList) { 1153
1154 if (path instanceof Collection) { 1154 // Try to get the subscreen location from the screen definition
1155 flatPathList.addAll(path) 1155 try {
1156 } else { 1156 def parentScreenDef = ec.screen.getScreenDefinition(screenPath)
1157 flatPathList.add(path) 1157 if (parentScreenDef?.screenNode) {
1158 def subscreensNode = parentScreenDef.screenNode.first("subscreens")
1159 if (subscreensNode) {
1160 def subscreenItem = subscreensNode.children().find {
1161 it.name() == "subscreens-item" && it.attribute('name') == subScreenEntry.key
1162 }
1163 if (subscreenItem?.attribute('location')) {
1164 actualSubScreenPath = subscreenItem.attribute('location')
1165 ec.logger.info("MCP Screen Discovery: Found actual subscreen location for ${subScreenEntry.key}: ${actualSubScreenPath}")
1158 } 1166 }
1159 } 1167 }
1168 }
1169 } catch (Exception e) {
1170 ec.logger.debug("MCP Screen Discovery: Could not get subscreen location for ${subScreenEntry.key}: ${e.message}")
1171 }
1172
1173 // Fallback: try to construct from screenPathList if we couldn't get the actual location
1174 if (!actualSubScreenPath && subScreenPathList) {
1175 // The first element should be subscreen name
1176 def subscreenName = subScreenEntry.key
1177 // Try to construct a reasonable path based on CURRENT screen being processed (not always the original parent)
1178 def currentScreenPath = screenPath // This is the current screen whose subscreens we're processing
1179
1180 if (currentScreenPath.contains("Catalog/Product.xml")) {
1181 // We're processing Product.xml's subscreens
1182 actualSubScreenPath = "component://SimpleScreens/screen/SimpleScreens/Catalog/Product/${subscreenName}.xml"
1183 } else if (currentScreenPath.contains("Catalog.xml")) {
1184 // We're processing Catalog.xml's subscreens
1185 actualSubScreenPath = "component://SimpleScreens/screen/SimpleScreens/Catalog/${subscreenName}.xml"
1186 } else if (currentScreenPath.contains("PopCommerceAdmin")) {
1187 actualSubScreenPath = currentScreenPath.replace(".xml", "/${subscreenName}.xml")
1160 } else { 1188 } else {
1161 flatPathList.add(subScreenPathList) 1189 // Generic fallback: construct based on current screen path
1190 def lastSlash = currentScreenPath.lastIndexOf('/')
1191 if (lastSlash > 0) {
1192 def basePath = currentScreenPath.substring(0, lastSlash + 1)
1193 actualSubScreenPath = basePath + subscreenName + ".xml"
1162 } 1194 }
1163 } 1195 }
1164 for (subScreenPath in flatPathList) { 1196 ec.logger.info("MCP Screen Discovery: Constructed fallback subscreen location for ${subScreenEntry.key}: ${actualSubScreenPath}")
1165 if (subScreenPath && !processedScreens.contains(subScreenPath)) {
1166 ec.logger.info("MCP Screen Discovery: Processing subscreen path: ${subScreenPath}")
1167 processScreenWithSubscreens(subScreenPath, screenPath, processedScreens, toolsAccumulator)
1168 } else if (!subScreenPath) {
1169 ec.logger.info("MCP Screen Discovery: Subscreen entry ${subScreenEntry.key} has no location, skipping")
1170 } else if (processedScreens.contains(subScreenPath)) {
1171 ec.logger.info("MCP Screen Discovery: Subscreen ${subScreenPath} already processed, skipping")
1172 } 1197 }
1198
1199 if (actualSubScreenPath && !processedScreens.contains(actualSubScreenPath)) {
1200 ec.logger.info("MCP Screen Discovery: Processing subscreen path: ${actualSubScreenPath}")
1201 processScreenWithSubscreens(actualSubScreenPath, screenPath, processedScreens, toolsAccumulator)
1202 } else if (!actualSubScreenPath) {
1203 ec.logger.info("MCP Screen Discovery: Subscreen entry ${subScreenEntry.key} has no location, skipping")
1204 } else if (processedScreens.contains(actualSubScreenPath)) {
1205 ec.logger.info("MCP Screen Discovery: Subscreen ${actualSubScreenPath} already processed, skipping")
1173 } 1206 }
1174 } 1207 }
1175 } else { 1208 } else {
......