Table of Contents

MCP Client

TTMSMCPClient is the host side of the Model Context Protocol: it holds a connection to a language model and a collection of connections to MCP servers, and routes the tool calls between them. You pick a service and a model, add one or more servers — a local process over STDIO, or a remote endpoint over SSE or streamable HTTP — and call Execute with a question. The client discovers each server's tools, advertises them to the model, executes the ones the model asks for against the server that owns them, and returns the finished answer on a single event. It also ships a ready-made settings dialog for editing servers and API keys, and a tools dialog for inspecting what a connection exposes.

Documentation

Start here Use when
Getting started You want one working question and answer through one MCP server.
User guide You want task-oriented chapters grouped by feature area.
API reference You want exact class, property, method, and event contracts.
Release notes You want the version history for this component.

Key classes

Class Role
TTMSMCPClient The component. Owns the LLM connection, the server collection, and the tool-call policy.
TTMSMCPCustomClient Base class carrying the routing implementation.
TTMSMCPClientServers The collection of MCP server connections, with JSON load and save.
TTMSMCPClientServerItem One connection: transport, command or URL, discovered tools, and its events.
TTMSMCPCustomClientConnection The protocol implementation behind a connection — handshake, requests, notifications.
TTMSMCPClientCapabilities What this client offers back to a server on one connection.
TTMSMCPClientElicitationCapability Whether the client will answer form and URL elicitation requests.
TTMSMCPCloudAI The language-model component behind the LLM property.
TTMSMCPClientSettingsDialog A finished UI for editing the server list and the API keys.
TTMSMCPClientToolsDialog A browser for the tools one connection exposes.
TTMSMCPCustomDialog Shared base for the product's dialogs.

Minimal example

procedure TForm1.FormCreate(Sender: TObject);
var
  Server: TTMSMCPClientServerItem;
begin
  { MCPClient is a TTMSMCPClient dropped on the form. }
  MCPClient.Service := aiOpenAI;
  MCPClient.APIKeys.OpenAI := GetEnvironmentVariable('OPENAI_API_KEY');
  MCPClient.Settings.OpenAIModel := 'gpt-4o-mini';
  MCPClient.OnExecuted := DoExecuted;

  { Let every discovered tool run without asking first. }
  MCPClient.ToolCallMode := tcmAllow;

  Server := MCPClient.Servers.Add;
  Server.DisplayName := 'Reports';
  Server.TransportType := ttSTDIO;
  Server.Command := 'my-mcp-server.exe';
  Server.Args.Add('--root');
  Server.Args.Add('C:\Reports');
  Server.OnGetToolsList := DoServerToolsReady;

  { Start returns before the handshake finishes, so leave the button
    disabled until the server has answered tools/list. }
  AskButton.Enabled := False;
  Server.Start;
end;

procedure TForm1.DoServerToolsReady(Sender: TObject);
begin
  { MCPClient.Tools now holds the tools the model may call. }
  AskButton.Enabled := True;
end;

procedure TForm1.AskButtonClick(Sender: TObject);
begin
  MCPClient.Execute('Summarise the newest report in the reports folder.');
end;

procedure TForm1.DoExecuted(Sender: TObject; AResponse: string;
  AHttpStatusCode: Integer; AHttpResult: string);
begin
  if AResponse <> '' then
    ShowAnswer(AResponse)
  else
    ShowAnswer(Format('The request failed (HTTP %d): %s',
      [AHttpStatusCode, AHttpResult]));
end;

API map

Role Types
Client TTMSMCPClient, TTMSMCPCustomClient, TTMSMCPClientToolCallMode
Servers TTMSMCPClientServers, TTMSMCPClientServerItem, TTMSMCPCustomClientConnection
Capabilities and roots TTMSMCPClientCapabilities, TTMSMCPClientElicitationCapability, TTMSMCPClientRootCapability, TTMSMCPClientRootItem, TTMSMCPClientRootItems, TTMSMCPClientServerUserResponse
Transports TTMSMCPClientTransportType, TTMSMCPClientTransport, TTMSMCPClientTransportSTDIO, TTMSMCPClientTransportSSE, TTMSMCPClientTransportHTTP
Language model TTMSMCPCloudAI, TTMSMCPCloudAIService, TTMSMCPCloudAIAPIKeys, TTMSMCPCloudAISettings, TTMSMCPCloudAITools, TTMSMCPCloudAITool
Dialogs TTMSMCPClientSettingsDialog, TTMSMCPClientToolsDialog, TTMSMCPCustomDialog, TTMSMCPClientToolsDialogInitListboxEvent
Protocol plumbing TTMSMCPClientRequestType, TTMSMCPClientNotificationType, TTMSMCPLoggingLevel, EMCPClientException
Events TTMSMCPClientAIResultEvent, TTMSMCPClientLoggingEvent, TTMSMCPClientBeforeUseToolEvent, TTMSMCPClientServerErrorEvent, TTMSMCPClientServerChangeEvent, TTMSMCPClientServerLoggingEvent, TTMSMCPClientServerElicitationEvent, TTMSMCPClientServerBeforeHTTPRequestEvent, TTMSMCPClientServerHTTPResponseEvent

Guides

Guide Covers
Querying a language model Service selection and per-provider models, API keys, generation settings, the tool collection the model sees, sending a query, and reading the answer.
Connecting to MCP servers The server collection, the three client transports and their platforms, JSON configuration files, tool discovery and routing, approving tool calls, elicitation, and logging.
The settings and tools dialogs Wiring the settings dialog to a client, persisting what it changes, and showing the tools dialog for a connection.

See Also