TsgcWSAPIServer_MCP

TsgcWSAPIServer_MCP component.

Introduction

TsgcWSAPIServer_MCP exposes the Model Context Protocol (MCP) over an sgcWebSockets HTTP server endpoint. The component bridges incoming HTTP requests with the TsgcAI_MCP_Server engine so that MCP-compatible clients can negotiate sessions, enumerate prompts/resources/tools, and invoke tools through JSON-RPC style calls.

Configuration

 

Built-in HTTP endpoints (no configuration required)

When the component is attached to an HTTP server, the following endpoints and behaviors are served automatically alongside /mcp, without any new property to enable them. This enables out-of-the-box compatibility with web-based MCP connectors such as claude.ai, which require OAuth 2.1 with Dynamic Client Registration over CORS.

 

 

 

 

 

 

 

Running over stdio (TsgcAI_MCP_Server_Stdio)

Besides the HTTP transports, the MCP server engine can also run over the stdio transport. The TsgcAI_MCP_Server_Stdio host wraps the same TsgcAI_MCP_Server engine, reads newline-delimited JSON-RPC messages from standard input and writes responses to standard output (UTF-8). This is the transport used by local AI agents such as Claude Code, which spawn the server as a child process. No HTTP server, port or TLS configuration is required.

Register tools, prompts and resources on TsgcAI_MCP_Server_Stdio.MCPServer exactly as on the HTTP component, then call Run to start processing messages. Standard output is the protocol channel, so send any logging to standard error instead.

var
  oServer: TsgcAI_MCP_Server_Stdio;
  oTool: TsgcAI_MCP_Tool;
begin
  oServer := TsgcAI_MCP_Server_Stdio.Create(nil);
  try
    oServer.ServerInfo.Name := 'MyDelphiServer';
    oServer.ServerInfo.Version := '1.0';

    oTool := oServer.MCPServer.Tools.AddTool('add', 'Adds two numbers');
    oTool.InputSchema.Properties.AddProperty('a', True, aimcpjtNumber);
    oTool.InputSchema.Properties.AddProperty('b', True, aimcpjtNumber);

    oServer.MCPServer.OnMCPRequestTool := OnRequestTool;

    oServer.Run; // reads stdin, writes stdout, blocks until EOF
  finally
    oServer.Free;
  end;
end;

 

Reference