Delphi MCP Components | Model Context Protocol Client & Server | eSeGeCe

Delphi MCP Components — Model Context Protocol Client and Server

Connect Delphi applications to the AI ecosystem through the Model Context Protocol: TsgcWSAPIServer_MCP exposes your application's tools, prompts and resources to AI models, and TsgcWSAPIClient_MCP consumes any MCP-compatible server. The same library ships AI API clients for OpenAI, Anthropic Claude and Google Gemini.

The bridge between AI models and your application

MCP is the emerging standard for connecting large language models to external tools and data. Instead of one custom integration per AI provider, you implement one protocol.

Model Context Protocol in Delphi means your existing VCL or FMX application can become an AI-accessible service. The protocol is JSON-RPC based and defines three primitives: tools (callable functions with typed parameters), prompts (reusable templates with arguments) and resources (data exposed through URI addressing). An MCP server publishes them; an MCP client (Claude Desktop, Cursor, or your own Delphi application) discovers and calls them.

The server component attaches to an sgcWebSockets HTTP server and supports both stdio and HTTP transports, so the same code serves a desktop AI assistant launching it as a subprocess and a remote agent calling it over the network. The client component talks JSON-RPC over HTTP or HTTP Streamable and covers the full catalogue surface: initialize, list and call tools, retrieve prompts, read resources, plus sampling and elicitation for interactive AI workflows.

MCP Server

TsgcWSAPIServer_MCP: tools, prompts, resources, stdio and HTTP transports

MCP Client

TsgcWSAPIClient_MCP: discover and call any MCP-compatible server

AI API clients

TsgcHTTP_API_OpenAI, TsgcHTTP_API_Anthropic, TsgcHTTP_API_Gemini

Compilers

Delphi 7 through RAD Studio 13, C++Builder 10.1 Berlin through 13, Lazarus 4.4.0

Both sides of the protocol

Server, client and the AI provider clients that consume what MCP exposes.

Tools with typed schemas

Tools.AddTool registers a callable function and its InputSchema properties; calls arrive in the OnMCPRequestTool event with parsed arguments and a structured response object.

Prompts & resources

Reusable prompt templates with arguments and URI-addressed resources, served through OnMCPRequestPrompt and OnMCPRequestResource.

Client catalogue surface

Initialize, ListTools, ListPrompts, ListResources, ListResourceTemplates, then RequestTool / RequestPrompt / RequestResource with event-driven responses.

Sampling & elicitation

The client supports MCP sampling (server-requested AI model interaction) and elicitation (gathering user input mid-workflow), the two interactive extensions of the protocol.

Authentication

Client-side authentication options include API keys via AuthenticationOptions.ApiKey; see the blog for OAuth2-protected MCP servers.

Two transports

Stdio for subprocess-launched servers (the Claude Desktop model) and HTTP for network deployments. One component, both channels.

AI client family

Talk to the models directly too: chat, streaming and function calling against OpenAI, Anthropic Claude and Google Gemini, plus DeepSeek, Grok, Mistral and Ollama in the same AI family.

Cross-platform

Windows 32/64, Linux 64, macOS (Intel and ARM), iOS and Android. VCL and FireMonkey, with design-time components.

Edition

The MCP server, MCP client and AI API clients are Enterprise edition features of sgcWebSockets.

An MCP server and an MCP client in Delphi

Register a tool with a typed argument on the server; discover and call it from the client.

uses
  sgcWebSocket_Server, sgcAI, sgcAI_MCP_Classes, sgcAI_MCP_Server;

procedure TForm1.SetupMCPServer;
begin
  // Attach the MCP API component to a sgcWebSockets HTTP server
  MCPServer.Server := Server;
  MCPServer.EndpointOptions.Endpoint := '/mcp';
  MCPServer.MCPOptions.ServerInfo.Name    := 'sgc-mcp-server';
  MCPServer.MCPOptions.ServerInfo.Version := '1.0.0';

  // Register a callable tool with a typed argument
  with MCPServer.Tools.AddTool('GetTemperature',
    'Get the actual temperature in a city.') do
    InputSchema.Properties.AddProperty('city', True);

  MCPServer.OnMCPRequestTool := MCPRequestTool;
  Server.Port   := 8080;
  Server.Active := True;
end;

procedure TForm1.MCPRequestTool(Sender: TObject;
  const aSession: TsgcAI_MCP_Session;
  const aRequest: TsgcAI_MCP_Request_ToolsCall;
  const aResponse: TsgcAI_MCP_Response_ToolsCall);
begin
  if aRequest.Params.Name = 'GetTemperature' then
    aResponse.Result.Content.AddText('The current temperature in ' +
      aRequest.Params.Arguments.Item[0].Value + ' is 22 Celsius');
end;
uses
  sgcAI_MCP_Client, sgcAI_MCP_Classes;

var
  MCP: TsgcWSAPIClient_MCP;
begin
  MCP := TsgcWSAPIClient_MCP.Create(nil);
  MCP.MCPOptions.HttpOptions.URL        := 'https://mcp.example.com/';
  MCP.MCPOptions.ClientInfo.Name        := 'sgc-mcp-client';
  MCP.MCPOptions.ClientInfo.Title       := 'sgc MCP demo';
  MCP.MCPOptions.ClientInfo.Version     := '1.0.0';
  MCP.MCPOptions.AuthenticationOptions.ApiKey.Enabled := True;
  MCP.MCPOptions.AuthenticationOptions.ApiKey.Value   := 'sk-mcp-...';

  MCP.OnMCPInitialize    := MCPInit;
  MCP.OnMCPListPrompts   := MCPListPrompts;
  MCP.OnMCPListTools     := MCPListTools;
  MCP.OnMCPResponseTool  := MCPToolResponse;

  MCP.Initialize;
  MCP.ListPrompts;
  MCP.ListResources;
  MCP.ListTools;
  MCP.RequestTool('GetTemperature', '{"city":"Madrid"}');
end;

What Delphi teams build with MCP

Database agents

Let an AI model query your application's data through controlled, typed tools. Read-only or read-write, your handler decides per call.

Business automation

Expose CRM, ERP or ticketing operations as MCP tools so natural-language instructions drive existing Delphi business logic.

AI-powered desktop tools

Give assistants like Claude Desktop access to a legacy application's functionality by wrapping it in a stdio MCP server.

Multi-step AI workflows

Chain tools and resources for retrieval, processing and action in a single AI-driven pipeline, orchestrated from the Delphi side.

More on MCP and AI in sgcWebSockets

MCP overview

What the Model Context Protocol is and how the server and client components divide the work.

MCP Server component

Full reference for TsgcWSAPIServer_MCP: properties, methods, events.

MCP Client component

Full reference for TsgcWSAPIClient_MCP: catalogue methods and response events.

Blog: Building an MCP server

Step-by-step walkthrough of a working Delphi MCP server.

Blog: The MCP client

Connecting a Delphi client to MCP servers and calling their tools.

Blog: MCP authentication

Securing MCP endpoints: API keys and authenticated flows from Delphi.

Best value: All-AccessEvery eSeGeCe product, Premium Support included, from €1,059/year.
See All-Access pricing

Start building with MCP today

Download the trial and run the MCP server and client demos against your favourite AI assistant.