Audit protocol types (#892)

This commit is contained in:
Mackinnon Buck 2025-11-04 18:41:10 -05:00 • committed by GitHub
commit 121929da36
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 262 additions and 168 deletions

View file

@ -153,7 +153,7 @@ public abstract partial class McpServer : McpSession, IMcpServer
var result = await SampleAsync(new()
{
Messages = samplingMessages,
MaxTokens = options?.MaxOutputTokens,
MaxTokens = options?.MaxOutputTokens ?? ServerOptions.MaxSamplingOutputTokens,
StopSequences = options?.StopSequences?.ToArray(),
SystemPrompt = systemPrompt?.ToString(),
Temperature = options?.Temperature,

View file

@ -152,4 +152,18 @@ public sealed class McpServerOptions
/// </para>
/// </remarks>
public McpServerPrimitiveCollection<McpServerPrompt>? PromptCollection { get; set; }
/// <summary>
/// Gets or sets the default maximum number of tokens to use for sampling requests when not explicitly specified.
/// </summary>
/// <remarks>
/// <para>
/// This value is used in <see cref="McpServer.SampleAsync(IEnumerable{Microsoft.Extensions.AI.ChatMessage}, Microsoft.Extensions.AI.ChatOptions?, CancellationToken)"/>
/// when <see cref="Microsoft.Extensions.AI.ChatOptions.MaxOutputTokens"/> is not set in the request options.
/// </para>
/// <para>
/// The default value is 1000 tokens.
/// </para>
/// </remarks>
public int MaxSamplingOutputTokens { get; set; } = 1000;
}