Skip to content

Commit 96fa96c

Browse files
authored
Split StdioClient/ServerTransports into Stdio : Stream (#172)
1 parent 57a526e commit 96fa96c

12 files changed

+667
-687
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
using Microsoft.Extensions.Logging;
2+
using ModelContextProtocol.Logging;
3+
using ModelContextProtocol.Protocol.Messages;
4+
using System.Diagnostics;
5+
6+
namespace ModelContextProtocol.Protocol.Transport;
7+
8+
/// <summary>Provides the client side of a stdio-based session transport.</summary>
9+
internal sealed class StdioClientSessionTransport : StreamClientSessionTransport
10+
{
11+
private readonly StdioClientTransportOptions _options;
12+
private readonly Process _process;
13+
14+
public StdioClientSessionTransport(StdioClientTransportOptions options, Process process, string endpointName, ILoggerFactory? loggerFactory)
15+
: base(process.StandardInput, process.StandardOutput, endpointName, loggerFactory)
16+
{
17+
_process = process;
18+
_options = options;
19+
}
20+
21+
/// <inheritdoc/>
22+
public override async Task SendMessageAsync(IJsonRpcMessage message, CancellationToken cancellationToken = default)
23+
{
24+
if (_process.HasExited)
25+
{
26+
Logger.TransportNotConnected(EndpointName);
27+
throw new McpTransportException("Transport is not connected");
28+
}
29+
30+
await base.SendMessageAsync(message, cancellationToken).ConfigureAwait(false);
31+
}
32+
33+
/// <inheritdoc/>
34+
protected override ValueTask CleanupAsync(CancellationToken cancellationToken)
35+
{
36+
StdioClientTransport.DisposeProcess(_process, processStarted: true, Logger, _options.ShutdownTimeout, EndpointName);
37+
38+
return base.CleanupAsync(cancellationToken);
39+
}
40+
}

src/ModelContextProtocol/Protocol/Transport/StdioClientStreamTransport.cs

Lines changed: 0 additions & 326 deletions
This file was deleted.

0 commit comments

Comments
 (0)