Table of Contents

Getting Started

TMS AI Studio adds a Model Context Protocol (MCP) client, an MCP server, and a set of cloud AI components to your Delphi or C++Builder application. Use the MCP server to expose your application's own tools, resources, and prompts to any MCP-compatible client (an IDE assistant, a chat client, another TMS AI Studio application); use the MCP client and the cloud AI components to let your application query an LLM directly, call MCP tools on its behalf, and optionally run a local or remote MCP server process for it.

Prerequisites

  • Delphi 11 Alexandria or newer, for the FMX or VCL framework.
  • Add TMSAIStudioPkg (runtime), TMSAIStudioPkgExtensions (extra registered tool-set components), and TMSAIStudioPkgDE (design-time editors) to your project or library path.

Building a minimal MCP server

A server exposes tools over a transport. The Streamable HTTP transport is the most broadly compatible choice for a standalone server process:

procedure TForm1.FormCreate(Sender: TObject);
var
  Transport: TTMSMCPStreamableHTTPTransport;
  Server: TTMSMCPServer;
  Tool: TTMSMCPTool;
begin
  Transport := TTMSMCPStreamableHTTPTransport.Create(Self, 8934, '/mcp');

  Server := TTMSMCPServer.Create(Self);
  Server.ServerName := 'My MCP Server';
  Server.ServerVersion := '1.0.0';
  Server.Transport := Transport;

  Tool := Server.Tools.Add;
  Tool.Name := 'echo';
  Tool.Description := 'Echoes the input text back to the caller';
  Tool.Method :=
    function(const Args: array of TValue): TValue
    begin
      Result := Args[0].AsString;
    end;

  Transport.Start;
end;

Server.Tools is a collection of TTMSMCPTool instances — set Method to an anonymous function to handle the tool call inline, or use OnExecute/DynamicMethod for more control. Register resources through Server.Resources and reusable prompt templates through Server.Prompts.

Connecting an MCP client to a service and a server

A client can talk to an LLM service directly, and separately drive one or more MCP server processes it starts or connects to:

{ Client is declared as a form field: Client: TTMSMCPClient; }
procedure TForm1.FormCreate(Sender: TObject);
var
  ServerItem: TTMSMCPClientServerItem;
begin
  Client := TTMSMCPClient.Create(Self);
  Client.OnExecuted := ClientExecuted;

  { Select and configure the LLM service used to interpret queries and tool calls }
  Client.Service := aiOpenAI;
  Client.APIKeys.OpenAI := 'my-openai-key';

  { Add and start a local MCP server process over STDIO }
  ServerItem := Client.Servers.Add;
  ServerItem.Command := 'path-to\my-server.exe';
  ServerItem.Args.Add('-myarg1');
  ServerItem.EnvironmentVariables.Add('MYVAR=myvalue');
  ServerItem.Start;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  Client.Execute('My query or question');
end;

procedure TForm1.ClientExecuted(Sender: TObject; AResponse: string;
  AHttpStatusCode: Integer; AHttpResult: string);
begin
  if AResponse <> '' then
    ShowMessage(AResponse);
end;

Client.Execute sends a query to the configured Service (OpenAI, Claude, Gemini, and others); OnBeforeUseTool lets the application approve or deny a tool call before it runs, and ToolCallMode controls whether tool calls are confirmed automatically or interactively.

Next steps

  • Components — browse every registered component and its API reference.
  • API reference — full class-level reference.