Blender scripting connect nodes
Look for the link.

Each run of script, offsetting old mix node
's location.x

Put all current mix nodes into a list.
Find any links between a mix node and the principle shader
Make a new mix node.
If there's a link attach the from node (a mix node) output to the
input of new mix node
Make link new mix node to principled shader
Move the old mix nodes.  Could do this prior... sometimes handy to post-process incase a prior step is aborted.)

Test script
import bpy
context = bpy.context
nodes = context.active_object.active_material.node_tree.nodes
links = context.active_object.active_material.node_tree.links
ps = nodes.get('Principled BSDF')


mixnodes = [n for n in nodes if n.label == &quot;mix&quot;]
mix_ps_links = [l for l in links if l.from_node.label == &quot;mix&quot; and l.to_node == ps]

# add new mix node
mix = nodes.new('ShaderNodeMixRGB')
mix.location = (-300, -200)
mix.label = &quot;mix&quot;

if mix_ps_links:
    link = mix_ps_links.pop()
    links.new(link.from_node.outputs[0], mix.inputs[0])

links.new(mix.outputs[0], ps.inputs[0])

for mix in mixnodes:
    mix.location.y -= 200

Note: I use the line in test code context = bpy.context to make it cut and paste directly into methods where context is passed, eg def execute(self, context):