We review recent advances toward a comprehensive mathematical theory of T-cell immunity. A key insight is that the efficacy of the T-cell response is best analyzed in terms of T-cell receptor (TCR) avidity and the distribution of this avidity across the TCR repertoire (the 'avidity spectrum'). Modification of this avidity spectrum by a wide range of tuning and tolerance mechanisms allows the system to adapt cross-reactivity and specificity to the challenge at hand while avoiding inappropriate responses against non-pathogenic cells and tissues. Theoretical models relate molecular kinetic parameters and cellular properties to systemic level statistics such as avidity spectra. Such bridge equations are crucial for rational clinical manipulation of T cells at the molecular level.