How to add transparency/alpha (material) value slider + viewport color
The context contains the current state within blender, eg bpy.context.selected_objects is a list of the selected objects while bpy.context.active_object is the active object.

While you can have an active material selected, every object can have their own active material, so it is an object property not a global context property. So in your example you want to use -

obj = context.object
mesh = obj.data
mat = obj.active_material
cmat = mat.cycles