TsgcWSAPIClient_MCPEvents › OnMCPStreamMessage

OnMCPStreamMessage Event

Fires while streaming responses are being read; inspect the raw JSON fragment and set Cancel := True to abort the stream.

Syntax

property OnMCPStreamMessage: TsgcAI_MCP_Client_OnStreamMessageEvent;
// TsgcAI_MCP_Client_OnStreamMessageEvent = procedure(Sender: TObject; const aMessage: string; var Cancel: Boolean) of object

Default Value

Remarks

Raised once per chunk when the streamable HTTP/SSE transport is used (MCPOptions.Transport := aimcptrHttpStreamable). aMessage carries the raw JSON fragment exactly as emitted by the server, so you can display incremental output (for example tokens from a streaming tool call) before the full JSON-RPC response is assembled. Set Cancel to True to stop consuming the stream; the component will close the HTTP reader cleanly.

Example

procedure TMainForm.MCPStreamMessage(Sender: TObject;
  const aMessage: string; var aCancel: Boolean);
begin
  if aMessage <> '' then
    MemoStream.Lines.Add('chunk: ' + aMessage);
  aCancel := UserAbortRequested;
end;

Back to Events