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 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.
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.
TsgcWSAPIClient_MCP
Consume MCP servers
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.
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();
The members you reach for most often.
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 carries the URL, TLS options and logging. StdioOptions carries Command, Arguments, WorkingDir, Environment and Timeout for the subprocess.
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.
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.
ListTools and RequestTool, ListPrompts and RequestPrompt, ListResources, ListResourceTemplates and RequestResource. Lists accept a cursor argument for paging.
SubscribeResource and UnsubscribeResource follow a resource for changes, SetLoggingLevel adjusts server-side verbosity, and Complete asks for argument completions.
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.
OnMCPInitialize, OnMCPPing, OnMCPListTools, OnMCPResponseTool, OnMCPListPrompts, OnMCPResponsePrompt, OnMCPListResources, OnMCPResponseResource and OnMCPStreamMessage.
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.
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.
SubscriptionsListen opens a stream for list changes and resource updates, delivered through OnMCPListChanged and OnMCPResourcesUpdated. SubscriptionsCancel closes it.
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.
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.
Authoritative sources for the services and protocols this component uses.
| Online HelpFull API reference and usage guide for the sgcAI components. | Open | |
| All sgcAI ComponentsBrowse the full feature matrix of all 15 components. | Open | |
| Download Free TrialConnect to a public or local MCP server from your own code. | Open | |
| PricingSingle, Team and Site licenses, full source code. | Open |