-
-
Notifications
You must be signed in to change notification settings - Fork 634
Expand file tree
/
Copy pathMcpService.cs
More file actions
46 lines (39 loc) · 1.26 KB
/
McpService.cs
File metadata and controls
46 lines (39 loc) · 1.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
using BotSharp.Core.MCP.Managers;
using BotSharp.Core.MCP.Settings;
using Microsoft.Extensions.Logging;
using ModelContextProtocol.Client;
namespace BotSharp.Core.MCP.Services;
public class McpService : IMcpService
{
private readonly IServiceProvider _services;
private readonly ILogger<McpService> _logger;
private readonly McpClientManager _mcpClientManager;
public McpService(
IServiceProvider services,
ILogger<McpService> logger,
McpClientManager mcpClient)
{
_services = services;
_logger = logger;
_mcpClientManager = mcpClient;
}
public IEnumerable<McpServerOptionModel> GetServerConfigs()
{
var options = new List<McpServerOptionModel>();
var settings = _services.GetRequiredService<McpSettings>();
var configs = settings?.McpServerConfigs ?? [];
foreach (var config in configs)
{
var tools = _mcpClientManager.GetMcpClientAsync(config.Id)
.Result.ListToolsAsync()
.Result.Select(x=> x.Name);
options.Add(new McpServerOptionModel
{
Id = config.Id,
Name = config.Name,
Tools = tools
});
}
return options;
}
}