-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathHuggingFaceMCP.cs
More file actions
35 lines (29 loc) · 1.02 KB
/
HuggingFaceMCP.cs
File metadata and controls
35 lines (29 loc) · 1.02 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
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;
using ModelContextProtocol.Client;
namespace MAF_ImageGen_01;
public class HuggingFaceMCP
{
public static async Task<(McpClient Client, IList<McpClientTool> Tools)> GetHuggingFaceMCPClientAndToolsAsync()
{
var builder = Host.CreateApplicationBuilder();
var config = builder.Configuration
.AddEnvironmentVariables()
.AddUserSecrets<Program>()
.Build();
var hfHeaders = new Dictionary<string, string>
{
{ "Authorization", $"Bearer {config["HF_API_KEY"]}" }
};
var clientTransport = new HttpClientTransport(
new()
{
Name = "HF Server",
Endpoint = new Uri("https://huggingface.co/mcp"),
AdditionalHeaders = hfHeaders
});
var mcpClient = await McpClient.CreateAsync(clientTransport);
var tools = await mcpClient.ListToolsAsync();
return (mcpClient, tools);
}
}