TsgcWSAPIServer_MCP › Events › OnMCPHTTPResponse
Fires after the HTTP response has been serialized; use it to add headers or log the exchange.
property OnMCPHTTPResponse: TsgcMCPServerOnHTTPResponseEvent;
// TsgcMCPServerOnHTTPResponseEvent = procedure(Sender: TObject; const aRequest: TsgcHTTPRequest; const aResponse: TsgcHTTPResponse) of object
—
Fires once the MCP engine has produced the JSON-RPC response and the aResponse object is fully populated (status code, content-type, body, Mcp-Session-Id header and, when streaming, chunked transfer). Use it to append extra headers (CORS, caching hints, request-id), to emit access logs, or to push telemetry. The response has not yet been flushed to the wire, so header mutations are still honoured.
procedure TMainForm.MCPServerMCPHTTPResponse(Sender: TObject;
const aRequest: TsgcHTTPRequest; const aResponse: TsgcHTTPResponse);
begin
aResponse.CustomHeaders.Add('X-Trace-Id: ' + CreateClassID);
MemoLog.Lines.Add(Format('%s %s -> %d', [aRequest.Method, aRequest.Document, aResponse.Code]));
end;