Skip to content

Commit caa6e11

Browse files
authored
.Net: Update ModelContextProtocol to 0.4.0-preview.3 (#13271)
1 parent 2530daf commit caa6e11

14 files changed

Lines changed: 22 additions & 28 deletions

File tree

‎dotnet/Directory.Packages.props‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@
8181
<PackageVersion Include="Microsoft.SemanticKernel.Planners.OpenAI" Version="1.47.0-preview" />
8282
<PackageVersion Include="Microsoft.VisualStudio.Threading" Version="17.12.19" />
8383
<PackageVersion Include="Microsoft.AspNetCore.SignalR.Client" Version="9.0.10" />
84-
<PackageVersion Include="ModelContextProtocol" Version="0.3.0-preview.2" />
84+
<PackageVersion Include="ModelContextProtocol" Version="0.4.0-preview.3" />
8585
<PackageVersion Include="MSTest.TestFramework" Version="3.8.0" />
8686
<PackageVersion Include="Newtonsoft.Json" Version="13.0.4" />
8787
<PackageVersion Include="Npgsql" Version="8.0.7" />

‎dotnet/samples/Demos/ModelContextProtocolClientServer/MCPClient/Samples/AgentAvailableAsMCPToolSample.cs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public static async Task RunAsync()
3333
Console.WriteLine($"Running the {nameof(AgentAvailableAsMCPToolSample)} sample.");
3434

3535
// Create an MCP client
36-
await using IMcpClient mcpClient = await CreateMcpClientAsync();
36+
McpClient mcpClient = await CreateMcpClientAsync();
3737

3838
// Retrieve and display the list provided by the MCP server
3939
IList<McpClientTool> tools = await mcpClient.ListToolsAsync();

‎dotnet/samples/Demos/ModelContextProtocolClientServer/MCPClient/Samples/AzureAIAgentWithMCPToolsSample.cs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public static async Task RunAsync()
3737
Console.WriteLine($"Running the {nameof(AzureAIAgentWithMCPToolsSample)} sample.");
3838

3939
// Create an MCP client
40-
await using IMcpClient mcpClient = await CreateMcpClientAsync();
40+
McpClient mcpClient = await CreateMcpClientAsync();
4141

4242
// Retrieve and display the list provided by the MCP server
4343
IList<McpClientTool> tools = await mcpClient.ListToolsAsync();

‎dotnet/samples/Demos/ModelContextProtocolClientServer/MCPClient/Samples/BaseSample.cs‎

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,27 +21,24 @@ internal abstract class BaseSample
2121
/// <param name="kernel">Optional kernel instance to use for the MCP client.</param>
2222
/// <param name="samplingRequestHandler">Optional handler for MCP sampling requests.</param>
2323
/// <returns>An instance of <see cref="IMcpClient"/>.</returns>
24-
protected static Task<IMcpClient> CreateMcpClientAsync(
24+
protected static Task<McpClient> CreateMcpClientAsync(
2525
Kernel? kernel = null,
2626
Func<Kernel, CreateMessageRequestParams?, IProgress<ProgressNotificationValue>, CancellationToken, Task<CreateMessageResult>>? samplingRequestHandler = null)
2727
{
2828
KernelFunction? skSamplingHandler = null;
2929

3030
// Create and return the MCP client
31-
return McpClientFactory.CreateAsync(
31+
return McpClient.CreateAsync(
3232
clientTransport: new StdioClientTransport(new StdioClientTransportOptions
3333
{
3434
Name = "MCPServer",
3535
Command = GetMCPServerPath(), // Path to the MCPServer executable
3636
}),
3737
clientOptions: samplingRequestHandler != null ? new McpClientOptions()
3838
{
39-
Capabilities = new ClientCapabilities
39+
Handlers = new()
4040
{
41-
Sampling = new SamplingCapability
42-
{
43-
SamplingHandler = InvokeHandlerAsync
44-
},
41+
SamplingHandler = InvokeHandlerAsync,
4542
},
4643
} : null
4744
);

‎dotnet/samples/Demos/ModelContextProtocolClientServer/MCPClient/Samples/ChatCompletionAgentWithMCPToolsSample.cs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public static async Task RunAsync()
3434
Console.WriteLine($"Running the {nameof(ChatCompletionAgentWithMCPToolsSample)} sample.");
3535

3636
// Create an MCP client
37-
await using IMcpClient mcpClient = await CreateMcpClientAsync();
37+
McpClient mcpClient = await CreateMcpClientAsync();
3838

3939
// Retrieve and display the list provided by the MCP server
4040
IList<McpClientTool> tools = await mcpClient.ListToolsAsync();

‎dotnet/samples/Demos/ModelContextProtocolClientServer/MCPClient/Samples/MCPPromptSample.cs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public static async Task RunAsync()
2929
Console.WriteLine($"Running the {nameof(MCPPromptSample)} sample.");
3030

3131
// Create an MCP client
32-
await using IMcpClient mcpClient = await CreateMcpClientAsync();
32+
McpClient mcpClient = await CreateMcpClientAsync();
3333

3434
// Retrieve and display the list of prompts provided by the MCP server
3535
IList<McpClientPrompt> prompts = await mcpClient.ListPromptsAsync();

‎dotnet/samples/Demos/ModelContextProtocolClientServer/MCPClient/Samples/MCPResourceTemplatesSample.cs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public static async Task RunAsync()
2929
Console.WriteLine($"Running the {nameof(MCPResourceTemplatesSample)} sample.");
3030

3131
// Create an MCP client
32-
await using IMcpClient mcpClient = await CreateMcpClientAsync();
32+
McpClient mcpClient = await CreateMcpClientAsync();
3333

3434
// Retrieve list of resource templates provided by the MCP server and display them
3535
IList<McpClientResourceTemplate> resourceTemplates = await mcpClient.ListResourceTemplatesAsync();
@@ -48,7 +48,7 @@ public static async Task RunAsync()
4848
string prompt = "What is the Semantic Kernel?";
4949

5050
// Retrieve relevant to the prompt records via MCP resource template
51-
ReadResourceResult resource = await mcpClient.ReadResourceAsync($"vectorStore://records/{prompt}");
51+
ReadResourceResult resource = await mcpClient.ReadResourceAsync(new Uri($"vectorStore://records/{prompt}"));
5252

5353
// Add the resource content/records to the chat history and prompt the AI model to explain what SK is
5454
ChatHistory chatHistory = [];

‎dotnet/samples/Demos/ModelContextProtocolClientServer/MCPClient/Samples/MCPResourcesSample.cs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public static async Task RunAsync()
2929
Console.WriteLine($"Running the {nameof(MCPResourcesSample)} sample.");
3030

3131
// Create an MCP client
32-
await using IMcpClient mcpClient = await CreateMcpClientAsync();
32+
McpClient mcpClient = await CreateMcpClientAsync();
3333

3434
// Retrieve list of resources provided by the MCP server and display them
3535
IList<McpClientResource> resources = await mcpClient.ListResourcesAsync();
@@ -46,7 +46,7 @@ public static async Task RunAsync()
4646
};
4747

4848
// Retrieve the `image://cat.jpg` resource from the MCP server
49-
ReadResourceResult resource = await mcpClient.ReadResourceAsync("image://cat.jpg");
49+
ReadResourceResult resource = await mcpClient.ReadResourceAsync(new Uri("image://cat.jpg"));
5050

5151
// Add the resource to the chat history and prompt the AI model to describe the content of the image
5252
ChatHistory chatHistory = [];

‎dotnet/samples/Demos/ModelContextProtocolClientServer/MCPClient/Samples/MCPSamplingSample.cs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public static async Task RunAsync()
4747
kernel.FunctionInvocationFilters.Add(new HumanInTheLoopFilter());
4848

4949
// Create an MCP client with a custom sampling request handler
50-
await using IMcpClient mcpClient = await CreateMcpClientAsync(kernel, SamplingRequestHandlerAsync);
50+
McpClient mcpClient = await CreateMcpClientAsync(kernel, SamplingRequestHandlerAsync);
5151

5252
// Import MCP tools as Kernel functions so AI model can call them
5353
IList<McpClientTool> tools = await mcpClient.ListToolsAsync();

‎dotnet/samples/Demos/ModelContextProtocolClientServer/MCPClient/Samples/MCPToolsSample.cs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public static async Task RunAsync()
3131
Console.WriteLine($"Running the {nameof(MCPToolsSample)} sample.");
3232

3333
// Create an MCP client
34-
await using IMcpClient mcpClient = await CreateMcpClientAsync();
34+
McpClient mcpClient = await CreateMcpClientAsync();
3535

3636
// Retrieve and display the list provided by the MCP server
3737
IList<McpClientTool> tools = await mcpClient.ListToolsAsync();

0 commit comments

Comments
 (0)