Add StreamableHttpHandler and WithHttpTransport (#291)

* Simplify ModelContextProtocol.AspNetCore README

* Add StreamableHttpHandler

* Use "docker info" in CheckIsDockerAvailable

* Call WithHttpTransport in samples, tests and README

* Cleanup test namespaces

* Add CanConnect_WithMcpClient_AfterCustomizingRoute test

* Simplify relative URI handling

* Handle request made directly to the MapMcp route pattern

* Add Messages_FromNewUser_AreRejected test

* Fix README

* Shorten UserIdClaim ValueTuple names

* Remove MaxReconnectAttempts and ReconnectDelay from SseClientTransportOptions

- Add proper AdditionalHeaders support
This commit is contained in:
Stephen Halter 2025-04-14 07:15:33 -07:00 • committed by GitHub
commit 9c124b1770
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 597 additions and 324 deletions

View file

@ -65,7 +65,8 @@ public class EverythingSseServerFixture : IAsyncDisposable
ProcessStartInfo processStartInfo = new()
{
FileName = "docker",
Arguments = "--version",
// "docker info" returns a non-zero exit code if docker engine is not running.
Arguments = "info",
UseShellExecute = false,
};

View file

@ -17,8 +17,6 @@ public class SseClientTransportTests : LoggedTest
{
Endpoint = new Uri("http://localhost:8080"),
ConnectionTimeout = TimeSpan.FromSeconds(2),
MaxReconnectAttempts = 3,
ReconnectDelay = TimeSpan.FromMilliseconds(50),
Name = "Test Server",
AdditionalHeaders = new Dictionary<string, string>
{
@ -76,15 +74,12 @@ public class SseClientTransportTests : LoggedTest
mockHttpHandler.RequestHandler = (request) =>
{
retries++;
throw new InvalidOperationException("Test exception");
throw new Exception("Test exception");
};
var action = async () => await transport.ConnectAsync();
var exception = await Assert.ThrowsAsync<McpTransportException>(action);
Assert.Equal("Exceeded reconnect limit", exception.Message);
Assert.Equal(_transportOptions.MaxReconnectAttempts, retries);
var exception = await Assert.ThrowsAsync<Exception>(() => transport.ConnectAsync(TestContext.Current.CancellationToken));
Assert.Equal("Test exception", exception.Message);
Assert.Equal(1, retries);
}
[Fact]

View file

@ -1,5 +1,4 @@
using Microsoft.Extensions.Logging;
using ModelContextProtocol.Test.Utils;
namespace ModelContextProtocol.Tests.Utils;

View file

@ -2,7 +2,7 @@
using System.Text;
using Microsoft.Extensions.Logging;
namespace ModelContextProtocol.Test.Utils;
namespace ModelContextProtocol.Tests.Utils;
public class XunitLoggerProvider(ITestOutputHelper output) : ILoggerProvider
{