TsgcWSAPIServer_MCPMethods › RequestSamplingCreateMessage

RequestSamplingCreateMessage Method

Sends a sampling/createMessage request so the client’s LLM can produce a completion.

Syntax

function RequestSamplingCreateMessage(const aSessionId: string; const aRequest: TsgcAI_MCP_Request_SamplingCreateMessage): Boolean;

Parameters

NameTypeDescription
aSessionIdconst stringIdentifier of the target MCP session the sampling request is sent to.
aRequestconst TsgcAI_MCP_Request_SamplingCreateMessagePopulated request object carrying the messages, model preferences, system prompt and sampling parameters.

Return Value

Returns True when the request has been written to the client connection; False when the session is unknown or offline. (Boolean)

Remarks

Asks the MCP client to run a sampling turn on its LLM and return the generated message. The call is asynchronous; listen on OnMCPResponseSamplingCreateMessage to receive the content, role, stop reason, and model reported by the client. The client may prompt the user for approval before honouring the request, and may deny it entirely — always treat the response as best-effort.

Example

var
  oRequest: TsgcAI_MCP_Request_SamplingCreateMessage;
begin
  oRequest := TsgcAI_MCP_Request_SamplingCreateMessage.Create;
  try
    oRequest.Params.Messages.AddText('user', 'Summarise the latest deployment failures.');
    oRequest.Params.MaxTokens := 512;
    MCPServer.RequestSamplingCreateMessage(SessionId, oRequest);
  finally
    oRequest.Free;
  end;
end;

Back to Methods