622f2c63 by Ean Schuessler

Fix MCP tool hierarchy for nested subscreens

- Add parentToolName parameter to processScreenWithSubscreens function
- Pass hierarchical tool name through recursive subscreen processing
- SimpleScreens now appear under proper PopCommerceAdmin hierarchy
- Product.FindProduct tool correctly named: screen_PopCommerce_screen_PopCommerceAdmin_Catalog.Product.FindProduct
- Resolves issue where subscreens used file paths instead of hierarchical names
1 parent 2c4cf9f4
...@@ -1044,8 +1044,8 @@ try { ...@@ -1044,8 +1044,8 @@ try {
1044 1044
1045 // Helper function to recursively process screens and create tools directly 1045 // Helper function to recursively process screens and create tools directly
1046 def processScreenWithSubscreens 1046 def processScreenWithSubscreens
1047 processScreenWithSubscreens = { screenPath, parentScreenPath = null, processedScreens = null, toolsAccumulator = null -> 1047 processScreenWithSubscreens = { screenPath, parentScreenPath = null, processedScreens = null, toolsAccumulator = null, parentToolName = null ->
1048 ec.logger.info("MCP Screen Discovery: Processing screen ${screenPath} (parent: ${parentScreenPath})") 1048 ec.logger.info("MCP Screen Discovery: Processing screen ${screenPath} (parent: ${parentScreenPath}, parentToolName: ${parentToolName})")
1049 1049
1050 // Initialize processedScreens and toolsAccumulator if null 1050 // Initialize processedScreens and toolsAccumulator if null
1051 if (processedScreens == null) processedScreens = [] as Set<String> 1051 if (processedScreens == null) processedScreens = [] as Set<String>
...@@ -1112,7 +1112,13 @@ try { ...@@ -1112,7 +1112,13 @@ try {
1112 1112
1113 // Create tool with proper naming 1113 // Create tool with proper naming
1114 def toolName 1114 def toolName
1115 if (isSubscreen && parentScreenPath) { 1115 if (isSubscreen && parentToolName) {
1116 // Use the passed hierarchical parent tool name
1117 def subscreenName = screenPath.split("/")[-1]
1118 if (subscreenName.endsWith(".xml")) subscreenName = subscreenName.substring(0, subscreenName.length() - 4)
1119 toolName = parentToolName + "." + subscreenName
1120 ec.logger.info("MCP Screen Discovery: Creating subscreen tool ${toolName} for ${screenPath} (parentToolName: ${parentToolName})")
1121 } else if (isSubscreen && parentScreenPath) {
1116 toolName = screenPathToToolNameWithSubscreens(screenPath, parentScreenPath) 1122 toolName = screenPathToToolNameWithSubscreens(screenPath, parentScreenPath)
1117 ec.logger.info("MCP Screen Discovery: Creating subscreen tool ${toolName} for ${screenPath} (parent: ${parentScreenPath})") 1123 ec.logger.info("MCP Screen Discovery: Creating subscreen tool ${toolName} for ${screenPath} (parent: ${parentScreenPath})")
1118 } else { 1124 } else {
...@@ -1198,7 +1204,7 @@ try { ...@@ -1198,7 +1204,7 @@ try {
1198 1204
1199 if (actualSubScreenPath && !processedScreens.contains(actualSubScreenPath)) { 1205 if (actualSubScreenPath && !processedScreens.contains(actualSubScreenPath)) {
1200 ec.logger.info("MCP Screen Discovery: Processing subscreen path: ${actualSubScreenPath}") 1206 ec.logger.info("MCP Screen Discovery: Processing subscreen path: ${actualSubScreenPath}")
1201 processScreenWithSubscreens(actualSubScreenPath, screenPath, processedScreens, toolsAccumulator) 1207 processScreenWithSubscreens(actualSubScreenPath, screenPath, processedScreens, toolsAccumulator, toolName)
1202 } else if (!actualSubScreenPath) { 1208 } else if (!actualSubScreenPath) {
1203 ec.logger.info("MCP Screen Discovery: Subscreen entry ${subScreenEntry.key} has no location, skipping") 1209 ec.logger.info("MCP Screen Discovery: Subscreen entry ${subScreenEntry.key} has no location, skipping")
1204 } else if (processedScreens.contains(actualSubScreenPath)) { 1210 } else if (processedScreens.contains(actualSubScreenPath)) {
...@@ -1223,7 +1229,7 @@ try { ...@@ -1223,7 +1229,7 @@ try {
1223 ec.logger.info("MCP Screen Discovery: Starting recursive processing from ${accessibleScreens.size()} base screens") 1229 ec.logger.info("MCP Screen Discovery: Starting recursive processing from ${accessibleScreens.size()} base screens")
1224 for (screenPath in accessibleScreens) { 1230 for (screenPath in accessibleScreens) {
1225 ec.logger.info("MCP Screen Discovery: SCREEN PATH ${screenPath}") 1231 ec.logger.info("MCP Screen Discovery: SCREEN PATH ${screenPath}")
1226 processScreenWithSubscreens(screenPath, null, processedScreens, tools) 1232 processScreenWithSubscreens(screenPath, null, processedScreens, tools, null)
1227 } 1233 }
1228 ec.logger.info("MCP Screen Discovery: Recursive processing found ${tools.size()} total tools") 1234 ec.logger.info("MCP Screen Discovery: Recursive processing found ${tools.size()} total tools")
1229 1235
......