The chemical reactions and pathways involving the molybdopterin cofactor (Moco), essential for the catalytic activity of some enzymes, e.g. sulfite oxidase, xanthine dehydrogenase, and aldehyde oxidase. The cofactor consists of a mononuclear molybdenum (Mo-molybdopterin) or tungsten ion (W-molybdopterin) coordinated by one or two molybdopterin ligands.