MCP Client Component — sgcAI | eSeGeCe

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, so there is no base license to buy.

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.

Events

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

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, no base product required.
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.