An Afghan soldier has opened fire on American troops, wounding at least seven of them, before being shot dead in a military base in northern Afghanistan, officials said, in the second so-called "insider attack" in the past week.

Abdul Qahar Araam, spokesman for the US military, said on Saturday that the attack took place at Camp Shaheen in Mazar-i-Sharif. Araam added that the soldiers returned fire and killed the attacker.

General Dawlat Waziri, a spokesman for the Afghan defence ministry, also confirmed the incident.

The Resolute Support, the international training mission to Afghanistan, announced on its Twitter feed that seven US service members were wounded, adding that there were no US fatalities.

Al Jazeera's Rob McBride, reporting from Afghanistan's capital, Kabul, said NATO soldiers were training their Afghan counterparts at the base where the attack took place.

"A source told Al Jazeera that the attack happened at the end of a training exercise," he said.

"We understand that the soldiers were getting back into their vehicle when a soldier from the Afghan national army picked up what is said to be a rocket-propelled grenade and fired it at the group of soldiers, and that is how these injuries have happened."

Another insider attack

Three US soldiers were killed and a fourth was wounded on June 11 when an Afghan soldier opened fire on them at a base in eastern Afghanistan's Nangarhar province.

Taliban claimed responsibility for that attack. Zabihullah Mujahid, a spokesman for the armed group, said at the time that a Taliban loyalist had infiltrated the Afghan army "just to attack foreign forces".

On Saturday, Mujahid praised the camp Shaheen attack in a statement sent to the media, but did not claim Taliban responsibility.

READ MORE: US troops killed in 'insider attack' in Nangarhar

In April, scores of Afghan soldiers were killed when fighters breached security at the camp, detonating explosives and shooting hundreds at a mosque and dining hall on the base. The attackers were disguised in Afghan army uniforms.

Coalition countries, led by the US, are considering sending thousands more troops to Afghanistan to help advise and assist Afghan forces struggling against Taliban and the Islamic State of Iraq and the Levant (ISIL, also known as ISIS) group.

US Secretary of Defense James Mattis said on Monday he would present options on Afghanistan to President Donald Trump "very soon".

Source: Al Jazeera and news agencies