98403b75 by Ean Schuessler

Fix MCP tool naming convention for nested subscreens

- Use dot (.) only for explicitly defined subscreen items
- Use underscore (_) for automatically discovered subscreens
- Product.FindProduct now correctly named: screen_PopCommerce_screen_PopCommerceAdmin_Catalog_Product_FindProduct
- Tool execution now works with proper screen path resolution
- Resolves dot vs underscore naming convention for Moqui MCP tools
1 parent 622f2c63
...@@ -1116,8 +1116,28 @@ try { ...@@ -1116,8 +1116,28 @@ try {
1116 // Use the passed hierarchical parent tool name 1116 // Use the passed hierarchical parent tool name
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 toolName = parentToolName + "." + subscreenName 1119
1120 ec.logger.info("MCP Screen Discovery: Creating subscreen tool ${toolName} for ${screenPath} (parentToolName: ${parentToolName})") 1120 // Use dot only for explicitly defined subscreen items, underscore for automatic subscreen discovery
1121 // Check if this screen was explicitly defined in parent's subscreens-item
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
1140 ec.logger.info("MCP Screen Discovery: Creating subscreen tool ${toolName} for ${screenPath} (parentToolName: ${parentToolName}, isExplicit: ${isExplicitSubscreen}, separator: ${separator})")
1121 } else if (isSubscreen && parentScreenPath) { 1141 } else if (isSubscreen && parentScreenPath) {
1122 toolName = screenPathToToolNameWithSubscreens(screenPath, parentScreenPath) 1142 toolName = screenPathToToolNameWithSubscreens(screenPath, parentScreenPath)
1123 ec.logger.info("MCP Screen Discovery: Creating subscreen tool ${toolName} for ${screenPath} (parent: ${parentScreenPath})") 1143 ec.logger.info("MCP Screen Discovery: Creating subscreen tool ${toolName} for ${screenPath} (parent: ${parentScreenPath})")
......