MCP Server Component — sgcAI | eSeGeCe

MCP Server

TsgcWSAPIServer_MCP turns an sgc HTTP or WebSocket server into a Model Context Protocol server. Publish your own tools, prompts and resources, and any MCP-aware client, an IDE agent, a desktop assistant or your own code, can call into your application.

TsgcWSAPIServer_MCP

The server half of MCP. It parses JSON-RPC at your endpoint, manages sessions, raises an event per tool, prompt or resource request, and can push notifications and server-initiated requests back to the client.

Component class

TsgcWSAPIServer_MCP

Purpose

Host tools for AI clients

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.

Publish your tools to AI clients

Attach the API to a server, fill in ServerInfo, handle the request events, set Active.

uses
  sgcAI, sgcAI_MCP_Classes, sgcHTTP_Server;

var
  oMCP: TsgcWSAPIServer_MCP;
begin
  oMCP := TsgcWSAPIServer_MCP.Create(nil);
  oMCP.Server := sgcHTTPServer1;
  oMCP.EndpointOptions.Endpoint := '/mcp';

  oMCP.MCPOptions.ServerInfo.Name    := 'sgc-mcp-server';
  oMCP.MCPOptions.ServerInfo.Version := '1.0.0';
  oMCP.MCPOptions.SessionTimeout     := 300;

  // Streamable HTTP enables notifications and server to client requests.
  oMCP.TransportOptions.Http.Enabled           := True;
  oMCP.TransportOptions.HttpStreamable.Enabled := True;

  oMCP.OnMCPInitialize     := SrvInitialize;
  oMCP.OnMCPSessionNew     := SrvSessionNew;
  oMCP.OnMCPRequestTool    := SrvCallTool;
  oMCP.OnMCPRequestPrompt  := SrvGetPrompt;
  oMCP.OnMCPRequestResource := SrvReadResource;

  sgcHTTPServer1.Active := True;

  // Tell every connected session the tool list changed.
  oMCP.SendNotificationToolsListChanged;
end;
// includes: sgcAI.hpp, sgcAI_MCP_Classes.hpp, sgcHTTP_Server.hpp

TsgcWSAPIServer_MCP *oMCP = new TsgcWSAPIServer_MCP(NULL);
oMCP->Server = sgcHTTPServer1;
oMCP->EndpointOptions->Endpoint = "/mcp";

oMCP->MCPOptions->ServerInfo->Name    = "sgc-mcp-server";
oMCP->MCPOptions->ServerInfo->Version = "1.0.0";

oMCP->TransportOptions->HttpStreamable->Enabled = true;
oMCP->OnMCPRequestTool = SrvCallTool;

sgcHTTPServer1->Active = true;

Key properties & methods

The members you reach for most often.

Server points at the HTTP or WebSocket server that listens, and EndpointOptions.Endpoint is the path the JSON-RPC requests arrive on.

MCPOptions

ServerInfo is what clients see during the handshake. SessionTimeout expires idle sessions, TasksSupported advertises the tasks capability, and AuthenticationOptions covers API key, custom header and OAuth 2.0.

TransportOptions

Http.Enabled serves plain JSON-RPC over POST. HttpStreamable.Enabled adds keep-alive plus the SSE notification stream, which is what makes notifications and server-initiated requests possible. HttpStreamable.ValidateOrigin pins a session to its original Origin header.

Catalogues

Tools, Prompts, Resources and ResourceTemplates hold what the server advertises. Fill them at startup or change them at runtime and send the matching list-changed notification.

Request events

OnMCPRequestTool, OnMCPRequestPrompt and OnMCPRequestResource are where your code does the work. OnMCPInitialize, OnMCPSessionNew and OnMCPSessionEnd track the session lifecycle, and OnMCPException reports failures.

Notifications

SendNotificationToolsListChanged, SendNotificationPromptsListChanged, SendNotificationResourcesListChanged, SendNotificationResourcesUpdated and SendLogMessage push updates to connected sessions.

Server-initiated requests

RequestRootsList, RequestSamplingCreateMessage and RequestElicitationCreate let the server ask the client for filesystem roots, a model completion or user input, answered on the matching OnMCPResponse* event.

Built-in OAuth 2.0

The component implements the authorization server side of the MCP auth flow, including dynamic client registration, a consent page, PKCE and refresh tokens, so an agent can authorize against your server without a separate identity service.

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 TrialExpose your own application logic to an AI client.
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 let an AI agent call into your application through MCP.