File tree Expand file tree Collapse file tree 2 files changed +8
-9
lines changed
docs/ai/quickstarts/snippets/mcp-client Expand file tree Collapse file tree 2 files changed +8
-9
lines changed Original file line number Diff line number Diff line change 1
- <Project Sdk =" Microsoft.NET.Sdk" >
1
+ <Project Sdk =" Microsoft.NET.Sdk" >
2
2
3
3
<PropertyGroup >
4
4
<OutputType >Exe</OutputType >
9
9
10
10
<ItemGroup >
11
11
<PackageReference Include =" Azure.AI.OpenAI" Version =" 2.2.0-beta.4" />
12
- <PackageReference Include =" Azure.Identity" Version =" 1.13.2 " />
12
+ <PackageReference Include =" Azure.Identity" Version =" 1.14.0 " />
13
13
<PackageReference Include =" Microsoft.Extensions.AI" Version =" 9.5.0" />
14
14
<PackageReference Include =" Microsoft.Extensions.AI.OpenAI" Version =" 9.4.3-preview.1.25230.7" />
15
- <PackageReference Include =" ModelContextProtocol" Version =" 0.1.0-preview.11 " />
15
+ <PackageReference Include =" ModelContextProtocol" Version =" 0.1.0-preview.14 " />
16
16
</ItemGroup >
17
17
18
18
</Project >
Original file line number Diff line number Diff line change 2
2
using Azure . Identity ;
3
3
using Microsoft . Extensions . AI ;
4
4
using ModelContextProtocol . Client ;
5
- using ModelContextProtocol . Protocol . Transport ;
6
5
7
6
// Create an IChatClient using Azure OpenAI.
8
7
IChatClient client =
15
14
16
15
// Create the MCP client
17
16
// Configure it to start and connect to your MCP server.
18
- var mcpClient = await McpClientFactory . CreateAsync (
17
+ IMcpClient mcpClient = await McpClientFactory . CreateAsync (
19
18
new StdioClientTransport ( new ( )
20
19
{
21
20
Command = "dotnet run" ,
25
24
26
25
// List all available tools from the MCP server.
27
26
Console . WriteLine ( "Available tools:" ) ;
28
- var tools = await mcpClient . ListToolsAsync ( ) ;
29
- foreach ( var tool in tools )
27
+ IList < McpClientTool > tools = await mcpClient . ListToolsAsync ( ) ;
28
+ foreach ( McpClientTool tool in tools )
30
29
{
31
30
Console . WriteLine ( $ "{ tool } ") ;
32
31
}
40
39
messages . Add ( new ( ChatRole . User , Console . ReadLine ( ) ) ) ;
41
40
42
41
List < ChatResponseUpdate > updates = [ ] ;
43
- await foreach ( var update in client
42
+ await foreach ( ChatResponseUpdate update in client
44
43
. GetStreamingResponseAsync ( messages , new ( ) { Tools = [ .. tools ] } ) )
45
44
{
46
45
Console . Write ( update ) ;
49
48
Console . WriteLine ( ) ;
50
49
51
50
messages . AddMessages ( updates ) ;
52
- }
51
+ }
You can’t perform that action at this time.
0 commit comments