TsgcWSAPIServer_MCP › Methods › RequestSamplingCreateMessage
Sends a sampling/createMessage request so the client’s LLM can produce a completion.
function RequestSamplingCreateMessage(const aSessionId: string; const aRequest: TsgcAI_MCP_Request_SamplingCreateMessage): Boolean;
| Name | Type | Description |
|---|---|---|
aSessionId | const string | Identifier of the target MCP session the sampling request is sent to. |
aRequest | const TsgcAI_MCP_Request_SamplingCreateMessage | Populated request object carrying the messages, model preferences, system prompt and sampling parameters. |
Returns True when the request has been written to the client connection; False when the session is unknown or offline. (Boolean)
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.
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;