Add net10.0 assets and run some fixers (#875)
This commit is contained in:
parent
e7b403b820
commit
bfc0980ef5
3 changed files with 168 additions and 194 deletions
|
|
@ -11,8 +11,6 @@ namespace ModelContextProtocol.Client;
|
|||
/// </remarks>
|
||||
public sealed class McpClientOptions
|
||||
{
|
||||
private McpClientHandlers? _handlers;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets information about this client implementation, including its name and version.
|
||||
/// </summary>
|
||||
|
|
@ -71,11 +69,11 @@ public sealed class McpClientOptions
|
|||
/// </summary>
|
||||
public McpClientHandlers Handlers
|
||||
{
|
||||
get => _handlers ??= new();
|
||||
get => field ??= new();
|
||||
set
|
||||
{
|
||||
Throw.IfNull(value);
|
||||
_handlers = value;
|
||||
field = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,21 +5,15 @@ using System.Diagnostics;
|
|||
namespace ModelContextProtocol.Client;
|
||||
|
||||
/// <summary>Provides the client side of a stdio-based session transport.</summary>
|
||||
internal sealed class StdioClientSessionTransport : StreamClientSessionTransport
|
||||
internal sealed class StdioClientSessionTransport(
|
||||
StdioClientTransportOptions options, Process process, string endpointName, Queue<string> stderrRollingLog, ILoggerFactory? loggerFactory) :
|
||||
StreamClientSessionTransport(process.StandardInput.BaseStream, process.StandardOutput.BaseStream, encoding: null, endpointName, loggerFactory)
|
||||
{
|
||||
private readonly StdioClientTransportOptions _options;
|
||||
private readonly Process _process;
|
||||
private readonly Queue<string> _stderrRollingLog;
|
||||
private readonly StdioClientTransportOptions _options = options;
|
||||
private readonly Process _process = process;
|
||||
private readonly Queue<string> _stderrRollingLog = stderrRollingLog;
|
||||
private int _cleanedUp = 0;
|
||||
|
||||
public StdioClientSessionTransport(StdioClientTransportOptions options, Process process, string endpointName, Queue<string> stderrRollingLog, ILoggerFactory? loggerFactory)
|
||||
: base(process.StandardInput.BaseStream, process.StandardOutput.BaseStream, encoding: null, endpointName, loggerFactory)
|
||||
{
|
||||
_process = process;
|
||||
_options = options;
|
||||
_stderrRollingLog = stderrRollingLog;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override async Task SendMessageAsync(JsonRpcMessage message, CancellationToken cancellationToken = default)
|
||||
{
|
||||
|
|
@ -56,7 +50,7 @@ internal sealed class StdioClientSessionTransport : StreamClientSessionTransport
|
|||
// Now terminate the server process.
|
||||
try
|
||||
{
|
||||
StdioClientTransport.DisposeProcess(_process, processRunning: true, _options.ShutdownTimeout, Name);
|
||||
StdioClientTransport.DisposeProcess(_process, processRunning: true, shutdownTimeout: _options.ShutdownTimeout);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ public sealed partial class StdioClientTransport : IClientTransport
|
|||
|
||||
_options = options;
|
||||
_loggerFactory = loggerFactory;
|
||||
Name = options.Name ?? $"stdio-{Regex.Replace(Path.GetFileName(options.Command), @"[\s\.]+", "-")}";
|
||||
Name = options.Name ?? $"stdio-{WhitespaceAndPeriods().Replace(Path.GetFileName(options.Command), "-")}";
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
|
|
@ -189,7 +189,7 @@ public sealed partial class StdioClientTransport : IClientTransport
|
|||
|
||||
try
|
||||
{
|
||||
DisposeProcess(process, processStarted, _options.ShutdownTimeout, endpointName);
|
||||
DisposeProcess(process, processStarted, _options.ShutdownTimeout);
|
||||
}
|
||||
catch (Exception ex2)
|
||||
{
|
||||
|
|
@ -201,7 +201,7 @@ public sealed partial class StdioClientTransport : IClientTransport
|
|||
}
|
||||
|
||||
internal static void DisposeProcess(
|
||||
Process? process, bool processRunning, TimeSpan shutdownTimeout, string endpointName)
|
||||
Process? process, bool processRunning, TimeSpan shutdownTimeout)
|
||||
{
|
||||
if (process is not null)
|
||||
{
|
||||
|
|
@ -279,4 +279,12 @@ public sealed partial class StdioClientTransport : IClientTransport
|
|||
|
||||
[LoggerMessage(Level = LogLevel.Warning, Message = "{EndpointName} shutdown failed.")]
|
||||
private static partial void LogTransportShutdownFailed(ILogger logger, string endpointName, Exception exception);
|
||||
|
||||
#if NET
|
||||
[GeneratedRegex(@"[\s\.]+")]
|
||||
private static partial Regex WhitespaceAndPeriods();
|
||||
#else
|
||||
private static Regex WhitespaceAndPeriods() => s_whitespaceAndPeriods;
|
||||
private static readonly Regex s_whitespaceAndPeriods = new(@"[\s\.]+", RegexOptions.Compiled);
|
||||
#endif
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue