Overhaul McpClientFactory/McpServerFactory (#87)
Handlers are now specified before connecting the client/server. Otherwise, race conditions exist. Handlers move into being a part of the McpClientOptions/McpServerOptions, so that they're provided to the factories. Where relevant, the handlers are specified as part of the capability descriptors, so that they go hand in hand. The factories are no longer stateful. Instead of allocating a factory and then calling a create method on it, you just call a static factory method.
This commit is contained in:
parent
63b24a4036
commit
08b0a04dab
1 changed files with 1306 additions and 2243 deletions
|
|
@ -1,7 +1,6 @@
|
|||
using McpDotNet.Client;
|
||||
using McpDotNet.Configuration;
|
||||
using Microsoft.Extensions.AI;
|
||||
using Microsoft.Extensions.Logging.Abstractions;
|
||||
using OpenAI;
|
||||
|
||||
namespace McpDotNet.Extensions.AI.Tests;
|
||||
|
|
@ -35,19 +34,13 @@ public class IntegrationTests
|
|||
ClientInfo = new() { Name = "McpDotNet.Extensions.AI.Tests", Version = "1.0.0" }
|
||||
};
|
||||
|
||||
var factory = new McpClientFactory(
|
||||
[GetEverythingServerConfig()],
|
||||
options,
|
||||
NullLoggerFactory.Instance
|
||||
);
|
||||
|
||||
return await factory.GetClientAsync("everything");
|
||||
return await McpClientFactory.CreateAsync(GetEverythingServerConfig(), options);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task IntegrateWithMeai_UsingEverythingServer_ToolsAreProperlyCalled()
|
||||
{
|
||||
var client = await GetMcpClientAsync();
|
||||
await using var client = await GetMcpClientAsync();
|
||||
var mappedTools = await client.ListToolsAsync().Select(t => t.ToAITool(client)).ToListAsync();
|
||||
|
||||
IChatClient openaiClient = new OpenAIClient(_openAIKey)
|
||||
|
|
|
|||
Loading…
Reference in a new issue