-
Notifications
You must be signed in to change notification settings - Fork 42
Expand file tree
/
Copy pathMCPClientPool.cs
More file actions
38 lines (32 loc) · 1.32 KB
/
MCPClientPool.cs
File metadata and controls
38 lines (32 loc) · 1.32 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
using MCPSharp;
using Microsoft.Extensions.AI;
using System.Collections;
class MCPClientPool : ICollection<MCPClient>
{
private readonly List<MCPClient> clients = [];
public async Task<List<AITool>> GetAllAIFunctionsAsync()
{
var functions = new List<AITool>();
foreach (var c in clients)
{
functions.AddRange(await c.GetFunctionsAsync());
}
return functions;
}
public int Count => clients.Count;
public bool IsReadOnly => false;
public void Add(string name, McpServerConfiguration server, Func<Dictionary<string, object>, bool>? permissionFunction = null)
{
clients.Add(new MCPClient(name, "0.1.0", server.Command, string.Join(' ', server.Args ?? []), server.Env)
{
GetPermission = permissionFunction ?? ((parameters) => true)
});
}
public void Add(MCPClient item) => clients.Add(item);
public void Clear() => clients.Clear();
public bool Contains(MCPClient item) => clients.Contains(item);
public void CopyTo(MCPClient[] array, int arrayIndex) => clients.CopyTo(array, arrayIndex);
public IEnumerator<MCPClient> GetEnumerator() => clients.GetEnumerator();
public bool Remove(MCPClient item) => clients.Remove(item);
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
}