2025-04-01 01:59:19 +00:00
|
|
|
using BotSharp.Core.MCP.Settings;
|
|
|
|
|
using ModelContextProtocol.Client;
|
|
|
|
|
|
|
|
|
|
namespace BotSharp.Core.MCP.Managers;
|
|
|
|
|
|
|
|
|
|
public class McpClientManager : IDisposable
|
|
|
|
|
{
|
2025-04-01 03:11:18 +00:00
|
|
|
private readonly McpSettings _mcpSettings;
|
2025-04-01 01:59:19 +00:00
|
|
|
|
2025-04-01 03:11:18 +00:00
|
|
|
public McpClientManager(McpSettings mcpSettings)
|
2025-04-01 01:59:19 +00:00
|
|
|
{
|
2025-04-01 03:11:18 +00:00
|
|
|
_mcpSettings = mcpSettings;
|
2025-04-01 01:59:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task<IMcpClient> GetMcpClientAsync(string serverId)
|
|
|
|
|
{
|
|
|
|
|
return await McpClientFactory.CreateAsync(
|
2025-04-01 03:11:18 +00:00
|
|
|
_mcpSettings.McpServerConfigs.Where(x=> x.Name == serverId).First(),
|
|
|
|
|
_mcpSettings.McpClientOptions);
|
2025-04-01 01:59:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Dispose()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|