I have tried using MCP tools with Ollama, but it is very unstable.
To see the problem in the AIsimple example, I added these lines to FormCreate:
TMSMCPCloudAI1.Settings.OllamaHost:='http://192.168.10.10'; // my server
TMSMCPCloudAI1.Settings.OllamaModel:='qwen3:8b'; // any model
with TMSMCPCloudAI1.Tools.Add do
begin
Name := 'getDatetime';
Description := 'get current date and time';
&Type := ttFunction;
onexecute := getdatetime;
end;
TMSMCPCloudAI1.Service :=a iOllama;
Memo1.Lines.Text := 'What time is it?';
Function is very basic:
procedure TForm1.getdatetime(Sender: TObject; Args: TJSONObject; var Result: string);
var
lSystemTime: TSystemTime;
begin
GetSystemTime(lSystemTime);
Result := DateTimeToStr((SystemTimeToDateTime(lSystemTime)));
end;
The first time you press execute, it works perfectly and the response is the date and time.
From then on, every time you try to run it again by pressing the button, you get a fatal error (access violation) corresponding to line 2149 of TMS.MCP.CloudAI (ljValue.free).
If you comment out that line, in addition to the obvious memory leak, sooner or later the model gets stuck thinking indefinitely or gives incoherent responses.