TTMSMCPServer turns a Delphi application into a Model Context Protocol server: a JSON-RPC 2.0 endpoint that advertises what the application can do and lets an AI agent call it. The server owns three collections — tools it can execute, resources it can read, and prompts it can supply — and handles the rest of the protocol around them: capability negotiation across four protocol versions, per-session state, change notifications, pagination, sampling, elicitation, long-running tasks, logging, completions, and an extensions framework.
procedure TForm1.FormCreate(Sender: TObject);
begin
Server := TTMSMCPServer.Create(Self);
Server.ServerName := 'InventoryServer';
Server.ServerVersion := '1.0.0';
Server.ServerDescription := 'Read-only access to the warehouse inventory';
Server.Tools.RegisterTool('stock_level',
'Returns the number of units on hand for a product',
function(const Args: array of TValue): TValue
begin
Result := StockLevel(Args[0].AsString);
end,
ptInteger);
{ With no Transport assigned the server uses STDIO. }
Server.Start;
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
Server.Stop;
end;