eSeGeCe
software
With the release of sgcWebSockets 2025.9.0, developers can now integrate Model Context Protocol (MCP) functionality directly into their servers. This includes the ability to handle MCP Tool Requests, a key component of enabling dynamic and intelligent communication between AI models and backend services.
This guide will walk you through how MCP Tool Requests work, how to handle them in your TsgcWSAPIServer_MCP server, and how to send structured responses back to the client or AI agent.
In the MCP (Model Context Protocol) ecosystem, Tools represent capabilities that an AI model can invoke — for example, querying a database, sending an email, or fetching data from an API.
An MCP server exposes these tools via WebSockets, and clients (like AI agents) can make Tool Requests to trigger specific actions. The TsgcWSAPIServer_MCP component in sgcWebSockets simplifies the entire flow, automatically decoding MCP messages and routing them to the appropriate event handlers in your server.
The communication flow typically looks like this:
OnToolRequest.Each MCP Tool Request is identified by:
Once you have configured your MCP server using TsgcWSAPIServer_MCP, you can handle incoming tool requests through event handlers.
Below is an example of how to implement a handler for incoming MCP Tool Requests.
procedure TMainForm.MCPServerMCPRequestTool(Sender: TObject;
const ASession: TsgcAI_MCP_Session;
const ARequest: TsgcAI_MCP_Request_ToolsCall;
const AResponse: TsgcAI_MCP_Response_ToolsCall);
var
LA, LB: Double;
begin
if ARequest.Params.Name = 'math.add' then
begin
LA := ARequest.Params.Arguments.Node['a'].AsNumber;
LB := ARequest.Params.Arguments.Node['b'].AsNumber;
AResponse.Result.Content.AddText(Format('Sum = %.2f', [LA + LB]));
end
else
AResponse.Result.IsError := True;
end;
You can also register and expose metadata about available tools using the MCP API.
This allows AI models to discover your available tools dynamically and understand their expected parameters.
For example, you can declare:
procedure TMainForm.FormCreate(Sender: TObject);
var
oTool: TsgcAI_MCP_Tool;
begin
oTool := MCPServer.Tools.AddTool('math.add', 'Adds two numbers');
oTool.InputSchema.Properties.AddProperty('a', True, aimcpjtNumber, 'Left operand');
oTool.InputSchema.Properties.AddProperty('b', True, aimcpjtNumber, 'Right operand');
end;
This information helps AI clients automatically understand how to call your tools, making it easier to create self-documenting AI integrations.
MCP Tool Requests in sgcWebSockets 2025.9.0 provide a simple but powerful way to connect your AI models with real-world systems.
By using the TsgcWSAPIServer_MCP component and its built-in Tool Request handling, you can:
For a deeper look into the MCP API and available server components, visit the official documentation:
👉 sgcWebSockets MCP Tools Server Reference
Find below a Delphi MCP Server Demo for Windows.
When you subscribe to the blog, we will send you an e-mail when there are new updates on the site so you wouldn't miss them.