Improve exception diagnostics for stdio client (#376)
* Improve exception diagnostics for stdio client Track the last several lines of stderr and include those in an exception created as part of CleanupAsync if the server process has already exited. This is based on an assumption that the server should never exit prior to CleanupAsync being called. * Address feedback and fix test failure
This commit is contained in:
parent
8d4f51da50
commit
c11c634945
1 changed files with 222 additions and 131 deletions
|
|
@ -0,0 +1,21 @@
|
|||
using ModelContextProtocol.Client;
|
||||
using ModelContextProtocol.Protocol.Transport;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace ModelContextProtocol.Tests.Transport;
|
||||
|
||||
public class StdioClientTransportTests
|
||||
{
|
||||
[Fact]
|
||||
public async Task CreateAsync_ValidProcessInvalidServer_Throws()
|
||||
{
|
||||
string id = Guid.NewGuid().ToString("N");
|
||||
|
||||
StdioClientTransport transport = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ?
|
||||
new(new() { Command = "cmd", Arguments = ["/C", $"echo \"{id}\" >&2"] }) :
|
||||
new(new() { Command = "ls", Arguments = [id] });
|
||||
|
||||
IOException e = await Assert.ThrowsAsync<IOException>(() => McpClientFactory.CreateAsync(transport, cancellationToken: TestContext.Current.CancellationToken));
|
||||
Assert.Contains(id, e.ToString());
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue