TsgcWSAPIServer_MCPEvents › OnMCPHTTPRequest

OnMCPHTTPRequest Event

Fires when an HTTP request reaches the MCP endpoint; set Handled := True to supply a custom response.

Syntax

property OnMCPHTTPRequest: TsgcMCPServerOnHTTPRequestEvent;
// TsgcMCPServerOnHTTPRequestEvent = procedure(Sender: TObject; const aRequest: TsgcHTTPRequest; const aResponse: TsgcHTTPResponse; var Handled: Boolean) of object

Default Value

Remarks

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.

Example

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;

Back to Events