Conversion of formamide to isocyanide Isocyanides are the only class of organic compounds which possess a divalent carbon. They react like a geminal nucleophilic/electrophilic synthon with oxidation of the C(II) atom to C(IV), which parallels the chemistry of carbenes and carbon monoxide.

Some of the most common methods for synthesizing isocyanides involve the dehydration of formamides. Various dehydrating agents (phosgene, phosphorus oxychloride) are used in the presence of a base (pyridine/TEA). In the follow reaction, however:

$\hspace{2.4cm}$

I'm unable to understand the role of p-TsCl, and can't work out the reaction mechanism.
Just like phosgene or phosphorus oxychloride, p-TsCl is acting as a dehydrating agent. Its affinity for oxygen atoms is fairly apparent when you consider its common use as an alcohol protecting agent. The mechanism is as follows:

$\hspace{2.6cm}$