A strong Confederate presence at Funkstown threatened any Union advance against Gen. Robert E. Lee's position near Williamsport and the Potomac River as he retreated to Virginia after the Battle of Gettysburg. Maj. Gen. J.E.B. Stuart's cavalry, posted at Funkstown, posed a serious risk to the Federal right and rear if the Union army lunged west from Boonsboro. Stuart, meanwhile, determined to wage a spirited defense to ensure Lee time to complete fortifications protecting his army and his avenue of retreat.