it depends on how you are spawning that inventory. if you are using a wrap box, get each item size and make the newly spawned context menu to always snap to the top left corner of the wrap box slot using some math.
for example, if each wrap box item is 90 x 90 with a 5 pixel padding on all sides, get the mouse X
position and divide by 100, Ceil (because you likely want it on the right), then multiply by 100 and subtract 5. do this for Y
but floor and add 5 instead. this will make the context menu always snap to the top right for slots with sizes of 90 and borders of 5.
heres an image of the logic