Skip to content

IMcpSampling

Provides direct access to MCP sampling (LLM completions) from the connected client. Inject this interface into command handlers to request completions outside the IReplInteractionChannel abstraction.

public interface IMcpSampling

SampleAsync(string, int, CancellationToken)

Section titled “SampleAsync(string, int, CancellationToken)”

Requests an LLM completion from the connected agent client. Returns null when the client does not support sampling.

ValueTask<string?> SampleAsync(string prompt, int maxTokens = 1024, CancellationToken cancellationToken = default)
  • prompt (string): The user prompt to send.
  • maxTokens (int): Maximum tokens for the response (default 1024).
  • cancellationToken (CancellationToken): Cancellation token.

ValueTask<string>

Gets a value indicating whether the connected MCP client supports sampling.

bool IsSupported { get; }

bool