TsgcWSAPIServer_MCPEvents › OnMCPResponseSamplingCreateMessage

OnMCPResponseSamplingCreateMessage Event

Receives the client’s reply to RequestSamplingCreateMessage with the generated message.

Syntax

property OnMCPResponseSamplingCreateMessage: TsgcAI_MCP_Server_OnResponseSamplingCreateMessageEvent;
// TsgcAI_MCP_Server_OnResponseSamplingCreateMessageEvent = procedure(Sender: TObject; const aSession: TsgcAI_MCP_Session; const aRequest: TsgcAI_MCP_Request_SamplingCreateMessage; const aResponse: TsgcAI_MCP_Response_SamplingCreateMessage) of object

Default Value

Remarks

Raised when the client finishes handling a previous RequestSamplingCreateMessage call. aResponse.Result.Role and aResponse.Result.Content carry the generated turn, aResponse.Result.Model reports the LLM selected by the client and aResponse.Result.StopReason explains why generation ended (endTurn, maxTokens, stopSequence, etc.). Merge the result into the ongoing workflow — clients may refuse the request, in which case the response contains an error payload.

Example

procedure TMainForm.MCPServerMCPResponseSamplingCreateMessage(Sender: TObject;
  const aSession: TsgcAI_MCP_Session; const aRequest: TsgcAI_MCP_Request_SamplingCreateMessage;
  const aResponse: TsgcAI_MCP_Response_SamplingCreateMessage);
begin
  MemoLog.Lines.Add('sampling reply (' + aResponse.Result.Model + '): ' +
    aResponse.Result.Content.AsText);
end;

Back to Events