The president thanked senators for their well wishes for his wife, Melania, who was at Walter Reed National Military Medical Center recovering from what the White House said was a medical procedure to treat a kidney condition, then he talked about her popularity. Mrs. Trump, he said, had really great poll numbers — so great that he has told her not to run against him.

And he recounted how he persuaded President Xi Jinping of China to release three American college basketball players arrested in Hangzhou, China, for shoplifting luxury goods, according to three people who were present or were told about his comments. Mr. Trump joked about the episode, marveling that three 7-foot-tall athletes could think that they could get away with stealing in a country where most people, he said, are around five feet tall.

Senators left the meeting privately comparing Mr. Trump’s freewheeling performance to a comedy club routine, according to one person briefed on the lunch.

“The president was in a very good mood,” Senator Mitch McConnell of Kentucky, the majority leader, told reporters later, “and really quite funny.”

Mr. Trump offered an update on negotiations on the North American Free Trade Agreement, calling it a “bad deal,” but said that the talks on revising it were going well and that it would soon become clear if a new version could be struck.

He also spoke about his priorities, including funding his long-promised wall on the southern border with Mexico, an item he has so far failed to get Congress to deliver. And he said he would become a fixture on the campaign trail to help Republicans defend their majority.

“Mostly, we didn’t interrupt the president; we let him talk,” said Senator John Kennedy, Republican of Louisiana. “It was a very honest, unvarnished, ‘here’s what I’m thinking’ speech. He said he feels very confident about the midterms.”