Communications were a significant concern for the security of the region. The best means of communication and travel to California, prior to the eventual transcontinental railroad ran through Mexico (at the Isthmus of Tehuantepec) and Nicaragua (San Juan River to Lake Nicaragua, then twelve miles down a road to the Pacific to catch another boat from San Juan del Sur). Official news of the gold rush didn't hit the telegraphs until New Orleans. You could go across the Great American Desert, but that was the hard way.
Both the Mexico and Nicaragua routes presented serious concerns as they depended on the goodwill of foreign powers. In the case of Nicaragua that was especially pertinent as the United Kingdom had a declared protectorate over the Mosquito Coast that ran right up to the eastern terminus of the route. The British had even settled some recently-freed slaves from Jamaica on the land, which helped fan the flames of an especially keen paranoia about their intentions among Southern politicians. One of them, Solon Borland, managed to catch a bottle to the face while passing through Greytown, the free port at the Caribbean end of the transit. Judging from the newspaper accounts I've read, Borland seems like the kind of guy that a lot of people wanted to do that to but he was still the US Minister to Nicaragua and notionally acting in an official capacity, or close enough to it for Greytown's status as a free port, when he involved himself in the dispute that ended with the bottle to the face.
In retaliation, the USS Cyane bombarded the place and more or less leveled it. The captain in charge, who had instructions to minimize destruction of life and property, gave warning and provided for the town's evacuation. Thus no one died. That went down in early May (bottle to the face) through mid-July (bombardment) 1854, roughly contemporaneous with the end of debates over the Kansas-Nebraska Act and it's passage (signed into law on May 31), so I wouldn't say that they had Borland's example in mind specifically but the risk of a foreign power cutting off communication with the Pacific West was definitely there.
Indeed, they run back to before California was an American possession. Asa Whitney expresses them in his 1848 memorial to Congress asking land grants to build a railroad Lake Michigan to the Columbia River or Puget Sound:
this proposed road will change the present route for all the vast commerce of all Europe with Asia, bring it across our continent, make it the world tributary to us, and, at the lowest tolls, give us 25 millions of dollars per annum for transit alone. It would bind Oregon and the Pacific coast to us, and forever prevent the otherwise inevitable catastrophe of a separate nation growing up west, to rise at our decline, and control us and the world.
I've only seen the 1848 version, but David Potter's The Impending Crisis says Whitney first petitioned for on the subject in 1844. Whitney's proposal didn't win acceptance, and interest in a Pacific railroad predates the Mexican War, but it did in some ways frame the debate. The notion of funding the construction of the railroad through land grants and its building by private business took root. Whitney's railroad would have naturally carried mail and would have very much facilitated the building of telegraph lines along the same route.
Stephen Douglas, senator from Illinois, was interested enough in the railroad that one of his fellow senators, John Bell, cracked a joke about it during the debates over the Kansas-Nebraska Act. He'd been chasing the dream essentially since he came to Washington. In 1852, Douglas even floated a novel plan, which he called military colonization, to recruit a volunteer army corps which would be paid in land along the route of the telegraph and rail lines they would build. The military plan was intended to sidestep a problem which had helped frustrate past proposals: all of them save the southern most route would have to pass through unorganized Indian territory where private development was strictly forbidden by the Non-Intercourse Act of 1834. Of course, that wouldn't have solved other problems about what route the lines should take. Geography alone would have made for considerable dispute on that front, since everyone understood that the line would generate a lot of cash and guide future development but the issue also had very strong connections to the controversy over slavery. Areas opened to white settlement would in time become states, probably sooner than other areas so opened that did not have a railroad to the Pacific. (Douglas was firm in his belief that the railroad should be built to draw settlement, rather than around and facilitated by existing or contemporaneously developing settlements which would pull the rail with them as Whitney had imagined.) Thus where they built would decide whether the Union had an infusion of new free states or new slave states.
Of course Douglas eventually got step one of his original design, the organization of territory for the railroad, through Congress. I wrote a bit about that last year that might be be of interest, but it's more about the sectional politics and legislative maneuvers than the debates themselves.
You can get a rough sketch of the Greytown affair in Potter's The Impending Crisis. There's rather more on it and in better context in Allan Nevins' Ordeal of the Union, Volume Two but it is fairly dated (1947) and out of print. When I took an interest in it last year I also looked through Robert E. Mays' The Southern Dream of a Caribbean Empire and Manifest Destiny's Underworld: Filibustering in Antebellum America, but both are more concerned with extralegal activity than the bombardment and don't turn to Nicaragua until a bit later, so neither had much to say save that the town recovered quickly enough to serve as a base for filibustering. I don't know that there's a more recent or detailed source in English. Regrettably, I also don't have the Spanish to know what Nicarguan historians have probably said about it.