MCP with Semantic Kernel - thangchung/mcp-labs GitHub Wiki
MCP with Semantic Kernel
# server part
dotnet new console -n MCPPredictor.Server
cd MCPPredictor.Server
dotnet add package ModelContextProtocol
// server codeusingModelContextProtocol;awaitMCPServer.StartAsync("MCPPredictor","1");[McpTool("getTrendingAI","Return top trending AI topics from Bing search")]publicstaticclassTrendingTool{publicstaticstringGetTrendingAI()=>"Semantic Kernel, MCP, .NET AI";}
# client part
dotnet new console -n MCPPredictor.Client
cd MCPPredictor.Client
dotnet add package ModelContextProtocol.Client
dotnet add package Microsoft.SemanticKernel
// client codeusingModelContextProtocol.Client;usingMicrosoft.SemanticKernel;varclient=newMCPClient("MCPPredictor","1");varkernel=Kernel.CreateBuilder().AddAzureOpenAIChatCompletion("gpt-4o-mini","<endpoint>","<api-key>").Build();vartool=client.ToKernelFunction("getTrendingAI");varresult=awaitkernel.RunAsync(tool);Console.WriteLine("AI Prediction based on trends: "+result.GetValue<string>());
List of extensions method to map MCP server functions with SK plugins and vice versa