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, so there is no base license to buy.
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.
OnMCPInitialize, OnMCPPing, OnMCPListTools, OnMCPResponseTool, OnMCPListPrompts, OnMCPResponsePrompt, OnMCPListResources, OnMCPResponseResource and OnMCPStreamMessage.
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, no base product required. | Open |