TsgcWSAPIServer_MCP › Events › OnMCPHTTPRequest
Fires when an HTTP request reaches the MCP endpoint; set Handled := True to supply a custom response.
property OnMCPHTTPRequest: TsgcMCPServerOnHTTPRequestEvent;
// TsgcMCPServerOnHTTPRequestEvent = procedure(Sender: TObject; const aRequest: TsgcHTTPRequest; const aResponse: TsgcHTTPResponse; var Handled: Boolean) of object
—
Fires as soon as an HTTP request matches EndpointOptions.Endpoint and before authentication or the JSON-RPC dispatcher run. Inspect aRequest (method, headers, content) and populate aResponse directly, then set Handled := True to skip the MCP engine entirely — useful to serve health checks (GET /mcp/healthz), documentation pages or to short-circuit preflight CORS responses. Leave Handled as False to let the component continue the normal MCP pipeline.
procedure TMainForm.MCPServerMCPHTTPRequest(Sender: TObject;
const aRequest: TsgcHTTPRequest; const aResponse: TsgcHTTPResponse;
var Handled: Boolean);
begin
if SameText(aRequest.Method, 'GET') then
begin
aResponse.Code := 200;
aResponse.ContentType := 'text/plain';
aResponse.Content := 'ok';
Handled := True;
end;
end;