Just a preliminary test…
This required a bit of python, since NodeGroupOutput isn’t available in the AddNode menu (for materials), and the ShaderNodeGroup don’t look up to materials’ node_trees.
But still, it works without any problem.
All I did was to add a GroupOutput to the material_A, and setup as in a normal nodegroup.
bpy.data.materials['Material_A'].node_tree.nodes.new("NodeGroupOutput")
In the Material_B, add a ShaderNodeGroup, and set its node_tree to point to Material_A.node_tree.
gnode = bpy.data.materials['Material_B'].node_tree.nodes.new("ShaderNodeGroup")
gnode.node_tree = bpy.data.materials['Material_A'].node_tree