Remove warnings from build (#29)

* Remove warnings from build

* More fixes.

* Using const for transport types
This commit is contained in:
Toni Wenzel 2025-03-06 21:02:13 +01:00 • committed by GitHub
commit 7d69499ad5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
22 changed files with 277 additions and 263 deletions

View file

@ -1,7 +1,7 @@
namespace McpDotNet.Client;
using McpDotNet.Protocol.Types;
using McpDotNet.Protocol.Messages;
using McpDotNet.Protocol.Types;
/// <summary>
/// Represents an instance of the MCP client connecting to a specific server.
@ -35,12 +35,12 @@ public interface IMcpClient : IAsyncDisposable
/// <summary>
/// Gets or sets the handler for server sampling requests.
/// </summary>
Func<CreateMessageRequestParams, CancellationToken, Task<CreateMessageResult>>? SamplingHandler { get; set; }
Func<CreateMessageRequestParams?, CancellationToken, Task<CreateMessageResult>>? SamplingHandler { get; set; }
/// <summary>
/// Gets or sets the handler for providing root URIs to servers.
/// </summary>
Func<ListRootsRequestParams, CancellationToken, Task<ListRootsResult>>? RootsHandler { get; set; }
Func<ListRootsRequestParams?, CancellationToken, Task<ListRootsResult>>? RootsHandler { get; set; }
/// <summary>
/// Establishes a connection to the server.

View file

@ -1,12 +1,12 @@

using McpDotNet.Protocol.Types;
using McpDotNet.Protocol.Transport;
using McpDotNet.Protocol.Messages;
using System.Text.Json;
using Microsoft.Extensions.Logging;
using McpDotNet.Logging;
using McpDotNet.Configuration;
using McpDotNet.Logging;
using McpDotNet.Protocol.Messages;
using McpDotNet.Protocol.Transport;
using McpDotNet.Protocol.Types;
using McpDotNet.Shared;
using Microsoft.Extensions.Logging;
namespace McpDotNet.Client;
@ -46,7 +46,8 @@ internal class McpClient : McpJsonRpcEndpoint, IMcpClient
if (options.Capabilities?.Sampling != null)
{
SetRequestHandler<CreateMessageRequestParams, CreateMessageResult>("sampling/createMessage",
async (request) => {
async (request) =>
{
if (SamplingHandler == null)
{
// Setting the capability, but not a handler means we have nothing to return to the server
@ -168,7 +169,7 @@ internal class McpClient : McpJsonRpcEndpoint, IMcpClient
}
/// <inheritdoc/>
public async Task PingAsync(CancellationToken cancellationToken)
public async Task PingAsync(CancellationToken cancellationToken = default)
{
_logger.PingingServer(EndpointName);
await SendRequestAsync<dynamic>(
@ -268,7 +269,7 @@ internal class McpClient : McpJsonRpcEndpoint, IMcpClient
}
if (argumentValue is null)
{
_logger.InvalidCompletionArgumentValue(EndpointName, argumentValue);
_logger.InvalidCompletionArgumentValue(EndpointName, "null", argumentName);
throw new McpClientException("Argument value cannot be null");
}
@ -330,13 +331,13 @@ internal class McpClient : McpJsonRpcEndpoint, IMcpClient
new JsonRpcRequest
{
Method = "tools/call",
Params = CreateParametersDictionary(toolName, arguments ?? new())
Params = CreateParametersDictionary(toolName, arguments ?? [])
},
cancellationToken
).ConfigureAwait(false);
}
private static Dictionary<string, object?> CreateParametersDictionary(string nameParameter, Dictionary<string, object> arguments)
private static Dictionary<string, object?> CreateParametersDictionary(string nameParameter, Dictionary<string, object>? arguments)
{
var parameters = new Dictionary<string, object?>
{
@ -352,10 +353,10 @@ internal class McpClient : McpJsonRpcEndpoint, IMcpClient
}
/// <inheritdoc/>
public Func<CreateMessageRequestParams, CancellationToken, Task<CreateMessageResult>>? SamplingHandler { get; set; }
public Func<CreateMessageRequestParams?, CancellationToken, Task<CreateMessageResult>>? SamplingHandler { get; set; }
/// <inheritdoc/>
public Func<ListRootsRequestParams, CancellationToken, Task<ListRootsResult>>? RootsHandler { get; set; }
public Func<ListRootsRequestParams?, CancellationToken, Task<ListRootsResult>>? RootsHandler { get; set; }
/// <inheritdoc/>
public override string EndpointName

View file

@ -14,7 +14,7 @@ public class McpClientFactory
{
private readonly Dictionary<string, McpServerConfig> _serverConfigs;
private readonly McpClientOptions _clientOptions;
private readonly Dictionary<string, IMcpClient> _clients = new();
private readonly Dictionary<string, IMcpClient> _clients = [];
private readonly Func<McpServerConfig, IClientTransport> _transportFactoryMethod;
private readonly Func<IClientTransport, McpServerConfig, McpClientOptions, IMcpClient> _clientFactoryMethod;
private readonly ILoggerFactory _loggerFactory;
@ -47,12 +47,9 @@ public class McpClientFactory
// Initialize commands for stdio transport, this is to run commands in a shell even if specified directly, as otherwise
// the stdio protocol will not work correctly.
_logger.InitializingStdioCommands();
foreach (var config in _serverConfigs.Values)
foreach (var config in _serverConfigs.Values.Where(c => c.TransportType.Equals(TransportTypes.StdIo, StringComparison.OrdinalIgnoreCase)))
{
if (config.TransportType.ToLowerInvariant() == "stdio")
{
InitializeCommand(config);
}
InitializeCommand(config);
}
}
@ -97,11 +94,11 @@ public class McpClientFactory
{
string endpointName = $"Client ({config.Id}: {config.Name})";
var options = string.Join(", ", config.TransportOptions?.Select(kv => $"{kv.Key}={kv.Value}") ?? Enumerable.Empty<string>());
var options = string.Join(", ", config.TransportOptions?.Select(kv => $"{kv.Key}={kv.Value}") ?? []);
_logger.CreatingTransport(endpointName, config.TransportType, options);
return config.TransportType.ToLowerInvariant() switch
{
"stdio" => new StdioClientTransport(new StdioClientTransportOptions
TransportTypes.StdIo => new StdioClientTransport(new StdioClientTransportOptions
{
Command = GetCommand(config),
Arguments = config.TransportOptions?.GetValueOrDefault("arguments")?.Split(' '),
@ -110,7 +107,7 @@ public class McpClientFactory
.Where(kv => kv.Key.StartsWith("env:"))
.ToDictionary(kv => kv.Key.Substring(4), kv => kv.Value)
}, config, _loggerFactory),
"sse" or "http" => new SseClientTransport(
TransportTypes.Sse or "http" => new SseClientTransport(
new SseClientTransportOptions
{
ConnectionTimeout = TimeSpan.FromSeconds(ParseOrDefault(config.TransportOptions, "connectionTimeout", 30)),
@ -124,7 +121,7 @@ public class McpClientFactory
};
}
private static int ParseOrDefault(IDictionary<string, string>? options, string key, int defaultValue)
private static int ParseOrDefault(Dictionary<string, string>? options, string key, int defaultValue)
{
if (options?.TryGetValue(key, out var value) ?? false)
{
@ -135,15 +132,14 @@ public class McpClientFactory
return defaultValue;
}
private string? GetCommand(McpServerConfig config)
private static string GetCommand(McpServerConfig config)
{
if (config.TransportOptions == null ||
string.IsNullOrEmpty(config.TransportOptions.GetValueOrDefault("command")))
{
return config.Location!;
}
var command = config.TransportOptions?.GetValueOrDefault("command");
return OperatingSystem.IsWindows() ? "cmd.exe" : config.TransportOptions?.GetValueOrDefault("command");
if (string.IsNullOrEmpty(command))
return config.Location!;
return OperatingSystem.IsWindows() ? "cmd.exe" : command;
}
/// <summary>
@ -162,7 +158,7 @@ public class McpClientFactory
}
// On Windows, we need to wrap non-shell commands with cmd.exe /c
if (command.ToLowerInvariant().Contains("cmd.exe"))
if (command.Contains("cmd.exe", StringComparison.OrdinalIgnoreCase))
{
_logger.SkippingShellWrapper(endpointName);
return;
@ -171,8 +167,8 @@ public class McpClientFactory
// If the command is not empty and does not contain cmd.exe, we need to inject /c {command} (usually npx or uvicorn)
// This is because the stdio transport will not work correctly if the command is not run in a shell
_logger.PromotingCommandToShellArgumentForStdio(endpointName, command, config.TransportOptions!.GetValueOrDefault("arguments") ?? "");
config.TransportOptions!["arguments"] = config.TransportOptions.ContainsKey("arguments")
? $"/c {command} {config.TransportOptions["arguments"]}"
config.TransportOptions!["arguments"] = config.TransportOptions.TryGetValue("arguments", out var args)
? $"/c {command} {args}"
: $"/c {command}";
}
}

View file

@ -28,7 +28,7 @@ public static class McpServerBuilderExtensions
/// <param name="builder">The builder instance.</param>
/// <param name="handler">The handler.</param>
/// <returns></returns>
public static IMcpServerBuilder WithListToolsHandler(this IMcpServerBuilder builder, Func<ListToolsRequestParams, CancellationToken, Task<ListToolsResult>> handler)
public static IMcpServerBuilder WithListToolsHandler(this IMcpServerBuilder builder, Func<ListToolsRequestParams?, CancellationToken, Task<ListToolsResult>> handler)
{
builder.Services.Configure<McpServerDelegates>(s => s.ListToolsHandler = handler);
return builder;
@ -40,7 +40,7 @@ public static class McpServerBuilderExtensions
/// <param name="builder">The builder instance.</param>
/// <param name="handler">The handler.</param>
/// <returns></returns>
public static IMcpServerBuilder WithCallToolHandler(this IMcpServerBuilder builder, Func<CallToolRequestParams, CancellationToken, Task<CallToolResponse>> handler)
public static IMcpServerBuilder WithCallToolHandler(this IMcpServerBuilder builder, Func<CallToolRequestParams?, CancellationToken, Task<CallToolResponse>> handler)
{
builder.Services.Configure<McpServerDelegates>(s => s.CallToolHandler = handler);
return builder;
@ -52,7 +52,7 @@ public static class McpServerBuilderExtensions
/// <param name="builder">The builder instance.</param>
/// <param name="handler">The handler.</param>
/// <returns></returns>
public static IMcpServerBuilder WithListPromptsHandler(this IMcpServerBuilder builder, Func<ListPromptsRequestParams, CancellationToken, Task<ListPromptsResult>> handler)
public static IMcpServerBuilder WithListPromptsHandler(this IMcpServerBuilder builder, Func<ListPromptsRequestParams?, CancellationToken, Task<ListPromptsResult>> handler)
{
builder.Services.Configure<McpServerDelegates>(s => s.ListPromptsHandler = handler);
return builder;
@ -64,7 +64,7 @@ public static class McpServerBuilderExtensions
/// <param name="builder">The builder instance.</param>
/// <param name="handler">The handler.</param>
/// <returns></returns>
public static IMcpServerBuilder WithGetPromptHandler(this IMcpServerBuilder builder, Func<GetPromptRequestParams, CancellationToken, Task<GetPromptResult>> handler)
public static IMcpServerBuilder WithGetPromptHandler(this IMcpServerBuilder builder, Func<GetPromptRequestParams?, CancellationToken, Task<GetPromptResult>> handler)
{
builder.Services.Configure<McpServerDelegates>(s => s.GetPromptHandler = handler);
return builder;
@ -76,7 +76,7 @@ public static class McpServerBuilderExtensions
/// <param name="builder">The builder instance.</param>
/// <param name="handler">The handler.</param>
/// <returns></returns>
public static IMcpServerBuilder WithListResourcesHandler(this IMcpServerBuilder builder, Func<ListResourcesRequestParams, CancellationToken, Task<ListResourcesResult>> handler)
public static IMcpServerBuilder WithListResourcesHandler(this IMcpServerBuilder builder, Func<ListResourcesRequestParams?, CancellationToken, Task<ListResourcesResult>> handler)
{
builder.Services.Configure<McpServerDelegates>(s => s.ListResourcesHandler = handler);
return builder;
@ -88,7 +88,7 @@ public static class McpServerBuilderExtensions
/// <param name="builder">The builder instance.</param>
/// <param name="handler">The handler.</param>
/// <returns></returns>
public static IMcpServerBuilder WithReadResourceHandler(this IMcpServerBuilder builder, Func<ReadResourceRequestParams, CancellationToken, Task<ReadResourceResult>> handler)
public static IMcpServerBuilder WithReadResourceHandler(this IMcpServerBuilder builder, Func<ReadResourceRequestParams?, CancellationToken, Task<ReadResourceResult>> handler)
{
builder.Services.Configure<McpServerDelegates>(s => s.ReadResourceHandler = handler);
return builder;
@ -100,7 +100,7 @@ public static class McpServerBuilderExtensions
/// <param name="builder">The builder instance.</param>
/// <param name="handler">The handler.</param>
/// <returns></returns>
public static IMcpServerBuilder WithGetCompletionHandler(this IMcpServerBuilder builder, Func<CompleteRequestParams, CancellationToken, Task<CompleteResult>> handler)
public static IMcpServerBuilder WithGetCompletionHandler(this IMcpServerBuilder builder, Func<CompleteRequestParams?, CancellationToken, Task<CompleteResult>> handler)
{
builder.Services.Configure<McpServerDelegates>(s => s.GetCompletionHandler = handler);
return builder;

View file

@ -364,12 +364,13 @@ internal static partial class Log
[LoggerMessage(
EventId = 7006,
Level = LogLevel.Trace,
Message = "Invalid completion argument value {argumentValue} for {endpointName}"
Message = "Invalid completion argument value {argumentValue} for {argumentName} for {endpointName}"
)]
public static partial void InvalidCompletionArgumentValue(
this ILogger logger,
string endpointName,
string argumentValue);
string argumentValue,
string argumentName);
[LoggerMessage(
EventId = 7007,

View file

@ -1,12 +1,11 @@
using System.Text.Json;
using System.Net.Http.Headers;
using System.Text;
using McpDotNet.Protocol.Messages;
using System.Text.Json;
using McpDotNet.Configuration;
using Microsoft.Extensions.Logging;
using McpDotNet.Logging;
using System.Net.Http.Headers;
using System.Text.Json.Serialization;
using McpDotNet.Protocol.Messages;
using McpDotNet.Utils.Json;
using Microsoft.Extensions.Logging;
namespace McpDotNet.Protocol.Transport;
@ -24,7 +23,7 @@ public sealed class SseClientTransport : TransportBase, IClientTransport
private readonly ILogger<SseClientTransport> _logger;
private readonly McpServerConfig _serverConfig;
private readonly JsonSerializerOptions _jsonOptions;
private TaskCompletionSource<bool> _connectionEstablished;
private readonly TaskCompletionSource<bool> _connectionEstablished;
private string EndpointName => $"Client (SSE) for ({_serverConfig.Id}: {_serverConfig.Name})";
@ -100,7 +99,7 @@ public sealed class SseClientTransport : TransportBase, IClientTransport
);
string messageId = "(no id)";
RequestId? requestId = null;
if (message is IJsonRpcMessageWithId messageWithId)
{
messageId = messageWithId.Id.ToString();
@ -114,24 +113,22 @@ public sealed class SseClientTransport : TransportBase, IClientTransport
response.EnsureSuccessStatusCode();
var responseContent = await response.Content.ReadAsStringAsync();
var responseContent = await response.Content.ReadAsStringAsync(cancellationToken);
// Check if the message was an initialize request
if (message is JsonRpcRequest request && request.Method == "initialize")
{
// If the response is not a JSON-RPC response, it is an SSE message
if (responseContent.ToLowerInvariant() == "accepted")
if (responseContent.Equals("accepted", StringComparison.OrdinalIgnoreCase))
{
_logger.SSETransportPostAccepted(EndpointName, messageId);
// The response will arrive as an SSE message
}
else
{
JsonRpcResponse initializeResponse = JsonSerializer.Deserialize<JsonRpcResponse>(responseContent, _jsonOptions);
if (initializeResponse == null)
{
JsonRpcResponse initializeResponse = JsonSerializer.Deserialize<JsonRpcResponse>(responseContent, _jsonOptions) ??
throw new McpTransportException("Failed to initialize client");
}
_logger.TransportReceivedMessageParsed(EndpointName, messageId);
await WriteMessageAsync(initializeResponse, cancellationToken);
_logger.TransportMessageWritten(EndpointName, messageId);
@ -140,7 +137,7 @@ public sealed class SseClientTransport : TransportBase, IClientTransport
}
// Otherwise, check if the response was accepted (the response will come as an SSE message)
if (responseContent.ToLowerInvariant() == "accepted")
if (responseContent.Equals("accepted", StringComparison.OrdinalIgnoreCase))
{
_logger.SSETransportPostAccepted(EndpointName, messageId);
}
@ -154,7 +151,7 @@ public sealed class SseClientTransport : TransportBase, IClientTransport
/// <inheritdoc/>
public async Task CloseAsync()
{
_connectionCts.Cancel();
await _connectionCts.CancelAsync();
if (_receiveTask != null)
await _receiveTask;
@ -290,7 +287,7 @@ public sealed class SseClientTransport : TransportBase, IClientTransport
}
// Check if data is absolute URI
if (data.ToLowerInvariant().StartsWith("http://") || data.ToLowerInvariant().StartsWith("https://"))
if (data.StartsWith("http://", StringComparison.OrdinalIgnoreCase) || data.StartsWith("https://", StringComparison.OrdinalIgnoreCase))
{
// Since the endpoint is an absolute URI, we can use it directly
_messageEndpoint = new Uri(data);
@ -317,10 +314,4 @@ public sealed class SseClientTransport : TransportBase, IClientTransport
throw new McpTransportException("Failed to parse endpoint event", ex);
}
}
private record EndpointEventData
{
[JsonPropertyName("uri")]
public string? Uri { get; init; }
}
}

View file

@ -1,10 +1,10 @@
using System.Diagnostics;
using System.Text.Json;
using McpDotNet.Configuration;
using McpDotNet.Logging;
using McpDotNet.Protocol.Messages;
using McpDotNet.Utils.Json;
using Microsoft.Extensions.Logging;
using McpDotNet.Logging;
namespace McpDotNet.Protocol.Transport;
@ -139,7 +139,7 @@ public sealed class StdioClientTransport : TransportBase, IClientTransport
// Write the message followed by a newline
await _process!.StandardInput.WriteLineAsync(json.AsMemory(), cancellationToken);
await _process.StandardInput.FlushAsync();
await _process.StandardInput.FlushAsync(cancellationToken);
_logger.TransportSentMessage(EndpointName, id);
}
@ -228,7 +228,7 @@ public sealed class StdioClientTransport : TransportBase, IClientTransport
{
_logger.TransportCleaningUp(EndpointName);
if (_process != null && _processStarted && !_process.HasExited)
{
{
try
{
// Try to close stdin to signal the process to exit
@ -253,7 +253,8 @@ public sealed class StdioClientTransport : TransportBase, IClientTransport
_process = null;
}
_shutdownCts?.Cancel();
if (_shutdownCts != null)
await _shutdownCts.CancelAsync();
_shutdownCts?.Dispose();
_shutdownCts = null;

View file

@ -14,7 +14,7 @@ public record StdioClientTransportOptions
/// <summary>
/// Arguments to pass to the server process.
/// </summary>
public string[]? Arguments { get; set; } = Array.Empty<string>();
public string[]? Arguments { get; set; } = [];
/// <summary>
/// The working directory for the server process.

View file

@ -0,0 +1,17 @@
namespace McpDotNet.Protocol.Transport;
/// <summary>
/// List all transport types
/// </summary>
public static class TransportTypes
{
/// <summary>
/// The name of the Standard IO transport.
/// </summary>
public const string StdIo = "stdio";
/// <summary>
/// The name of the ServerSideEvents transport.
/// </summary>
public const string Sse = "sse";
}

View file

@ -8,9 +8,15 @@ namespace McpDotNet.Protocol.Types;
/// </summary>
public class Argument
{
/// <summary>
/// The name of the argument.
/// </summary>
[JsonPropertyName("name")]
public string Name { get; set; } = string.Empty;
/// <summary>
/// The value of the argument to use for completion matching.
/// </summary>
[JsonPropertyName("value")]
public string Value { get; set; } = string.Empty;
}

View file

@ -19,7 +19,7 @@ public class CallToolResponse
/// The server's response to a tools/call request from the client.
/// </summary>
[System.Text.Json.Serialization.JsonPropertyName("content")]
public List<Content> Content { get; set; } = new();
public List<Content> Content { get; set; } = [];
/// <summary>
/// Whether the tool call was unsuccessful. If true, the call was unsuccessful.

View file

@ -16,5 +16,5 @@ public class GetPromptResult
/// The prompt or prompt template that the server offers.
/// </summary>
[System.Text.Json.Serialization.JsonPropertyName("messages")]
public List<PromptMessage> Messages { get; set; } = new();
public List<PromptMessage> Messages { get; set; } = [];
}

View file

@ -12,5 +12,5 @@ public class ListPromptsResult : PaginatedResult
/// A list of prompts or prompt templates that the server offers.
/// </summary>
[System.Text.Json.Serialization.JsonPropertyName("prompts")]
public List<Prompt> Prompts { get; set; } = new();
public List<Prompt> Prompts { get; set; } = [];
}

View file

@ -12,5 +12,5 @@ public class ListResourcesResult : PaginatedResult
/// A list of resources that the server offers.
/// </summary>
[System.Text.Json.Serialization.JsonPropertyName("resources")]
public List<Resource> Resources { get; set; } = new();
public List<Resource> Resources { get; set; } = [];
}

View file

@ -12,5 +12,5 @@ public class ListToolsResult : PaginatedResult
/// The server's response to a tools/list request from the client.
/// </summary>
[System.Text.Json.Serialization.JsonPropertyName("tools")]
public List<Tool> Tools { get; set; } = new();
public List<Tool> Tools { get; set; } = [];
}

View file

@ -58,7 +58,7 @@ public class ModelPreferences
public bool Validate(out string errorMessage)
{
bool valid = true;
List<string> errors = new();
List<string> errors = [];
if (CostPriority < 0 || CostPriority > 1)
{
errors.Add("CostPriority must be between 0 and 1");

View file

@ -10,5 +10,5 @@ public class ReadResourceResult
/// A list of ResourceContents that this resource contains.
/// </summary>
[System.Text.Json.Serialization.JsonPropertyName("contents")]
public List<ResourceContents> Contents { get; set; } = new();
public List<ResourceContents> Contents { get; set; } = [];
}

View file

@ -14,9 +14,15 @@ public class Reference
[JsonPropertyName("type")]
public string Type { get; set; } = string.Empty;
/// <summary>
/// The URI or URI template of the resource.
/// </summary>
[JsonPropertyName("uri")]
public string? Uri { get; set; }
/// <summary>
/// The name of the prompt or prompt template.
/// </summary>
[JsonPropertyName("name")]
public string? Name { get; set; }
@ -65,6 +71,9 @@ public class Reference
/// </summary>
public class CompleteResult
{
/// <summary>
/// The completion object containing the completion values.
/// </summary>
[JsonPropertyName("completion")]
public Completion Completion { get; set; } = new Completion();
}

View file

@ -1,5 +1,5 @@
using McpDotNet.Protocol.Types;
using McpDotNet.Protocol.Messages;
using McpDotNet.Protocol.Messages;
using McpDotNet.Protocol.Types;
namespace McpDotNet.Server;
@ -31,37 +31,37 @@ public interface IMcpServer : IAsyncDisposable
/// <summary>
/// Gets or sets the handler for list tools requests.
/// </summary>
Func<ListToolsRequestParams, CancellationToken, Task<ListToolsResult>>? ListToolsHandler { get; set; }
Func<ListToolsRequestParams?, CancellationToken, Task<ListToolsResult>>? ListToolsHandler { get; set; }
/// <summary>
/// Gets or sets the handler for call tool requests.
/// </summary>
Func<CallToolRequestParams, CancellationToken, Task<CallToolResponse>>? CallToolHandler { get; set; }
Func<CallToolRequestParams?, CancellationToken, Task<CallToolResponse>>? CallToolHandler { get; set; }
/// <summary>
/// Gets or sets the handler for list prompts requests.
/// </summary>
Func<ListPromptsRequestParams, CancellationToken, Task<ListPromptsResult>>? ListPromptsHandler { get; set; }
Func<ListPromptsRequestParams?, CancellationToken, Task<ListPromptsResult>>? ListPromptsHandler { get; set; }
/// <summary>
/// Gets or sets the handler for get prompt requests.
/// </summary>
Func<GetPromptRequestParams, CancellationToken, Task<GetPromptResult>>? GetPromptHandler { get; set; }
Func<GetPromptRequestParams?, CancellationToken, Task<GetPromptResult>>? GetPromptHandler { get; set; }
/// <summary>
/// Gets or sets the handler for list resources requests.
/// </summary>
Func<ListResourcesRequestParams, CancellationToken, Task<ListResourcesResult>>? ListResourcesHandler { get; set; }
Func<ListResourcesRequestParams?, CancellationToken, Task<ListResourcesResult>>? ListResourcesHandler { get; set; }
/// <summary>
/// Gets or sets the handler for read resources requests.
/// </summary>
Func<ReadResourceRequestParams, CancellationToken, Task<ReadResourceResult>>? ReadResourceHandler { get; set; }
Func<ReadResourceRequestParams?, CancellationToken, Task<ReadResourceResult>>? ReadResourceHandler { get; set; }
/// <summary>
/// Gets or sets the handler for get resources requests.
/// </summary>
Func<CompleteRequestParams, CancellationToken, Task<CompleteResult>>? GetCompletionHandler { get; set; }
Func<CompleteRequestParams?, CancellationToken, Task<CompleteResult>>? GetCompletionHandler { get; set; }
/// <summary>
/// Gets or sets the handler for subscribe to resources messages.

View file

@ -139,8 +139,8 @@ internal class McpServer : McpJsonRpcEndpoint, IMcpServer
SetRequestHandler<InitializeRequestParams, InitializeResult>("initialize",
(request) =>
{
ClientCapabilities = request.Capabilities ?? new();
ClientInfo = request.ClientInfo;
ClientCapabilities = request?.Capabilities ?? new();
ClientInfo = request?.ClientInfo;
return Task.FromResult(new InitializeResult()
{
ProtocolVersion = options.ProtocolVersion,
@ -171,25 +171,25 @@ internal class McpServer : McpJsonRpcEndpoint, IMcpServer
public string? ServerInstructions { get; set; }
/// <inheritdoc />
public Func<ListToolsRequestParams, CancellationToken, Task<ListToolsResult>>? ListToolsHandler { get; set; }
public Func<ListToolsRequestParams?, CancellationToken, Task<ListToolsResult>>? ListToolsHandler { get; set; }
/// <inheritdoc />
public Func<CallToolRequestParams, CancellationToken, Task<CallToolResponse>>? CallToolHandler { get; set; }
public Func<CallToolRequestParams?, CancellationToken, Task<CallToolResponse>>? CallToolHandler { get; set; }
/// <inheritdoc />
public Func<ListPromptsRequestParams, CancellationToken, Task<ListPromptsResult>>? ListPromptsHandler { get; set; }
public Func<ListPromptsRequestParams?, CancellationToken, Task<ListPromptsResult>>? ListPromptsHandler { get; set; }
/// <inheritdoc />
public Func<GetPromptRequestParams, CancellationToken, Task<GetPromptResult>>? GetPromptHandler { get; set; }
public Func<GetPromptRequestParams?, CancellationToken, Task<GetPromptResult>>? GetPromptHandler { get; set; }
/// <inheritdoc />
public Func<ListResourcesRequestParams, CancellationToken, Task<ListResourcesResult>>? ListResourcesHandler { get; set; }
public Func<ListResourcesRequestParams?, CancellationToken, Task<ListResourcesResult>>? ListResourcesHandler { get; set; }
/// <inheritdoc />
public Func<ReadResourceRequestParams, CancellationToken, Task<ReadResourceResult>>? ReadResourceHandler { get; set; }
public Func<ReadResourceRequestParams?, CancellationToken, Task<ReadResourceResult>>? ReadResourceHandler { get; set; }
/// <inheritdoc />
public Func<CompleteRequestParams, CancellationToken, Task<CompleteResult>>? GetCompletionHandler { get; set; }
public Func<CompleteRequestParams?, CancellationToken, Task<CompleteResult>>? GetCompletionHandler { get; set; }
/// <inheritdoc />
public Func<string, CancellationToken, Task>? SubscribeToResourcesHandler { get; set; }

Some files were not shown because too many files have changed in this diff Show more