TsgcWSAPIServer_MCPEvents › OnMCPRequestResource

OnMCPRequestResource Event

Raised when a client issues resources/read; stream the resource content back to the caller.

Syntax

property OnMCPRequestResource: TsgcAI_MCP_Server_OnRequestResourceEvent;
// TsgcAI_MCP_Server_OnRequestResourceEvent = procedure(Sender: TObject; const aSession: TsgcAI_MCP_Session; const aRequest: TsgcAI_MCP_Request_ResourcesRead; const aResponse: TsgcAI_MCP_Response_ResourcesRead) of object

Default Value

Remarks

Fires when the client reads a resource through resources/read. aRequest.Params.Uri carries the URI the client asks for (either a static entry from Resources or a match of a ResourceTemplates pattern). Append one or more content blocks to aResponse.Result.Contents using AddContentText or AddContentBlob; each block carries its own MIME type and metadata. Set aResponse.Result.IsError := True if the URI cannot be resolved.

Example

procedure TMainForm.MCPServerMCPRequestResource(Sender: TObject;
  const aSession: TsgcAI_MCP_Session; const aRequest: TsgcAI_MCP_Request_ResourcesRead;
  const aResponse: TsgcAI_MCP_Response_ResourcesRead);
begin
  if SameText(aRequest.Params.Uri, 'metrics://deployments') then
    aResponse.Result.Contents.AddContentText(aRequest.Params.Uri, 'DeploymentMetrics',
      'Deployment metrics feed', 'application/json', FetchDeploymentMetrics)
  else
    aResponse.Result.IsError := True;
end;

Back to Events