Add net10.0 assets and run some fixers (#875)
This commit is contained in:
parent
e7b403b820
commit
bfc0980ef5
12 changed files with 168 additions and 194 deletions
|
|
@ -59,7 +59,7 @@ internal sealed class AIFunctionMcpServerPrompt : McpServerPrompt
|
|||
return Create(
|
||||
AIFunctionFactory.Create(method, args =>
|
||||
{
|
||||
Debug.Assert(args.Services is RequestServiceProvider<GetPromptRequestParams>, $"The service provider should be a {nameof(RequestServiceProvider<GetPromptRequestParams>)} for this method to work correctly.");
|
||||
Debug.Assert(args.Services is RequestServiceProvider<GetPromptRequestParams>, $"The service provider should be a {nameof(RequestServiceProvider<>)} for this method to work correctly.");
|
||||
return createTargetFunc(((RequestServiceProvider<GetPromptRequestParams>)args.Services!).Request);
|
||||
}, CreateAIFunctionFactoryOptions(method, options)),
|
||||
options);
|
||||
|
|
|
|||
|
|
@ -67,7 +67,7 @@ internal sealed class AIFunctionMcpServerResource : McpServerResource
|
|||
return Create(
|
||||
AIFunctionFactory.Create(method, args =>
|
||||
{
|
||||
Debug.Assert(args.Services is RequestServiceProvider<ReadResourceRequestParams>, $"The service provider should be a {nameof(RequestServiceProvider<ReadResourceRequestParams>)} for this method to work correctly.");
|
||||
Debug.Assert(args.Services is RequestServiceProvider<ReadResourceRequestParams>, $"The service provider should be a {nameof(RequestServiceProvider<>)} for this method to work correctly.");
|
||||
return createTargetFunc(((RequestServiceProvider<ReadResourceRequestParams>)args.Services!).Request);
|
||||
}, CreateAIFunctionFactoryOptions(method, options)),
|
||||
options);
|
||||
|
|
|
|||
|
|
@ -63,7 +63,7 @@ internal sealed partial class AIFunctionMcpServerTool : McpServerTool
|
|||
return Create(
|
||||
AIFunctionFactory.Create(method, args =>
|
||||
{
|
||||
Debug.Assert(args.Services is RequestServiceProvider<CallToolRequestParams>, $"The service provider should be a {nameof(RequestServiceProvider<CallToolRequestParams>)} for this method to work correctly.");
|
||||
Debug.Assert(args.Services is RequestServiceProvider<CallToolRequestParams>, $"The service provider should be a {nameof(RequestServiceProvider<>)} for this method to work correctly.");
|
||||
return createTargetFunc(((RequestServiceProvider<CallToolRequestParams>)args.Services!).Request);
|
||||
}, CreateAIFunctionFactoryOptions(method, options)),
|
||||
options);
|
||||
|
|
|
|||
|
|
@ -27,8 +27,11 @@ internal sealed class DestinationBoundMcpServer(McpServerImpl server, ITransport
|
|||
throw new ArgumentException("Only transports can provide a JsonRpcMessageContext.");
|
||||
}
|
||||
|
||||
message.Context = new JsonRpcMessageContext();
|
||||
message.Context.RelatedTransport = transport;
|
||||
message.Context = new()
|
||||
{
|
||||
RelatedTransport = transport
|
||||
};
|
||||
|
||||
return server.SendMessageAsync(message, cancellationToken);
|
||||
}
|
||||
|
||||
|
|
@ -39,8 +42,11 @@ internal sealed class DestinationBoundMcpServer(McpServerImpl server, ITransport
|
|||
throw new ArgumentException("Only transports can provide a JsonRpcMessageContext.");
|
||||
}
|
||||
|
||||
request.Context = new JsonRpcMessageContext();
|
||||
request.Context.RelatedTransport = transport;
|
||||
request.Context = new()
|
||||
{
|
||||
RelatedTransport = transport
|
||||
};
|
||||
|
||||
return server.SendRequestAsync(request, cancellationToken);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -341,13 +341,9 @@ public abstract partial class McpServer : McpSession, IMcpServer
|
|||
throw new McpProtocolException(error);
|
||||
}
|
||||
|
||||
var primitiveSchemaDefinition =
|
||||
jsonElement.Deserialize(McpJsonUtilities.JsonContext.Default.PrimitiveSchemaDefinition);
|
||||
|
||||
if (primitiveSchemaDefinition is null)
|
||||
return
|
||||
jsonElement.Deserialize(McpJsonUtilities.JsonContext.Default.PrimitiveSchemaDefinition) ??
|
||||
throw new McpProtocolException($"Type '{type.FullName}' is not a supported property type for elicitation requests.");
|
||||
|
||||
return primitiveSchemaDefinition;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -452,11 +448,9 @@ public abstract partial class McpServer : McpSession, IMcpServer
|
|||
}
|
||||
|
||||
/// <summary>Provides an <see cref="IChatClient"/> implementation that's implemented via client sampling.</summary>
|
||||
private sealed class SamplingChatClient : IChatClient
|
||||
private sealed class SamplingChatClient(McpServer server) : IChatClient
|
||||
{
|
||||
private readonly McpServer _server;
|
||||
|
||||
public SamplingChatClient(McpServer server) => _server = server;
|
||||
private readonly McpServer _server = server;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public Task<ChatResponse> GetResponseAsync(IEnumerable<ChatMessage> messages, ChatOptions? options = null, CancellationToken cancellationToken = default) =>
|
||||
|
|
@ -493,11 +487,9 @@ public abstract partial class McpServer : McpSession, IMcpServer
|
|||
/// Provides an <see cref="ILoggerProvider"/> implementation for creating loggers
|
||||
/// that send logging message notifications to the client for logged messages.
|
||||
/// </summary>
|
||||
private sealed class ClientLoggerProvider : ILoggerProvider
|
||||
private sealed class ClientLoggerProvider(McpServer server) : ILoggerProvider
|
||||
{
|
||||
private readonly McpServer _server;
|
||||
|
||||
public ClientLoggerProvider(McpServer server) => _server = server;
|
||||
private readonly McpServer _server = server;
|
||||
|
||||
/// <inheritdoc />
|
||||
public ILogger CreateLogger(string categoryName)
|
||||
|
|
@ -510,16 +502,10 @@ public abstract partial class McpServer : McpSession, IMcpServer
|
|||
/// <inheritdoc />
|
||||
void IDisposable.Dispose() { }
|
||||
|
||||
private sealed class ClientLogger : ILogger
|
||||
private sealed class ClientLogger(McpServer server, string categoryName) : ILogger
|
||||
{
|
||||
private readonly McpServer _server;
|
||||
private readonly string _categoryName;
|
||||
|
||||
public ClientLogger(McpServer server, string categoryName)
|
||||
{
|
||||
_server = server;
|
||||
_categoryName = categoryName;
|
||||
}
|
||||
private readonly McpServer _server = server;
|
||||
private readonly string _categoryName = categoryName;
|
||||
|
||||
/// <inheritdoc />
|
||||
public IDisposable? BeginScope<TState>(TState state) where TState : notnull =>
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ public sealed class McpServerFilters
|
|||
/// Tools from both sources will be combined when returning results to clients.
|
||||
/// </para>
|
||||
/// </remarks>
|
||||
public List<McpRequestFilter<ListToolsRequestParams, ListToolsResult>> ListToolsFilters { get; } = new();
|
||||
public List<McpRequestFilter<ListToolsRequestParams, ListToolsResult>> ListToolsFilters { get; } = [];
|
||||
|
||||
/// <summary>
|
||||
/// Gets the filters for the call tool handler pipeline.
|
||||
|
|
@ -36,7 +36,7 @@ public sealed class McpServerFilters
|
|||
/// The filters can modify, log, or perform additional operations on requests and responses for
|
||||
/// <see cref="RequestMethods.ToolsCall"/> requests. The handler should implement logic to execute the requested tool and return appropriate results.
|
||||
/// </remarks>
|
||||
public List<McpRequestFilter<CallToolRequestParams, CallToolResult>> CallToolFilters { get; } = new();
|
||||
public List<McpRequestFilter<CallToolRequestParams, CallToolResult>> CallToolFilters { get; } = [];
|
||||
|
||||
/// <summary>
|
||||
/// Gets the filters for the list prompts handler pipeline.
|
||||
|
|
@ -53,7 +53,7 @@ public sealed class McpServerFilters
|
|||
/// Prompts from both sources will be combined when returning results to clients.
|
||||
/// </para>
|
||||
/// </remarks>
|
||||
public List<McpRequestFilter<ListPromptsRequestParams, ListPromptsResult>> ListPromptsFilters { get; } = new();
|
||||
public List<McpRequestFilter<ListPromptsRequestParams, ListPromptsResult>> ListPromptsFilters { get; } = [];
|
||||
|
||||
/// <summary>
|
||||
/// Gets the filters for the get prompt handler pipeline.
|
||||
|
|
@ -63,7 +63,7 @@ public sealed class McpServerFilters
|
|||
/// The filters can modify, log, or perform additional operations on requests and responses for
|
||||
/// <see cref="RequestMethods.PromptsGet"/> requests. The handler should implement logic to fetch or generate the requested prompt and return appropriate results.
|
||||
/// </remarks>
|
||||
public List<McpRequestFilter<GetPromptRequestParams, GetPromptResult>> GetPromptFilters { get; } = new();
|
||||
public List<McpRequestFilter<GetPromptRequestParams, GetPromptResult>> GetPromptFilters { get; } = [];
|
||||
|
||||
/// <summary>
|
||||
/// Gets the filters for the list resource templates handler pipeline.
|
||||
|
|
@ -74,7 +74,7 @@ public sealed class McpServerFilters
|
|||
/// <see cref="RequestMethods.ResourcesTemplatesList"/> requests. It supports pagination through the cursor mechanism,
|
||||
/// where the client can make repeated calls with the cursor returned by the previous call to retrieve more resource templates.
|
||||
/// </remarks>
|
||||
public List<McpRequestFilter<ListResourceTemplatesRequestParams, ListResourceTemplatesResult>> ListResourceTemplatesFilters { get; } = new();
|
||||
public List<McpRequestFilter<ListResourceTemplatesRequestParams, ListResourceTemplatesResult>> ListResourceTemplatesFilters { get; } = [];
|
||||
|
||||
/// <summary>
|
||||
/// Gets the filters for the list resources handler pipeline.
|
||||
|
|
@ -85,7 +85,7 @@ public sealed class McpServerFilters
|
|||
/// <see cref="RequestMethods.ResourcesList"/> requests. It supports pagination through the cursor mechanism,
|
||||
/// where the client can make repeated calls with the cursor returned by the previous call to retrieve more resources.
|
||||
/// </remarks>
|
||||
public List<McpRequestFilter<ListResourcesRequestParams, ListResourcesResult>> ListResourcesFilters { get; } = new();
|
||||
public List<McpRequestFilter<ListResourcesRequestParams, ListResourcesResult>> ListResourcesFilters { get; } = [];
|
||||
|
||||
/// <summary>
|
||||
/// Gets the filters for the read resource handler pipeline.
|
||||
|
|
@ -95,7 +95,7 @@ public sealed class McpServerFilters
|
|||
/// The filters can modify, log, or perform additional operations on requests and responses for
|
||||
/// <see cref="RequestMethods.ResourcesRead"/> requests. The handler should implement logic to locate and retrieve the requested resource.
|
||||
/// </remarks>
|
||||
public List<McpRequestFilter<ReadResourceRequestParams, ReadResourceResult>> ReadResourceFilters { get; } = new();
|
||||
public List<McpRequestFilter<ReadResourceRequestParams, ReadResourceResult>> ReadResourceFilters { get; } = [];
|
||||
|
||||
/// <summary>
|
||||
/// Gets the filters for the complete handler pipeline.
|
||||
|
|
@ -106,7 +106,7 @@ public sealed class McpServerFilters
|
|||
/// <see cref="RequestMethods.CompletionComplete"/> requests. The handler processes auto-completion requests, returning a list of suggestions based on the
|
||||
/// reference type and current argument value.
|
||||
/// </remarks>
|
||||
public List<McpRequestFilter<CompleteRequestParams, CompleteResult>> CompleteFilters { get; } = new();
|
||||
public List<McpRequestFilter<CompleteRequestParams, CompleteResult>> CompleteFilters { get; } = [];
|
||||
|
||||
/// <summary>
|
||||
/// Gets the filters for the subscribe to resources handler pipeline.
|
||||
|
|
@ -123,7 +123,7 @@ public sealed class McpServerFilters
|
|||
/// whenever a relevant resource is created, updated, or deleted.
|
||||
/// </para>
|
||||
/// </remarks>
|
||||
public List<McpRequestFilter<SubscribeRequestParams, EmptyResult>> SubscribeToResourcesFilters { get; } = new();
|
||||
public List<McpRequestFilter<SubscribeRequestParams, EmptyResult>> SubscribeToResourcesFilters { get; } = [];
|
||||
|
||||
/// <summary>
|
||||
/// Gets the filters for the unsubscribe from resources handler pipeline.
|
||||
|
|
@ -140,7 +140,7 @@ public sealed class McpServerFilters
|
|||
/// to the client for the specified resources.
|
||||
/// </para>
|
||||
/// </remarks>
|
||||
public List<McpRequestFilter<UnsubscribeRequestParams, EmptyResult>> UnsubscribeFromResourcesFilters { get; } = new();
|
||||
public List<McpRequestFilter<UnsubscribeRequestParams, EmptyResult>> UnsubscribeFromResourcesFilters { get; } = [];
|
||||
|
||||
/// <summary>
|
||||
/// Gets the filters for the set logging level handler pipeline.
|
||||
|
|
@ -157,5 +157,5 @@ public sealed class McpServerFilters
|
|||
/// at or above the specified level to the client as notifications/message notifications.
|
||||
/// </para>
|
||||
/// </remarks>
|
||||
public List<McpRequestFilter<SetLevelRequestParams, EmptyResult>> SetLoggingLevelFilters { get; } = new();
|
||||
public List<McpRequestFilter<SetLevelRequestParams, EmptyResult>> SetLoggingLevelFilters { get; } = [];
|
||||
}
|
||||
|
|
|
|||
|
|
@ -207,12 +207,9 @@ internal sealed partial class McpServerImpl : McpServer
|
|||
// Otherwise, try to use whatever the client requested as long as it's supported.
|
||||
// If it's not supported, fall back to the latest supported version.
|
||||
string? protocolVersion = options.ProtocolVersion;
|
||||
if (protocolVersion is null)
|
||||
{
|
||||
protocolVersion = request?.ProtocolVersion is string clientProtocolVersion && McpSessionHandler.SupportedProtocolVersions.Contains(clientProtocolVersion) ?
|
||||
clientProtocolVersion :
|
||||
McpSessionHandler.LatestProtocolVersion;
|
||||
}
|
||||
protocolVersion ??= request?.ProtocolVersion is string clientProtocolVersion && McpSessionHandler.SupportedProtocolVersions.Contains(clientProtocolVersion) ?
|
||||
clientProtocolVersion :
|
||||
McpSessionHandler.LatestProtocolVersion;
|
||||
|
||||
_negotiatedProtocolVersion = protocolVersion;
|
||||
|
||||
|
|
|
|||
|
|
@ -7,8 +7,6 @@ namespace ModelContextProtocol.Server;
|
|||
/// </summary>
|
||||
public sealed class McpServerOptions
|
||||
{
|
||||
private McpServerHandlers? _handlers;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets information about this server implementation, including its name and version.
|
||||
/// </summary>
|
||||
|
|
@ -97,11 +95,11 @@ public sealed class McpServerOptions
|
|||
/// </summary>
|
||||
public McpServerHandlers Handlers
|
||||
{
|
||||
get => _handlers ??= new();
|
||||
get => field ??= new();
|
||||
set
|
||||
{
|
||||
Throw.IfNull(value);
|
||||
_handlers = value;
|
||||
field = value;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -90,7 +90,7 @@ public sealed class McpServerPromptCreateOptions
|
|||
/// Creates a shallow clone of the current <see cref="McpServerPromptCreateOptions"/> instance.
|
||||
/// </summary>
|
||||
internal McpServerPromptCreateOptions Clone() =>
|
||||
new McpServerPromptCreateOptions
|
||||
new()
|
||||
{
|
||||
Services = Services,
|
||||
Name = Name,
|
||||
|
|
|
|||
|
|
@ -105,7 +105,7 @@ public sealed class McpServerResourceCreateOptions
|
|||
/// Creates a shallow clone of the current <see cref="McpServerResourceCreateOptions"/> instance.
|
||||
/// </summary>
|
||||
internal McpServerResourceCreateOptions Clone() =>
|
||||
new McpServerResourceCreateOptions
|
||||
new()
|
||||
{
|
||||
Services = Services,
|
||||
UriTemplate = UriTemplate,
|
||||
|
|
|
|||
|
|
@ -176,7 +176,7 @@ public sealed class McpServerToolCreateOptions
|
|||
/// Creates a shallow clone of the current <see cref="McpServerToolCreateOptions"/> instance.
|
||||
/// </summary>
|
||||
internal McpServerToolCreateOptions Clone() =>
|
||||
new McpServerToolCreateOptions
|
||||
new()
|
||||
{
|
||||
Services = Services,
|
||||
Name = Name,
|
||||
|
|
|
|||
|
|
@ -17,8 +17,6 @@ public sealed class RequestContext<TParams>
|
|||
/// <summary>The server with which this instance is associated.</summary>
|
||||
private McpServer _server;
|
||||
|
||||
private IDictionary<string, object?>? _items;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="RequestContext{TParams}"/> class with the specified server and JSON-RPC request.
|
||||
/// </summary>
|
||||
|
|
@ -51,14 +49,8 @@ public sealed class RequestContext<TParams>
|
|||
/// </summary>
|
||||
public IDictionary<string, object?> Items
|
||||
{
|
||||
get
|
||||
{
|
||||
return _items ??= new Dictionary<string, object?>();
|
||||
}
|
||||
set
|
||||
{
|
||||
_items = value;
|
||||
}
|
||||
get => field ??= new Dictionary<string, object?>();
|
||||
set => field = value;
|
||||
}
|
||||
|
||||
/// <summary>Gets or sets the services associated with this request.</summary>
|
||||
|
|
|
|||
Loading…
Reference in a new issue