-
Notifications
You must be signed in to change notification settings - Fork 680
Expand file tree
/
Copy pathProgram.cs
More file actions
52 lines (43 loc) · 1.34 KB
/
Program.cs
File metadata and controls
52 lines (43 loc) · 1.34 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
47
48
49
50
51
52
using System.Text.Json;
using ModelContextProtocol;
using ModelContextProtocol.Client;
using ModelContextProtocol.Protocol;
var endpoint = Environment.GetEnvironmentVariable("ENDPOINT") ?? "http://localhost:3001";
var clientTransport = new HttpClientTransport(new()
{
Endpoint = new Uri(endpoint),
TransportMode = HttpTransportMode.StreamableHttp,
});
McpClientOptions options = new()
{
ClientInfo = new()
{
Name = "ProgressClient",
Version = "1.0.0"
}
};
await using var mcpClient = await McpClient.CreateAsync(clientTransport, options);
var tools = await mcpClient.ListToolsAsync();
foreach (var tool in tools)
{
Console.WriteLine($"Connected to server with tools: {tool.Name}");
}
Console.WriteLine($"Calling tool: {tools.First().Name}");
// <snippet_ProgressHandler>
var progressHandler = new Progress<ProgressNotificationValue>(value =>
{
Console.WriteLine($"Tool progress: {value.Progress} of {value.Total} - {value.Message}");
});
var result = await mcpClient.CallToolAsync(toolName: tools.First().Name, progress: progressHandler);
// </snippet_ProgressHandler>
foreach (var block in result.Content)
{
if (block is TextContentBlock textBlock)
{
Console.WriteLine(textBlock.Text);
}
else
{
Console.WriteLine($"Received unexpected result content of type {block.GetType()}");
}
}