* Move notification handler registrations to capabilities Currently request handlers are set on the capability objects, but notification handlers are set after construction via an AddNotificationHandler method on the IMcpEndpoint interface. This moves handler specification to be at construction as well. This makes it more consistent with request handlers, simplifies the IMcpEndpoint interface to just be about message sending, and avoids a concurrency bug that could occur if someone tried to add a handler while the endpoint was processing notifications. * Address more feedback and further cleanup
61 lines
No EOL
2.1 KiB
C#
61 lines
No EOL
2.1 KiB
C#
using ModelContextProtocol.Client;
|
|
using ModelContextProtocol.Protocol.Transport;
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
namespace ModelContextProtocol.Tests;
|
|
|
|
public class ClientIntegrationTestFixture
|
|
{
|
|
private ILoggerFactory? _loggerFactory;
|
|
|
|
public McpServerConfig EverythingServerConfig { get; }
|
|
public McpServerConfig TestServerConfig { get; }
|
|
|
|
public static IEnumerable<string> ClientIds => ["everything", "test_server"];
|
|
|
|
public ClientIntegrationTestFixture()
|
|
{
|
|
EverythingServerConfig = new()
|
|
{
|
|
Id = "everything",
|
|
Name = "Everything",
|
|
TransportType = TransportTypes.StdIo,
|
|
TransportOptions = new Dictionary<string, string>
|
|
{
|
|
["command"] = "npx",
|
|
// Change to ["arguments"] = "mcp-server-everything" if you want to run the server locally after creating a symlink
|
|
["arguments"] = "-y --verbose @modelcontextprotocol/server-everything"
|
|
}
|
|
};
|
|
|
|
TestServerConfig = new()
|
|
{
|
|
Id = "test_server",
|
|
Name = "TestServer",
|
|
TransportType = TransportTypes.StdIo,
|
|
TransportOptions = new Dictionary<string, string>
|
|
{
|
|
["command"] = OperatingSystem.IsWindows() ? "TestServer.exe" : "dotnet",
|
|
// Change to ["arguments"] = "mcp-server-everything" if you want to run the server locally after creating a symlink
|
|
}
|
|
};
|
|
|
|
if (!OperatingSystem.IsWindows())
|
|
{
|
|
TestServerConfig.TransportOptions["arguments"] = "TestServer.dll";
|
|
}
|
|
}
|
|
|
|
public void Initialize(ILoggerFactory loggerFactory)
|
|
{
|
|
_loggerFactory = loggerFactory;
|
|
}
|
|
|
|
public Task<IMcpClient> CreateClientAsync(string clientId, McpClientOptions? clientOptions = null) =>
|
|
McpClientFactory.CreateAsync(clientId switch
|
|
{
|
|
"everything" => EverythingServerConfig,
|
|
"test_server" => TestServerConfig,
|
|
_ => throw new ArgumentException($"Unknown client ID: {clientId}")
|
|
}, clientOptions, loggerFactory: _loggerFactory);
|
|
} |