2025-02-23 14:55:35 +00:00
|
|
|
using BotSharp.Core.Mcp.Settings;
|
2025-02-25 14:57:22 +00:00
|
|
|
using Microsoft.Extensions.Logging;
|
2025-03-21 05:14:19 +00:00
|
|
|
using ModelContextProtocol.Client;
|
2025-02-25 14:57:22 +00:00
|
|
|
using System;
|
2025-03-18 10:43:31 +00:00
|
|
|
using System.Linq;
|
|
|
|
|
using System.Threading.Tasks;
|
2025-02-23 11:45:05 +00:00
|
|
|
|
2025-02-23 14:55:35 +00:00
|
|
|
namespace BotSharp.Core.Mcp;
|
2025-02-23 11:45:05 +00:00
|
|
|
|
|
|
|
|
public class MCPClientManager : IDisposable
|
|
|
|
|
{
|
2025-03-26 05:36:29 +00:00
|
|
|
|
2025-02-23 11:45:05 +00:00
|
|
|
private readonly MCPSettings mcpSettings;
|
|
|
|
|
|
2025-03-26 05:36:29 +00:00
|
|
|
public MCPClientManager(MCPSettings settings)
|
2025-02-23 11:45:05 +00:00
|
|
|
{
|
|
|
|
|
mcpSettings = settings;
|
2025-03-18 10:43:31 +00:00
|
|
|
}
|
2025-02-23 11:45:05 +00:00
|
|
|
|
2025-03-18 10:43:31 +00:00
|
|
|
public async Task<IMcpClient> GetMcpClientAsync(string serverId)
|
|
|
|
|
{
|
|
|
|
|
return await McpClientFactory.CreateAsync(mcpSettings.McpServerConfigs
|
|
|
|
|
.Where(x=> x.Name == serverId).First(), mcpSettings.McpClientOptions);
|
2025-02-23 11:45:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Dispose()
|
|
|
|
|
{
|
2025-03-26 05:36:29 +00:00
|
|
|
|
2025-02-23 11:45:05 +00:00
|
|
|
}
|
|
|
|
|
}
|