Skip to content

Commit ef02432

Browse files
Merge branch 'microsoft:main' into main
2 parents 2896b5a + ad5026f commit ef02432

32 files changed

+285
-316
lines changed

dotnet/Directory.Packages.props

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
<PackageVersion Include="EntityFramework" Version="6.5.1" />
3030
<PackageVersion Include="FastBertTokenizer" Version="1.0.28" />
3131
<PackageVersion Include="Google.Apis.Auth" Version="1.69.0" />
32-
<PackageVersion Include="mcpdotnet" Version="1.0.1.3" />
32+
<PackageVersion Include="ModelContextProtocol" Version="0.1.0-preview.1.25171.12" />
3333
<PackageVersion Include="Microsoft.AspNetCore.Mvc.Testing" Version="8.0.13" />
3434
<PackageVersion Include="Microsoft.AspNetCore.OpenApi" Version="8.0.13" />
3535
<PackageVersion Include="Microsoft.ML.Tokenizers.Data.Cl100kBase" Version="1.0.1" />

dotnet/SK-dotnet.sln

+9-9
Original file line numberDiff line numberDiff line change
@@ -498,8 +498,6 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ChatWithAgent.ServiceDefaul
498498
EndProject
499499
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ChatWithAgent.Web", "samples\Demos\AgentFrameworkWithAspire\ChatWithAgent.Web\ChatWithAgent.Web.csproj", "{543879BF-E2CD-6521-8322-8FBCD6EC57A0}"
500500
EndProject
501-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ModelContextProtocol", "samples\Demos\ModelContextProtocol\ModelContextProtocol.csproj", "{B16AC373-3DA8-4505-9510-110347CD635D}"
502-
EndProject
503501
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "StructuredDataPlugin", "samples\Demos\StructuredDataPlugin\StructuredDataPlugin.csproj", "{BEDAC050-016A-46F4-9173-339C46DFD3ED}"
504502
EndProject
505503
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Plugins.StructuredData.EntityFramework", "src\Plugins\Plugins.StructuredData.EntityFramework\Plugins.StructuredData.EntityFramework.csproj", "{0C81C377-3CDC-46A8-BED1-4B50BDA2202E}"
@@ -508,6 +506,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SqlServerIntegrationTests",
508506
EndProject
509507
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PineconeIntegrationTests", "src\VectorDataIntegrationTests\PineconeIntegrationTests\PineconeIntegrationTests.csproj", "{E9A74E0C-BC02-4DDD-A487-89847EDF8026}"
510508
EndProject
509+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ModelContextProtocolPlugin", "samples\Demos\ModelContextProtocolPlugin\ModelContextProtocolPlugin.csproj", "{801C9CE4-53AF-D2DB-E0D6-9A6BB47E9654}"
510+
EndProject
511511
Global
512512
GlobalSection(SolutionConfigurationPlatforms) = preSolution
513513
Debug|Any CPU = Debug|Any CPU
@@ -1373,12 +1373,6 @@ Global
13731373
{543879BF-E2CD-6521-8322-8FBCD6EC57A0}.Publish|Any CPU.Build.0 = Release|Any CPU
13741374
{543879BF-E2CD-6521-8322-8FBCD6EC57A0}.Release|Any CPU.ActiveCfg = Release|Any CPU
13751375
{543879BF-E2CD-6521-8322-8FBCD6EC57A0}.Release|Any CPU.Build.0 = Release|Any CPU
1376-
{B16AC373-3DA8-4505-9510-110347CD635D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
1377-
{B16AC373-3DA8-4505-9510-110347CD635D}.Debug|Any CPU.Build.0 = Debug|Any CPU
1378-
{B16AC373-3DA8-4505-9510-110347CD635D}.Publish|Any CPU.ActiveCfg = Debug|Any CPU
1379-
{B16AC373-3DA8-4505-9510-110347CD635D}.Publish|Any CPU.Build.0 = Debug|Any CPU
1380-
{B16AC373-3DA8-4505-9510-110347CD635D}.Release|Any CPU.ActiveCfg = Release|Any CPU
1381-
{B16AC373-3DA8-4505-9510-110347CD635D}.Release|Any CPU.Build.0 = Release|Any CPU
13821376
{BEDAC050-016A-46F4-9173-339C46DFD3ED}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
13831377
{BEDAC050-016A-46F4-9173-339C46DFD3ED}.Debug|Any CPU.Build.0 = Debug|Any CPU
13841378
{BEDAC050-016A-46F4-9173-339C46DFD3ED}.Publish|Any CPU.ActiveCfg = Debug|Any CPU
@@ -1403,6 +1397,12 @@ Global
14031397
{E9A74E0C-BC02-4DDD-A487-89847EDF8026}.Publish|Any CPU.Build.0 = Release|Any CPU
14041398
{E9A74E0C-BC02-4DDD-A487-89847EDF8026}.Release|Any CPU.ActiveCfg = Release|Any CPU
14051399
{E9A74E0C-BC02-4DDD-A487-89847EDF8026}.Release|Any CPU.Build.0 = Release|Any CPU
1400+
{801C9CE4-53AF-D2DB-E0D6-9A6BB47E9654}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
1401+
{801C9CE4-53AF-D2DB-E0D6-9A6BB47E9654}.Debug|Any CPU.Build.0 = Debug|Any CPU
1402+
{801C9CE4-53AF-D2DB-E0D6-9A6BB47E9654}.Publish|Any CPU.ActiveCfg = Release|Any CPU
1403+
{801C9CE4-53AF-D2DB-E0D6-9A6BB47E9654}.Publish|Any CPU.Build.0 = Release|Any CPU
1404+
{801C9CE4-53AF-D2DB-E0D6-9A6BB47E9654}.Release|Any CPU.ActiveCfg = Release|Any CPU
1405+
{801C9CE4-53AF-D2DB-E0D6-9A6BB47E9654}.Release|Any CPU.Build.0 = Release|Any CPU
14061406
EndGlobalSection
14071407
GlobalSection(SolutionProperties) = preSolution
14081408
HideSolutionNode = FALSE
@@ -1589,11 +1589,11 @@ Global
15891589
{758457BF-87EF-D8A0-4045-9F03D3DAD0BF} = {41AC66EE-B656-4CDF-A512-C7259C2F6CF7}
15901590
{8C6EC8E2-4DC1-5B2E-F22A-CB4FD96DEF50} = {41AC66EE-B656-4CDF-A512-C7259C2F6CF7}
15911591
{543879BF-E2CD-6521-8322-8FBCD6EC57A0} = {41AC66EE-B656-4CDF-A512-C7259C2F6CF7}
1592-
{B16AC373-3DA8-4505-9510-110347CD635D} = {5D4C0700-BBB5-418F-A7B2-F392B9A18263}
15931592
{BEDAC050-016A-46F4-9173-339C46DFD3ED} = {5D4C0700-BBB5-418F-A7B2-F392B9A18263}
15941593
{0C81C377-3CDC-46A8-BED1-4B50BDA2202E} = {D6D598DF-C17C-46F4-B2B9-CDE82E2DE132}
15951594
{A5E6193C-8431-4C6E-B674-682CB41EAA0C} = {4F381919-F1BE-47D8-8558-3187ED04A84F}
15961595
{E9A74E0C-BC02-4DDD-A487-89847EDF8026} = {4F381919-F1BE-47D8-8558-3187ED04A84F}
1596+
{801C9CE4-53AF-D2DB-E0D6-9A6BB47E9654} = {5D4C0700-BBB5-418F-A7B2-F392B9A18263}
15971597
EndGlobalSection
15981598
GlobalSection(ExtensibilityGlobals) = postSolution
15991599
SolutionGuid = {FBDC56A3-86AD-4323-AA0F-201E59123B83}

dotnet/samples/Demos/AgentFrameworkWithAspire/ChatWithAgent.AppHost/Properties/launchSettings.json

-29
This file was deleted.

dotnet/samples/Demos/ModelContextProtocol/McpDotNetExtensions.cs

-159
This file was deleted.

dotnet/samples/Demos/ModelContextProtocol/ModelContextProtocol.csproj renamed to dotnet/samples/Demos/ModelContextProtocolPlugin/ModelContextProtocolPlugin.csproj

+2-8
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,17 @@
66
<ImplicitUsings>enable</ImplicitUsings>
77
<Nullable>enable</Nullable>
88
<UserSecretsId>5ee045b0-aea3-4f08-8d31-32d1a6f8fed0</UserSecretsId>
9-
<NoWarn>$(NoWarn);CA2249;CS0612</NoWarn>
9+
<NoWarn>$(NoWarn);CA2249;CS0612;SKEXP0001;VSTHRD111;CA2007</NoWarn>
1010
</PropertyGroup>
1111

1212
<ItemGroup>
13-
<PackageReference Include="mcpdotnet" />
13+
<PackageReference Include="ModelContextProtocol" />
1414
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" />
1515
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" />
1616
<PackageReference Include="Microsoft.Extensions.Logging" />
1717
<PackageReference Include="Microsoft.Extensions.Logging.Console" />
1818
<PackageReference Include="Microsoft.Extensions.Logging.Debug" />
1919
</ItemGroup>
20-
21-
<ItemGroup>
22-
<None Update="SimpleToolsConsole.json">
23-
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
24-
</None>
25-
</ItemGroup>
2620

2721
<ItemGroup>
2822
<ProjectReference Include="..\..\..\src\Connectors\Connectors.AzureOpenAI\Connectors.AzureOpenAI.csproj" />

dotnet/samples/Demos/ModelContextProtocol/Program.cs renamed to dotnet/samples/Demos/ModelContextProtocolPlugin/Program.cs

+28-22
Original file line numberDiff line numberDiff line change
@@ -5,48 +5,54 @@
55
using Microsoft.Extensions.Logging;
66
using Microsoft.SemanticKernel;
77
using Microsoft.SemanticKernel.Connectors.OpenAI;
8-
using ModelContextProtocol;
8+
using ModelContextProtocol.Client;
99

1010
var config = new ConfigurationBuilder()
1111
.AddUserSecrets<Program>()
1212
.AddEnvironmentVariables()
1313
.Build();
1414

15-
// Prepare and build kernel
16-
var builder = Kernel.CreateBuilder();
17-
builder.Services.AddLogging(c => c.AddDebug().SetMinimumLevel(Microsoft.Extensions.Logging.LogLevel.Trace));
18-
19-
if (config["OpenAI:ApiKey"] is not null)
20-
{
21-
builder.Services.AddOpenAIChatCompletion(
22-
serviceId: "openai",
23-
modelId: config["OpenAI:ChatModelId"] ?? "gpt-4o",
24-
apiKey: config["OpenAI:ApiKey"]!);
25-
}
26-
else
15+
if (config["OpenAI:ApiKey"] is not { } apiKey)
2716
{
2817
Console.Error.WriteLine("Please provide a valid OpenAI:ApiKey to run this sample. See the associated README.md for more details.");
2918
return;
3019
}
3120

32-
Kernel kernel = builder.Build();
33-
3421
// Create an MCPClient for the GitHub server
35-
var mcpClient = await McpDotNetExtensions.GetGitHubToolsAsync().ConfigureAwait(false);
22+
await using var mcpClient = await McpClientFactory.CreateAsync(
23+
new()
24+
{
25+
Id = "github",
26+
Name = "GitHub",
27+
TransportType = "stdio",
28+
TransportOptions = new Dictionary<string, string>
29+
{
30+
["command"] = "npx",
31+
["arguments"] = "-y @modelcontextprotocol/server-github",
32+
}
33+
},
34+
new() { ClientInfo = new() { Name = "GitHub", Version = "1.0.0" } }).ConfigureAwait(false);
3635

3736
// Retrieve the list of tools available on the GitHub server
38-
var tools = await mcpClient.ListToolsAsync().ConfigureAwait(false);
39-
foreach (var tool in tools.Tools)
37+
var tools = await mcpClient.GetAIFunctionsAsync().ConfigureAwait(false);
38+
foreach (var tool in tools)
4039
{
4140
Console.WriteLine($"{tool.Name}: {tool.Description}");
4241
}
4342

44-
// Add the MCP tools as Kernel functions
45-
var functions = await mcpClient.MapToFunctionsAsync().ConfigureAwait(false);
46-
kernel.Plugins.AddFromFunctions("GitHub", functions);
43+
// Prepare and build kernel with the MCP tools as Kernel functions
44+
var builder = Kernel.CreateBuilder();
45+
builder.Services
46+
.AddLogging(c => c.AddDebug().SetMinimumLevel(Microsoft.Extensions.Logging.LogLevel.Trace))
47+
.AddOpenAIChatCompletion(
48+
serviceId: "openai",
49+
modelId: config["OpenAI:ChatModelId"] ?? "gpt-4o-mini",
50+
apiKey: apiKey);
51+
Kernel kernel = builder.Build();
52+
kernel.Plugins.AddFromFunctions("GitHub", tools.Select(aiFunction => aiFunction.AsKernelFunction()));
4753

4854
// Enable automatic function calling
49-
var executionSettings = new OpenAIPromptExecutionSettings
55+
OpenAIPromptExecutionSettings executionSettings = new()
5056
{
5157
Temperature = 0,
5258
FunctionChoiceBehavior = FunctionChoiceBehavior.Auto()

dotnet/samples/Demos/ModelContextProtocol/README.md renamed to dotnet/samples/Demos/ModelContextProtocolPlugin/README.md

+6-4
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,17 @@ MCP is an open protocol that standardizes how applications provide context to LL
66

77
For information on Model Context Protocol (MCP) please refer to the [documentation](https://modelcontextprotocol.io/introduction).
88

9-
This sample uses [mcpdotnet](https://www.nuget.org/packages/mcpdotnet) and is heavily influenced by the [samples](https://github.com/PederHP/mcpdotnet/tree/main/samples) from that repository.
10-
119
The sample shows:
1210

13-
1. How to connect to an MCP Server using [mcpdotnet](https://www.nuget.org/packages/mcpdotnet)
11+
1. How to connect to an MCP Server using [ModelContextProtocol](https://www.nuget.org/packages/ModelContextProtocol)
1412
2. Retrieve the list of tools the MCP Server makes available
1513
3. Convert the MCP tools to Semantic Kernel functions so they can be added to a Kernel instance
1614
4. Invoke the tools from Semantic Kernel using function calling
1715

16+
## Installing Prerequisites
17+
18+
The sample requires node.js and npm to be installed. So, please install them from [here](https://nodejs.org/en/download/).
19+
1820
## Configuring Secrets or Environment Variables
1921

2022
The example require credentials to access OpenAI.
@@ -24,7 +26,7 @@ If you have set up those credentials as secrets within Secret Manager or through
2426
### To set your secrets with Secret Manager
2527

2628
```text
27-
cd dotnet/samples/Demos/ModelContextProtocol
29+
cd dotnet/samples/Demos/ModelContextProtocolPlugin
2830
2931
dotnet user-secrets init
3032

0 commit comments

Comments
 (0)