Implement proper MCP tool naming convention based on hierarchy level
- Add level parameter to processScreenWithSubscreens function - Use dot (.) only for first level subscreens (level == 1) - Use underscore (_) for all deeper levels (level > 1) - Preserves full hierarchy path in parentToolName parameter - Results in correct naming: Catalog.Product, Catalog_Product_FindProduct, Catalog_Product_Content_ContentCompare - Tool execution works with proper screen path resolution
Showing
1 changed file
with
7 additions
and
24 deletions
| ... | @@ -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, parentToolName = null -> | 1047 | processScreenWithSubscreens = { screenPath, parentScreenPath = null, processedScreens = null, toolsAccumulator = null, parentToolName = null, level = 1 -> |
| 1048 | ec.logger.info("MCP Screen Discovery: Processing screen ${screenPath} (parent: ${parentScreenPath}, parentToolName: ${parentToolName})") | 1048 | ec.logger.info("MCP Screen Discovery: Processing screen ${screenPath} (parent: ${parentScreenPath}, parentToolName: ${parentToolName}, level: ${level})") |
| 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> |
| ... | @@ -1117,27 +1117,10 @@ try { | ... | @@ -1117,27 +1117,10 @@ try { |
| 1117 | def subscreenName = screenPath.split("/")[-1] | 1117 | def subscreenName = screenPath.split("/")[-1] |
| 1118 | if (subscreenName.endsWith(".xml")) subscreenName = subscreenName.substring(0, subscreenName.length() - 4) | 1118 | if (subscreenName.endsWith(".xml")) subscreenName = subscreenName.substring(0, subscreenName.length() - 4) |
| 1119 | 1119 | ||
| 1120 | // Use dot only for explicitly defined subscreen items, underscore for automatic subscreen discovery | 1120 | // Use dot only for first level subscreens, underscore for deeper levels |
| 1121 | // Check if this screen was explicitly defined in parent's subscreens-item | 1121 | def separator = (level == 1) ? "." : "_" |
| 1122 | def isExplicitSubscreen = false | ||
| 1123 | try { | ||
| 1124 | def parentScreenDef = ec.screen.getScreenDefinition(parentScreenPath) | ||
| 1125 | if (parentScreenDef?.screenNode) { | ||
| 1126 | def subscreensNode = parentScreenDef.screenNode.first("subscreens") | ||
| 1127 | if (subscreensNode) { | ||
| 1128 | def subscreenItem = subscreensNode.children().find { | ||
| 1129 | it.name() == "subscreens-item" && it.attribute('location') == screenPath | ||
| 1130 | } | ||
| 1131 | isExplicitSubscreen = (subscreenItem != null) | ||
| 1132 | } | ||
| 1133 | } | ||
| 1134 | } catch (Exception e) { | ||
| 1135 | ec.logger.debug("Could not check explicit subscreen for ${screenPath}: ${e.message}") | ||
| 1136 | } | ||
| 1137 | |||
| 1138 | def separator = isExplicitSubscreen ? "." : "_" | ||
| 1139 | toolName = parentToolName + separator + subscreenName | 1122 | toolName = parentToolName + separator + subscreenName |
| 1140 | ec.logger.info("MCP Screen Discovery: Creating subscreen tool ${toolName} for ${screenPath} (parentToolName: ${parentToolName}, isExplicit: ${isExplicitSubscreen}, separator: ${separator})") | 1123 | ec.logger.info("MCP Screen Discovery: Creating subscreen tool ${toolName} for ${screenPath} (parentToolName: ${parentToolName}, level: ${level}, separator: ${separator})") |
| 1141 | } else if (isSubscreen && parentScreenPath) { | 1124 | } else if (isSubscreen && parentScreenPath) { |
| 1142 | toolName = screenPathToToolNameWithSubscreens(screenPath, parentScreenPath) | 1125 | toolName = screenPathToToolNameWithSubscreens(screenPath, parentScreenPath) |
| 1143 | ec.logger.info("MCP Screen Discovery: Creating subscreen tool ${toolName} for ${screenPath} (parent: ${parentScreenPath})") | 1126 | ec.logger.info("MCP Screen Discovery: Creating subscreen tool ${toolName} for ${screenPath} (parent: ${parentScreenPath})") |
| ... | @@ -1224,7 +1207,7 @@ try { | ... | @@ -1224,7 +1207,7 @@ try { |
| 1224 | 1207 | ||
| 1225 | if (actualSubScreenPath && !processedScreens.contains(actualSubScreenPath)) { | 1208 | if (actualSubScreenPath && !processedScreens.contains(actualSubScreenPath)) { |
| 1226 | ec.logger.info("MCP Screen Discovery: Processing subscreen path: ${actualSubScreenPath}") | 1209 | ec.logger.info("MCP Screen Discovery: Processing subscreen path: ${actualSubScreenPath}") |
| 1227 | processScreenWithSubscreens(actualSubScreenPath, screenPath, processedScreens, toolsAccumulator, toolName) | 1210 | processScreenWithSubscreens(actualSubScreenPath, screenPath, processedScreens, toolsAccumulator, toolName, level + 1) |
| 1228 | } else if (!actualSubScreenPath) { | 1211 | } else if (!actualSubScreenPath) { |
| 1229 | ec.logger.info("MCP Screen Discovery: Subscreen entry ${subScreenEntry.key} has no location, skipping") | 1212 | ec.logger.info("MCP Screen Discovery: Subscreen entry ${subScreenEntry.key} has no location, skipping") |
| 1230 | } else if (processedScreens.contains(actualSubScreenPath)) { | 1213 | } else if (processedScreens.contains(actualSubScreenPath)) { |
| ... | @@ -1249,7 +1232,7 @@ try { | ... | @@ -1249,7 +1232,7 @@ try { |
| 1249 | ec.logger.info("MCP Screen Discovery: Starting recursive processing from ${accessibleScreens.size()} base screens") | 1232 | ec.logger.info("MCP Screen Discovery: Starting recursive processing from ${accessibleScreens.size()} base screens") |
| 1250 | for (screenPath in accessibleScreens) { | 1233 | for (screenPath in accessibleScreens) { |
| 1251 | ec.logger.info("MCP Screen Discovery: SCREEN PATH ${screenPath}") | 1234 | ec.logger.info("MCP Screen Discovery: SCREEN PATH ${screenPath}") |
| 1252 | processScreenWithSubscreens(screenPath, null, processedScreens, tools, null) | 1235 | processScreenWithSubscreens(screenPath, null, processedScreens, tools, null, 1) |
| 1253 | } | 1236 | } |
| 1254 | ec.logger.info("MCP Screen Discovery: Recursive processing found ${tools.size()} total tools") | 1237 | ec.logger.info("MCP Screen Discovery: Recursive processing found ${tools.size()} total tools") |
| 1255 | 1238 | ... | ... |
-
Please register or sign in to post a comment