David Gibson is facing a jail term over the attack on Dr Douglas Walker at the Links Health Centre in Montrose, Angus, last year.
Gibson had had an appointment with Dr Walker that morning and appeared upset.
He said he had tried to speak to his mental health support team but no-one was available and left in an “agitated manner”.
At 4pm Gibson then called and spoke to staff member Susan Aitken saying he had four knives and was going to stab someone in order to get help.
The concerned receptionist called the mental health team - but was told that because it was after 4pm he would have to contact NHS 24 for help.
When Miss Aitken called him back and told him he said he was “about to stab someone” and hung up - prompting the surgery to contact police.
They went to his home in The Mall, Montrose, but were too late to catch him.
Fiscal depute Stewart Duncan told the court that at 4.45pm unemployed Gibson turned up at the surgery and went on the rampage.
He said: “Multiple 999 calls were made asking for the police to attend.
“The accused entered the front door of the locus holding a knife and stripped off his T-shirt and jacket. He then roared loudly and proceeded to Dr Walker’s room.
“People were fleeing and running out of the building.
“Dr Walker was with a patient and the accused shouted at the patient to get out before turning to the doctor, shouting: ‘Remember me, it’s not so funny now.’”
The court heard the accused then attacked the doctor with the knife and the doctor pushed him away with his feet.
Mr Duncan added: “Gibson attacked him again, lunging at him with the knife, which sliced the webbing between his thumb and forefinger.”
The doctor was able to grab the accused and the knife and wrestle him out of the room before locking the door.
Gibson then charged towards members of the public in the reception area before going back and repeatedly stabbing Dr Walker’s door with the knife.
Police arrived and members of the public were seen to be leaving in distress and others were running into rooms and offices in an attempt to hide from the accused, the court heard.
Officers told him to drop the knife, which he did and he was arrested.
Gibson, 42, a prisoner at HMP Perth, admitted three charges at Dundee Sheriff Court of rampaging through the building brandishing a knife and causing panic, fear and alarm to members of the public, severely injuring a doctor with a knife and repeatedly striking the doctor’s door with a knife, on September 25 last year.
Defence Solicitor Ross Donnelly, for Gibson, said his client had mental health issues and asked the sheriff to defer sentence for background and psychiatric reports.
Sheriff Alastair Carmichael deferred sentence for social work and psychiatric reports and for a restriction of liberty order assessment until February 19.
Gibson was remanded in custody.