Add ModelContextProtocol.AspNetCore (#160)

* Add ModelContextProtocol.AspNetCore

- Remove IServerTransport and HttpListenerSseServerTransport
- Replace HttpListenerSseServerTransport usage in tests with ASP.NET Core.

Co-authored-by: Eirik Tsarpalis <eirik.tsarpalis@gmail.com>
Co-authored-by: Jeff Handley <jeffhandley@users.noreply.github.com>
This commit is contained in:
Stephen Halter 2025-03-31 12:01:04 -07:00 • committed by GitHub
commit 973c7c093f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 332 additions and 831 deletions

View file

@ -32,22 +32,16 @@ public class McpServerFactoryTests : LoggedTest
}
[Fact]
public async Task Create_Throws_For_Null_ServerTransport()
public void Create_Throws_For_Null_ServerTransport()
{
// Arrange, Act & Assert
Assert.Throws<ArgumentNullException>("transport", () => McpServerFactory.Create(null!, _options, LoggerFactory));
await Assert.ThrowsAsync<ArgumentNullException>("serverTransport", () =>
McpServerFactory.AcceptAsync(null!, _options, LoggerFactory, cancellationToken: TestContext.Current.CancellationToken));
}
[Fact]
public async Task Create_Throws_For_Null_Options()
public void Create_Throws_For_Null_Options()
{
// Arrange, Act & Assert
Assert.Throws<ArgumentNullException>("serverOptions", () => McpServerFactory.Create(Mock.Of<ITransport>(), null!, LoggerFactory));
await Assert.ThrowsAsync<ArgumentNullException>("serverOptions", () =>
McpServerFactory.AcceptAsync(Mock.Of<IServerTransport>(), null!, LoggerFactory, cancellationToken: TestContext.Current.CancellationToken));
}
}

View file

@ -168,18 +168,6 @@ public class McpServerTests : LoggedTest
await runTask;
}
[Fact]
public async Task Throws_Exception_If_Not_Connected()
{
await using var server = McpServerFactory.Create(_serverTransport.Object, _options, LoggerFactory, _serviceProvider);
SetClientCapabilities(server, new ClientCapabilities { Roots = new RootsCapability() });
_serverTransport.SetupGet(t => t.IsConnected).Returns(false);
var action = async () => await server.RequestRootsAsync(new ListRootsRequestParams(), CancellationToken.None);
await Assert.ThrowsAsync<McpClientException>(action);
}
[Fact]
public async Task Can_Handle_Ping_Requests()
{