The Republican presidential nominee-in-waiting also praised the moderate Palestinian president, Mahmoud Abbas, saying he is committed to reaching a peace deal with Israel - though McCain is not meeting Palestinians this time.
McCain's visit to Israel is part of a weeklong trip through the Middle East and Europe. After a day of meetings with Israeli leaders, he visited Sderot, the southern Israeli border town that has been the target of thousands of crude Palestinian rockets in recent years.
"That is not a way for people to live," McCain said. "No nation in the world can be attacked incessantly and have its population killed and intimidated without responding. That's one of the first obligations of government, to provide security for its citizens." Israel has been widely criticized for military operations aimed at stopping the rocket attacks, as well as its blockade of Gaza.
While billed as routine congressional business, the visit appeared to be aimed at burnishing McCain's leadership credentials and courting Jewish voters for next fall's election. Jews make up large voting blocs in several key swing states, including Florida and Michigan, and could help influence the outcome of the election.
Though McCain did not visit Palestinian areas, Palestinian peace negotiator Saeb Erekat said the senator has always been accessible to the Palestinians and is "committed to peace." But he suggested McCain's visit was aimed more at attracting Jewish voters than promoting negotiations. "Maybe one day Palestinians will have money for your campaigns in the United States," he said.
McCain told reporters that because he was on a congressional fact-finding tour, it was not the time to discuss his campaign.
Still, in an interview published in the Jerusalem Post, McCain said he would "personally be engaged" in peace talks if elected and "give it my highest priority."
Speaking to reporters in Sderot, McCain gave strong indications that he would follow the policies of President Bush, who has promoted peace talks between Israel and the moderate Palestinian president Mahmoud Abbas, while working to isolate the Hamas government in Gaza.
Hamas seized Gaza from Abbas' forces last June, and Abbas now rules from the West Bank.
McCain did not meet with Abbas during his two-day visit, but said he spoke to the Palestinian leader by telephone. McCain said the Palestinian leader is committed to reaching a peace deal with Israel, though he questioned whether a target of an agreement this year is realistic.
"I hope that he can deliver. I think he is sincere," McCain said. "I think the Palestinian people desire peace. I believe they deserve peace, and I think President Abbas is capable of conducting those negotiations."
Discussing the U.S. role, McCain said there has to be "an environment of reconciliation between parties," but that "there also has to be an outside party that is willing to bring the parties to the table and facilitate that process." He said a peace agreement is a key U.S. interest.
Israel and the Palestinians launched peace talks at a U.S.-hosted conference in Annapolis, Maryland, last November. The sides have made little visible progress. Israeli Prime Minister Ehud Olmert has warned that even if a deal is reached this year, it cannot be carried out until Abbas regains control of Gaza.
The Palestinians seek an independent state in the West Bank and Gaza Strip - territories that lie on opposite sides of Israel. Hamas is committed to Israel's destruction and opposes the peace talks.
Israel frequently conducts military operations in Gaza in response to rockets fired by Hamas and other militant groups. A recent Israeli offensive killed more than 120 Palestinians, including dozens of civilians, drawing heavy international criticism. Since ending the operation, there has been a relative lull, and Israeli defense officials have confirmed they are working through Egyptian mediators to reach a truce with Hamas.
McCain said he would respect any Israeli decision but questioned the wisdom of negotiating with the Islamic militants.
"The Palestinian authority in Gaza is committed to the extermination of the state of Israel. It is very difficult to negotiate with an organization that is dedicated to your extermination," he said.
In Gaza, Hamas spokesman Sami Abu Zuhri said McCain's comments shows "there isn't the faintest hope" for a change in American policies. He called on the Arab world to reconsider its ties with the U.S.