MCP Client / Server setup - X number of tools available on the server.
I want to prevent specific tool usage if they are a certain class of user.
To test this I implemented OnBeforeUseTool of the TMSMCPClient
procedure TForm1.MCPClientBeforeUseTool(Sender: TObject; AToolName: string;
AParam: TJSONObject; var AAllow: Boolean);
begin
ThinkingMemo.Lines.Add('<-' + AToolName + ' - ' + AParam.ToString);
AAllow := False;
end;
Using Grok - I see that it gets stuck in a loop calling the same tool over and over again.
<-run-sql - {"sql":"SELECT COUNT() AS CustomerCount FROM MAccount WHERE Type = 1"}
11/12/2025 4:50:38 PM - Tool execution not allowed: run-sql
<-run-sql - {"sql":"SELECT COUNT() AS CustomerCount FROM MAccount WHERE Type = 1"}
11/12/2025 4:50:39 PM - Tool execution not allowed: run-sql
<-run-sql - {"sql":"SELECT COUNT() AS CustomerCount FROM MAccount WHERE Type = 1"}
11/12/2025 4:50:43 PM - Tool execution not allowed: run-sql
<-run-sql - {"sql":"SELECT COUNT() AS CustomerCount FROM MAccount WHERE Type = 1"}
11/12/2025 4:50:44 PM - Tool execution not allowed: run-sql
<-run-sql - {"sql":"SELECT COUNT() AS CustomerCount FROM MAccount WHERE Type = 1"}
11/12/2025 4:50:46 PM - Tool execution not allowed: run-sql
<-run-sql - {"sql":"SELECT COUNT() AS CustomerCount FROM MAccount WHERE Type = 1"}
11/12/2025 4:50:47 PM - Tool execution not allowed: run-sql
<-run-sql - {"sql":"SELECT COUNT() AS CustomerCount FROM MAccount WHERE Type = 1"}
11/12/2025 4:50:48 PM - Tool execution not allowed: run-sql
<-run-sql - {"sql":"SELECT COUNT() AS CustomerCount FROM MAccount WHERE Type = 1"}
11/12/2025 4:50:49 PM - Tool execution not allowed: run-sql
<-run-sql - {"sql":"SELECT COUNT(*) AS CustomerCount FROM MAccount WHERE Type = 1"}
...
OpenAI - seems to be a lot better here, it tries a couple different tools and then gives up. That's more than fine.
I don't have API keys for the others, or I'd report them here.
Thoughts?