MCP Client

TsgcWSAPIClient_MCP is the client half of the Model Context Protocol. It connects to any MCP server, over HTTP, HTTP Streamable or a local stdio subprocess, lists the tools, prompts and resources it offers, and calls them from your code.

TsgcWSAPIClient_MCP

A JSON-RPC MCP client with three transports. It performs the initialize handshake, tracks the session, issues requests and answers the server-initiated ones your application chooses to support.

Component class

TsgcWSAPIClient_MCP

Purpose

Consume MCP servers

Platforms

Windows, macOS, Linux, iOS and Android

sgcAI is self-contained. This component ships inside sgcAI together with the sgcWebSockets Core runtime it is built on.

Call a tool on an MCP server

Set the transport and its options, initialize, then list and call tools, prompts and resources.

uses
  sgcAI, sgcAI_MCP_Classes, sgcAI_MCP_Types;

var
  oMCP: TsgcWSAPIClient_MCP;
begin
  oMCP := TsgcWSAPIClient_MCP.Create(nil);

  // Remote server over streamable HTTP.
  oMCP.MCPOptions.Transport      := aimcptrHttpStreamable;
  oMCP.MCPOptions.HttpOptions.URL := 'https://mcp.example.com/mcp';
  oMCP.MCPOptions.ClientInfo.Name    := 'sgc-mcp-client';
  oMCP.MCPOptions.ClientInfo.Version := '1.0.0';
  oMCP.MCPOptions.AuthenticationOptions.ApiKey.Enabled := True;
  oMCP.MCPOptions.AuthenticationOptions.ApiKey.Value   := 'mcp-...';

  oMCP.OnMCPListTools    := MCPListTools;
  oMCP.OnMCPResponseTool := MCPToolResponse;

  oMCP.Initialize;
  oMCP.ListTools;
  oMCP.RequestTool('GetTemperature', vArguments);   // vArguments: IsgcJSON
end;

// Or spawn a local MCP server as a subprocess instead:
oMCP.MCPOptions.Transport := aimcptrStdio;
oMCP.MCPOptions.StdioOptions.Command   := 'C:\tools\my-mcp-server.exe';
oMCP.MCPOptions.StdioOptions.Arguments := '--stdio';
// includes: sgcAI.hpp, sgcAI_MCP_Classes.hpp, sgcAI_MCP_Types.hpp

TsgcWSAPIClient_MCP *oMCP = new TsgcWSAPIClient_MCP(NULL);
oMCP->MCPOptions->Transport = aimcptrHttpStreamable;
oMCP->MCPOptions->HttpOptions->URL = "https://mcp.example.com/mcp";
oMCP->MCPOptions->ClientInfo->Name = "sgc-mcp-client";

oMCP->OnMCPListTools    = MCPListTools;
oMCP->OnMCPResponseTool = MCPToolResponse;

oMCP->Initialize();
oMCP->ListTools();

Key properties & methods

The members you reach for most often.

Transport

MCPOptions.Transport selects aimcptrHttp for plain JSON-RPC over POST, aimcptrHttpStreamable for keep-alive plus an SSE notification stream, or aimcptrStdio to spawn a local server as a subprocess.

HttpOptions and StdioOptions

HttpOptions carries the URL, TLS options and logging. StdioOptions carries Command, Arguments, WorkingDir, Environment and Timeout for the subprocess.

Authentication

AuthenticationOptions supports an API key, a custom header, or a full OAuth 2.0 flow including identity assertion, which is what public MCP servers increasingly require.

Session

Initialize performs the handshake and Ping checks liveness. HeartBeat sends periodic pings so an idle session is not dropped, and Session exposes the negotiated session state.

Tools, prompts and resources

ListTools and RequestTool, ListPrompts and RequestPrompt, ListResources, ListResourceTemplates and RequestResource. Lists accept a cursor argument for paging.

Subscriptions and logging

SubscribeResource and UnsubscribeResource follow a resource for changes, SetLoggingLevel adjusts server-side verbosity, and Complete asks for argument completions.

Answering the server

OnMCPListRoots, OnMCPSamplingCreateMessage and OnMCPElicitationCreate fire when the server asks the client for filesystem roots, a model completion or user input, so your application supplies the answer. A legacy (2025-11-25 or earlier) server that sends these requests directly, outside Multi Round-Trip Requests, gets its reply sent back automatically once the handler returns.

Events

OnMCPInitialize, OnMCPPing, OnMCPListTools, OnMCPResponseTool, OnMCPListPrompts, OnMCPResponsePrompt, OnMCPListResources, OnMCPResponseResource and OnMCPStreamMessage.

MCP 2026-07-28

MCPOptions.ProtocolEra selects Auto, Modern or Legacy. In Auto the client calls server/discover and falls back to the 2025-11-25 initialize handshake when the server is older. Discover, NegotiatedEra and OnMCPDiscover expose the result.

Multi Round-Trip Requests

When a server needs elicitation, sampling or roots to finish a call, OnMCPInputRequired fires with the requests. Fill the answers and the client retries with the signed requestState, up to MCPOptions.MRTR.MaxRounds.

subscriptions/listen

SubscriptionsListen opens a stream for list changes and resource updates, delivered through OnMCPListChanged and OnMCPResourcesUpdated. SubscriptionsCancel closes it.

Tasks extension

MCPOptions.Tasks.Enabled declares the extension; AutoPoll polls a running task automatically. TasksGet, TasksUpdate and TasksCancel are the manual methods, and OnMCPTaskCreated, OnMCPTaskStatus and OnMCPTaskCompleted report progress.

OAuth for MCP servers

MCPOptions.Authorization discovers protected resource metadata, registers through Client ID Metadata Documents or dynamic registration with application_type, uses PKCE and resource indicators, validates iss (RFC 9207) and keeps credentials per issuer.

Specifications & references

Authoritative sources for the services and protocols this component uses.

Keep exploring

Online HelpFull API reference and usage guide for the sgcAI components.
All sgcAI ComponentsBrowse the full feature matrix of all 15 components.
Download Free TrialConnect to a public or local MCP server from your own code.
PricingSingle, Team and Site licenses, full source code.
Best value: All-AccessEvery eSeGeCe product, Premium Support included, from €1,059/year.
See All-Access pricing

Ready to Get Started?

Download the free trial and call an MCP server from Delphi or C++ Builder.