﻿
{"id":27751,"date":"2025-04-22T20:50:41","date_gmt":"2025-04-22T20:50:41","guid":{"rendered":"https:\/\/www.gencayyildiz.com\/blog\/?p=27751"},"modified":"2025-04-22T20:50:41","modified_gmt":"2025-04-22T20:50:41","slug":"model-context-protocol-mcpunun-semantic-kernel-ile-birlikte-kullanimi","status":"publish","type":"post","link":"https:\/\/www.gencayyildiz.com\/blog\/model-context-protocol-mcpunun-semantic-kernel-ile-birlikte-kullanimi\/","title":{"rendered":"Model Context Protocol (MCP)&#8217;\u00fcn\u00fcn Semantic Kernel \u0130le Birlikte Kullan\u0131m\u0131"},"content":{"rendered":"<div id=\"fb-root\"><\/div>\n<p>Merhaba,<\/p>\n<p>Bir \u00f6nceki <a href=\"https:\/\/www.gencayyildiz.com\/blog\/model-context-protocol-mcp-nedir-derinlemesine-degerlendirelim\/\" target=\"_blank\">Model Context Protocol (MCP) Nedir? Derinlemesine De\u011ferlendirelim\u2026<\/a> ba\u015fl\u0131kl\u0131 i\u00e7eri\u011fimizde MCP&#8217;ye dair tam teferruatl\u0131 bir incelemede bulunmu\u015f ve \u00f6zelle\u015ftirilmi\u015f MCP Server&#8217;lar e\u015fli\u011finde MCP Client&#8217;lar\u0131n nas\u0131l olu\u015fturulabilece\u011fini ele alm\u0131\u015ft\u0131k. Bu i\u00e7eri\u011fimizde ise <a href=\"https:\/\/www.gencayyildiz.com\/blog\/semantic-kernel-nedir-deepseek-r1-esliginde-net-acisindan-derinlemesine-degerlendirelim\/\" target=\"_blank\">Semantic Kernel<\/a> ile birlikte MCP protokol\u00fcn\u00fcn birlikte nas\u0131l kullan\u0131labilece\u011fini inceleyecek ve AI modelleriyle birebir ileti\u015fim s\u00fcre\u00e7lerine odakl\u0131 bir seyri deneyimliyor olaca\u011f\u0131z. O halde buyurun ba\u015flayal\u0131m&#8230;<\/p>\n<h4>Neden Semantic Kernel \u0130le MCP&#8217;yi Birlikte Kullanmal\u0131y\u0131z?<\/h4>\n<p>Biliyorsunuz ki Semantic Kernel, AI modelleri ile uygulamalar aras\u0131nda ba\u011flant\u0131 kurmay\u0131 kolayla\u015ft\u0131ran bir ara\u00e7 tak\u0131m\u0131d\u0131r. MCP ise bir AI modelinin ba\u011flam\u0131n\u0131 y\u00f6netmek ve girdileri-\u00e7\u0131kt\u0131lar\u0131 standardize etmek i\u00e7in tasarlanm\u0131\u015f bir protokold\u00fcr. Ee haliyle her ikisini bir araya getirerek k\u00fcm\u00fclatif bir i\u015flev ortaya koyulabilir ve Semantic Kernel ile AI modelleri uygulamaya entegre edilirken, MCP ile de bu entegrasyon neticesinde i\u015flevsellik g\u00f6sterecek olan AI modellerinin ba\u011flamlar\u0131na hem standart bir \u015fekilde m\u00fcdahale edilebilir hem de di\u011fer uygulamalar ve AI modelleriyle bu ba\u011flam\u0131n payla\u015f\u0131lmas\u0131 s\u00f6z konusu olabilir. Bunlar\u0131n yan\u0131nda AI modellerine gelen prompt&#8217;lar neticesinde \u00e7a\u011fr\u0131lacak olan tool&#8217;lara dair loglar tutulabilir, trace ve metric i\u015flemleri yap\u0131land\u0131r\u0131labilir ve bunlar kolayca monitoring edilebilir.<\/p>\n<h4>SK ile MCP&#8217;yi Birlikte Nas\u0131l Kullanabiliriz?<\/h4>\n<p><a href=\"https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2025\/04\/Model-Context-Protocol-MCPunun-Semantic-Kernel-Ile-Birlikte-Kullanimi.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2025\/04\/Model-Context-Protocol-MCPunun-Semantic-Kernel-Ile-Birlikte-Kullanimi.png\" alt=\"Model Context Protocol (MCP)&#039;\u00fcn\u00fcn Semantic Kernel \u0130le Birlikte Kullan\u0131m\u0131\" width=\"782\" height=\"529\" class=\"aligncenter size-full wp-image-27759\" srcset=\"https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2025\/04\/Model-Context-Protocol-MCPunun-Semantic-Kernel-Ile-Birlikte-Kullanimi.png 782w, https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2025\/04\/Model-Context-Protocol-MCPunun-Semantic-Kernel-Ile-Birlikte-Kullanimi-300x203.png 300w, https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2025\/04\/Model-Context-Protocol-MCPunun-Semantic-Kernel-Ile-Birlikte-Kullanimi-768x520.png 768w\" sizes=\"auto, (max-width: 782px) 100vw, 782px\" \/><\/a>Semantic Kernel ile MCP, birbirlerine \u00e7ift y\u00f6nl\u00fc i\u015flevsellik kazand\u0131rabilecek \u015fekilde kullan\u0131labilmektedir. \u015e\u00f6yle ki, Semantic Kernel&#8217;\u0131n i\u015flevsellikleri olan <em>Plugin<\/em> ve <em>Function<\/em>&#8216;lar MCP&#8217;ye tool olarak aktar\u0131labilir. Benzer mant\u0131kla MCP&#8217;de ki tool&#8217;lar da Semantic Kernel&#8217;a <em>Plugin<\/em> ve <em>Function<\/em> olarak yans\u0131t\u0131labilir. Bu \u00e7ift y\u00f6nl\u00fc kullan\u0131m bizlere daha b\u00fct\u00fcnc\u00fcl bir i\u015flevsellik kazand\u0131racakt\u0131r. <em>Nas\u0131l m\u0131?<\/em> diye sordu\u011funuzu duyar gibiyim&#8230; Hemen izah edelim; Semantic Kernel&#8217;da tan\u0131ml\u0131 olan bir <em>Plugin<\/em>&#8216;i herhangi bir MCP Server&#8217;a tool olarak aktarabilirsek bu durum, sistemdeki di\u011fer AI modellerinin de bu plugin&#8217;den istifade etmesine zemin haz\u0131rlayacakt\u0131r. Ayn\u0131 \u015fekilde MCP&#8217;de ki bir tool&#8217;u Semantic Kernel&#8217;a <em>Plugin<\/em> olarak ekledi\u011fimizde de bu tool AI modelleriyle olan i\u015f ak\u0131\u015flar\u0131 s\u00fcre\u00e7lerinde Semantic Kernel taraf\u0131ndan kullan\u0131labilir olacakt\u0131r.<\/p>\n<p>\u015eimdi gelin bu \u00e7ift y\u00f6nl\u00fc ak\u0131\u015f\u0131n her ikisini de yap\u0131land\u0131rma ve i\u015flevsellik a\u00e7\u0131s\u0131ndan de\u011ferlendirelim. Bunun i\u00e7in \u00f6ncelikle <code>MCP.Client<\/code> ve <code>MCP.Server<\/code> ad\u0131nda iki adet proje olu\u015ftural\u0131m ve bu projelere gerekli olan k\u00fct\u00fcphaneleri y\u00fckleyerek haz\u0131r bir altyap\u0131 sa\u011flayal\u0131m. Tabi bu \u00e7al\u0131\u015fmada Semantic Kernel ile ilgili yap\u0131land\u0131rmalar\u0131 <code>MCP.Client<\/code> projesinde yapaca\u011f\u0131m\u0131z a\u015fikar olsa gerek. Bundan kaynakl\u0131, s\u00fcreci daha efektif test edebilmek i\u00e7in bu projenin \u00f6zellikle Asp.NET Core olmas\u0131na \u00f6zen g\u00f6sterelim.<\/p>\n<p>Ayr\u0131ca, MCP&#8217;nin AI modeli ile MCP Server&#8217;lar aras\u0131ndaki context payla\u015f\u0131m\u0131n\u0131 tecr\u00fcbe edebilmek ve bir yandan da bu s\u00fcrecin Semantic Kernel ile daha da efektif k\u0131l\u0131nabildi\u011fini deneyimlemek i\u00e7in uygulamaya OpenRouter platformu \u00fczerinden bir adet AI modeli(<code>google\/gemini-2.0-flash-exp:free<\/code>) entegre edelim.<\/p>\n<div style=\"color:red;text-align:center;border:1px;border-style:dotted;font-size:12px;\">Burada kesinlikle unutulmamas\u0131 gereken bir husus vard\u0131r ki, o da, kullan\u0131lacak olan AI modelinin tools\/plugin deste\u011finin olmas\u0131d\u0131r. Aksi taktirde i\u00e7erik s\u00fcrecinde odak konu olarak yap\u0131land\u0131r\u0131lan \u00e7al\u0131\u015fmalardan hi\u00e7bir \u015fekilde netice al\u0131namayacakt\u0131r.<\/div>\n<p><\/p>\n<p><em>MCP.Client<\/em> uygulamas\u0131nda Semantic Kernel yap\u0131land\u0131rmas\u0131 a\u015fa\u011f\u0131daki gibi olacakt\u0131r;<\/p>\n<div style=\"font-size:12px;\">\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\nusing Microsoft.SemanticKernel;\r\nusing Microsoft.SemanticKernel.ChatCompletion;\r\nusing OpenAI;\r\nusing System.ClientModel;\r\n\r\nvar builder = WebApplication.CreateBuilder(args);\r\n\r\nbuilder.Services\r\n    .AddKernel()\r\n    .AddOpenAIChatCompletion(\r\n        modelId: &quot;google\/gemini-2.0-flash-exp:free&quot;,\r\n        openAIClient: new OpenAIClient(\r\n                credential: new ApiKeyCredential(&quot;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&quot;),\r\n                options: new OpenAIClientOptions\r\n                {\r\n                    Endpoint = new Uri(&quot;https:\/\/openrouter.ai\/api\/v1&quot;)\r\n                }\r\n            )\r\n    );\r\n\r\nvar app = builder.Build();\r\n\r\n.\r\n.\r\n.\r\n\r\napp.Run();\r\n\r\n<\/pre>\n<\/div>\n<p>Benzer mant\u0131kla yine ayn\u0131 uygulama bir yandan MCP Host olaca\u011f\u0131ndan dolay\u0131, \u00f6zel olarak MCP Client olu\u015fturmam\u0131z\u0131 sa\u011flayacak olan yap\u0131land\u0131rma a\u015fa\u011f\u0131daki gibi olabilir;<\/p>\n<div style=\"font-size:12px;\">\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n    public class GoogleGeminiAIMCPClient(string MCPServerName, string MCPServerPath)\r\n    {\r\n        private IMcpClient _mcpClient;\r\n        public async Task&lt;IMcpClient&gt; GetClientAsync()\r\n        {\r\n            if (_mcpClient == null)\r\n                _mcpClient = await McpClientFactory.CreateAsync(\r\n                         clientTransport: new StdioClientTransport(new()\r\n                         {\r\n                             Name = MCPServerName,\r\n                             Command = MCPServerPath\r\n                         }),\r\n                         clientOptions: new McpClientOptions()\r\n                         {\r\n                             ClientInfo = new Implementation()\r\n                             {\r\n                                 Name = &quot;Google.Gemini.AI.MCP.Client&quot;,\r\n                                 Version = &quot;1.0.0&quot;\r\n                             }\r\n                         }\r\n                     );\r\n\r\n            return _mcpClient;\r\n        }\r\n\r\n        public async Task&lt;IList&lt;McpClientTool&gt;&gt; GetToolListAsync()\r\n        {\r\n            _mcpClient = await GetClientAsync();\r\n            IList&lt;McpClientTool&gt; tools = await _mcpClient.ListToolsAsync();\r\n            return tools;\r\n        }\r\n\r\n        public async Task&lt;object&gt; CallToolAsync(string toolName, Dictionary&lt;string, object?&gt; input)\r\n        {\r\n            _mcpClient = await GetClientAsync();\r\n            CallToolResponse response = await _mcpClient.CallToolAsync(\r\n                       toolName,\r\n                       input\r\n                       );\r\n            return response.Content.First(c =&gt; c.Type == &quot;text&quot;).Text;\r\n        }\r\n    }\r\n<\/pre>\n<\/div>\n<p>Bak\u0131n! olabilir diyorum \u00e7\u00fcnk\u00fc buradaki \u00e7al\u0131\u015fman\u0131n usul\u00fc ve yakla\u015f\u0131m\u0131 sizlere kalm\u0131\u015ft\u0131r. Malum, bir MCP Host i\u00e7erisinde birden fazla MCP Client olu\u015fturulabilir ve bu client&#8217;lar\u0131n her biri farkl\u0131 MCP Server&#8217;larla ba\u011flant\u0131 kurabilir. \u015e\u00f6yle ki; A modelinde kullan\u0131lacak MCP Server&#8217;lar O, R ve P iken, B modelinde kullan\u0131lacak olanlar \u00c7, C, \u011e olabilir. Bunlar\u0131n her birinin yap\u0131land\u0131r\u0131lmas\u0131 ve y\u00f6netimi i\u00e7in bu MCP Host uygulamas\u0131nda birer MCP Client nesnesi olu\u015fturulmas\u0131 gerekecektir. \u0130\u015fte bu tarz bir ihtiyaca kar\u015f\u0131n bu tarz hususi s\u0131n\u0131flar geli\u015ftirebilir ya da daha farkl\u0131 ve daha g\u00fczel \u00e7\u00f6z\u00fcmler \u00fcretebilirsiniz.<\/p>\n<p>Ve haz\u0131rl\u0131k a\u015famas\u0131n\u0131n sonuncu hamlesi olarak <em>MCP.Server<\/em> uygulamas\u0131n\u0131 da a\u015fa\u011f\u0131daki gibi \u00f6rnek tool e\u015fli\u011finde olu\u015fturabilirsiniz;<\/p>\n<div style=\"font-size:12px;\">\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\nusing Microsoft.Extensions.DependencyInjection;\r\nusing Microsoft.Extensions.Hosting;\r\nusing Microsoft.Extensions.Logging;\r\nusing Serilog;\r\n\r\nLog.Logger = new LoggerConfiguration()\r\n    .MinimumLevel.Verbose()\r\n    .WriteTo.File(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, &quot;logs&quot;, &quot;MCP.Server.Log&quot;))\r\n    .WriteTo.Debug()\r\n    .WriteTo.Console()\r\n    .CreateLogger();\r\n\r\nLog.Information(&quot;Server ba\u015flat\u0131l\u0131yor...&quot;);\r\n\r\nvar builder = Host.CreateApplicationBuilder(args);\r\nbuilder.Logging.AddConsole(consoleLogOptions =&gt;\r\n{\r\n    consoleLogOptions.LogToStandardErrorThreshold = LogLevel.Trace;\r\n});\r\nbuilder.Services.AddHttpClient();\r\n\r\nbuilder.Services\r\n    .AddMcpServer()\r\n    .WithStdioServerTransport()\r\n    .WithToolsFromAssembly();\r\n\r\nawait builder.Build().RunAsync();\r\n<\/pre>\n<\/div>\n<div style=\"font-size:12px;\">\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n    &#x5B;McpServerToolType]\r\n    public class UserTool(IHttpClientFactory httpClientFactory)\r\n    {\r\n        &#x5B;McpServerTool, Description(&quot;T\u00fcm kullan\u0131c\u0131lar\u0131, bilgileriyle birlikte getirir.&quot;)]\r\n        public async Task&lt;List&lt;object&gt;&gt; GetUsersAsync()\r\n        {\r\n            Log.Information(&quot;JSONPlaceholder'dan kullan\u0131c\u0131 bilgileri \u00e7ekiliyor...&quot;);\r\n\r\n            HttpClient httpClient = httpClientFactory.CreateClient();\r\n            HttpResponseMessage httpResponseMessage = await httpClient.GetAsync(&quot;https:\/\/jsonplaceholder.typicode.com\/users&quot;);\r\n            string jsonData = await httpResponseMessage.Content.ReadAsStringAsync();\r\n\r\n            JsonDocument document = JsonDocument.Parse(jsonData);\r\n            JsonElement root = document.RootElement;\r\n\r\n            List&lt;object&gt; usersData = new();\r\n\r\n            foreach (JsonElement element in root.EnumerateArray())\r\n            {\r\n                usersData.Add(new\r\n                {\r\n                    Id = element.GetProperty(&quot;id&quot;).GetInt32(),\r\n                    Name = element.GetProperty(&quot;name&quot;).GetString(),\r\n                    Username = element.GetProperty(&quot;username&quot;).GetString(),\r\n                    Email = element.GetProperty(&quot;email&quot;).GetString()\r\n                });\r\n            }\r\n\r\n            Log.Information(&quot;JSONPlaceholder'dan kullan\u0131c\u0131 bilgileri \u00e7ekildi...&quot;);\r\n            return usersData;\r\n        }\r\n    }\r\n<\/pre>\n<\/div>\n<p>Evet, g\u00f6r\u00fcld\u00fc\u011f\u00fc \u00fczere burada \u00f6rnek olarak JSONPlaceholder&#8217;dan t\u00fcm kullan\u0131c\u0131lar\u0131 \u00e7eken &#8216;GetUsers&#8217; tool&#8217;unu olu\u015fturmu\u015f bulunuyorum. Burada tool&#8217;un ad\u0131, i\u015flevsel olarak asenkron s\u00fcre\u00e7 bar\u0131nd\u0131rd\u0131\u011f\u0131ndan dolay\u0131 yaz\u0131l\u0131m gelene\u011fi icab\u0131 <em>&#8216;&#8230;Async&#8217;<\/em> \u015feklinde bitiyor olabilir, ancak yine de bu tool client a\u00e7\u0131s\u0131ndan &#8216;GetUsers&#8217; \u015feklinde de\u011ferlendirilecektir. Bu temel yap\u0131land\u0131rmalardan sonra art\u0131k i\u00e7eri\u011fimizin esas konusuna odaklanabilir ve Semantic Kernel e\u015fli\u011finde MCP manevralar\u0131na ba\u015flayabiliriz \ud83d\ude42<\/p>\n<h5>MCP&#8217;den SK&#8217;ya Tool Aktar\u0131m\u0131 Kullan\u0131m\u0131<\/h5>\n<p>\u0130lk olarak MCP Server&#8217;lar\u0131ndaki yeteneklerin Semantic Kernel&#8217;a aktar\u0131m\u0131n\u0131 ele alaca\u011f\u0131z. Bunun i\u00e7in a\u015fa\u011f\u0131daki gibi, yukar\u0131da olu\u015fturdu\u011fumuz <code>GoogleGeminiAIMCPClient<\/code> s\u0131n\u0131f\u0131 \u00fczerinden bir instance olu\u015fturmal\u0131 ve bu MCP Client&#8217;a ba\u011fl\u0131 olan MCP Server&#8217;dan tool&#8217;lar\u0131 elde edip, Semantic Kernel yap\u0131land\u0131rmas\u0131na plugin olarak tan\u0131mlamal\u0131y\u0131z;<\/p>\n<div style=\"font-size:12px;\">\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n.\r\n.\r\n.\r\nGoogleGeminiAIMCPClient mcpClient = new(&quot;MCP.Server&quot;, Path.Combine(&quot;..&quot;, &quot;MCP.Server&quot;, &quot;bin&quot;, &quot;Debug&quot;, &quot;net9.0&quot;, &quot;MCP.Server.exe&quot;));\r\nIList&lt;McpClientTool&gt; tools = await mcpClient.GetToolListAsync();\r\n\r\nbuilder.Services\r\n    .AddKernel()\r\n    .AddOpenAIChatCompletion(\r\n        modelId: &quot;google\/gemini-2.0-flash-exp:free&quot;,\r\n        openAIClient: new OpenAIClient(\r\n                credential: new ApiKeyCredential(&quot;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&quot;),\r\n                options: new OpenAIClientOptions\r\n                {\r\n                    Endpoint = new Uri(&quot;https:\/\/openrouter.ai\/api\/v1&quot;),\r\n                }\r\n            )\r\n    )\r\n    .Plugins.AddFromFunctions(&quot;UserTool&quot;, tools.Select(_tool =&gt; _tool.AsKernelFunction()));\r\n.\r\n.\r\n.\r\n<\/pre>\n<\/div>\n<p>Yapt\u0131\u011f\u0131m\u0131z \u00e7al\u0131\u015fmaya g\u00f6z atarsan\u0131z e\u011fer MCP Server&#8217;dan gelen tool&#8217;lar\u0131 SK&#8217;ya plugin olarak verirken <code>.Plugins.AddFromFunctions<\/code> komutu \u00fczerinden yap\u0131land\u0131rma ger\u00e7ekle\u015ftirmekteyiz. Ayr\u0131ca, bu tool&#8217;lar\u0131 plugin olarak kullan\u0131labilir hale getirmek i\u00e7in <code>AsKernelFunction<\/code> metoduyla Semantic Kernel&#8217;\u0131n plugin yap\u0131lanmas\u0131na uygun function haline getirmekteyiz ve bu vaziyette <code>Plugins<\/code> property&#8217;si i\u00e7erisine eklemekteyiz.<\/p>\n<p>\u015eimdi yap\u0131lan bu \u00e7al\u0131\u015fma neticesinde a\u015fa\u011f\u0131daki gibi otomatik plugin&#8217;i devreye sokacak \u015fekilde yap\u0131land\u0131r\u0131lm\u0131\u015f olarak AI modele bir prompt g\u00f6nderelim ve neticeyi g\u00f6zlemleyelim.<\/p>\n<div style=\"font-size:12px;\">\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n.\r\n.\r\n.\r\napp.MapGet(&quot;\/&quot;, async (IChatCompletionService chatCompletionService, Kernel kernel) =&gt;\r\n{\r\n    ChatMessageContent content = await chatCompletionService.GetChatMessageContentAsync(\r\n        prompt: &quot;T\u00fcm kullan\u0131c\u0131lar\u0131 getir? Ka\u00e7 adet olduklar\u0131n\u0131, username ve email bilgilerini '&#x5B;username | email]' format\u0131nda yazman\u0131 istiyorum. Ayr\u0131ca s\u0131ralamay\u0131 username'e g\u00f6re alfabetik olarak tersine yapman\u0131 istiyorum. Ard\u0131ndan, ---------- \u00e7izgi ile sayfay\u0131 ay\u0131r ve \u015fu dediklerimi yap: bir \u015firket senaryosunda gibi davranman\u0131 ve bu kullan\u0131c\u0131lardan 2 tanesini bu \u015firkette m\u00fcd\u00fcr olarak se\u00e7meni ve di\u011ferlerine de kendine g\u00f6re belirledi\u011fin senaryolarda farkl\u0131 g\u00f6revler atayarak bu y\u00f6neticiler alt\u0131nda payla\u015ft\u0131rman\u0131 istiyorum. M\u0131\u015f gibi yapacak ve bir hikaye \u00e7izeceksin anlayaca\u011f\u0131n.&quot;,\r\n        executionSettings: new OpenAIPromptExecutionSettings()\r\n        {\r\n            FunctionChoiceBehavior = FunctionChoiceBehavior.Auto(options: new() { }),\r\n        },\r\n        kernel: kernel);\r\n\r\n    return content.Content.ToString();\r\n});\r\n<\/pre>\n<\/div>\n<p><a href=\"https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2025\/04\/Model-Context-Protocol-MCPunun-Semantic-Kernel-Ile-Birlikte-Kullanimi-1.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2025\/04\/Model-Context-Protocol-MCPunun-Semantic-Kernel-Ile-Birlikte-Kullanimi-1.png\" alt=\"Model Context Protocol (MCP)&#039;\u00fcn\u00fcn Semantic Kernel \u0130le Birlikte Kullan\u0131m\u0131\" width=\"1872\" height=\"865\" class=\"aligncenter size-full wp-image-27764\" srcset=\"https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2025\/04\/Model-Context-Protocol-MCPunun-Semantic-Kernel-Ile-Birlikte-Kullanimi-1.png 1872w, https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2025\/04\/Model-Context-Protocol-MCPunun-Semantic-Kernel-Ile-Birlikte-Kullanimi-1-300x139.png 300w, https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2025\/04\/Model-Context-Protocol-MCPunun-Semantic-Kernel-Ile-Birlikte-Kullanimi-1-1024x473.png 1024w, https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2025\/04\/Model-Context-Protocol-MCPunun-Semantic-Kernel-Ile-Birlikte-Kullanimi-1-768x355.png 768w, https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2025\/04\/Model-Context-Protocol-MCPunun-Semantic-Kernel-Ile-Birlikte-Kullanimi-1-1536x710.png 1536w\" sizes=\"auto, (max-width: 1872px) 100vw, 1872px\" \/><\/a>G\u00f6r\u00fcld\u00fc\u011f\u00fc \u00fczere AI modele g\u00f6nderdi\u011fimiz prompt&#8217;un mahiyetine g\u00f6re MCP Server&#8217;daki tool tetiklenerek veriler elde edilmi\u015f ve istedi\u011fimiz \u015fekilde d\u00fczenlenip cevap taraf\u0131m\u0131za sunulmu\u015ftur.<\/p>\n<p>MCP Server&#8217;lardaki yetenekler Semantic Kernel&#8217;a bu kadar basit bir \u015fekilde aktar\u0131lmaktad\u0131r. \u015eimdi gelin, Semantic Kernel&#8217;dan MCP Server&#8217;a yetenek aktar\u0131m\u0131n\u0131 inceleyelim&#8230;<\/p>\n<h5>SK&#8217;dan MCP&#8217;ye Plugin Aktar\u0131m\u0131 ve Kullan\u0131m\u0131<\/h5>\n<p>Kimi zaman, Semantic Kernel ile AI entegrasyonu yaparak geli\u015ftirdi\u011fimiz uygulaman\u0131n bir yandan da farkl\u0131 bir MCP Client uygulamas\u0131 taraf\u0131ndan MCP Server olarak kullan\u0131lmas\u0131 s\u00f6z konusu olabilir. \u0130\u015fte b\u00f6yle durumlarda, Semantic Kernel&#8217;\u0131n yeteneklerini de MCP Server&#8217;a aktarmam\u0131z gerekebilir. Bunun i\u00e7in \u015f\u00f6yle bir \u00e7al\u0131\u015fman\u0131n yap\u0131lmas\u0131 yeterli olacakt\u0131r;<\/p>\n<p>Tabi ilk olarak a\u015fa\u011f\u0131daki gibi Semantic Kernel plugin&#8217;i oldu\u011funu varsayal\u0131m;<\/p>\n<div style=\"font-size:12px;\">\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n    public sealed class TodoPlugin(IHttpClientFactory httpClientFactory)\r\n    {\r\n        &#x5B;KernelFunction, Description(&quot;Kullan\u0131c\u0131lara dair yap\u0131lacaklar listesini ve durumlar\u0131n\u0131 getirir.&quot;)]\r\n        public async Task&lt;List&lt;object&gt;&gt; GetTodoListAsync()\r\n        {\r\n            Log.Information(&quot;Yap\u0131lacaklar listesi \u00e7ekiliyor...&quot;);\r\n\r\n            HttpClient httpClient = httpClientFactory.CreateClient();\r\n            HttpResponseMessage httpResponseMessage = await httpClient.GetAsync(&quot;https:\/\/jsonplaceholder.typicode.com\/todos&quot;);\r\n            string jsonData = await httpResponseMessage.Content.ReadAsStringAsync();\r\n\r\n            JsonDocument document = JsonDocument.Parse(jsonData);\r\n            JsonElement root = document.RootElement;\r\n\r\n            List&lt;object&gt; usersData = new();\r\n\r\n            foreach (JsonElement element in root.EnumerateArray())\r\n            {\r\n                usersData.Add(new\r\n                {\r\n                    UserId = element.GetProperty(&quot;userId&quot;).GetInt32(),\r\n                    Id = element.GetProperty(&quot;id&quot;).GetInt32(),\r\n                    Title = element.GetProperty(&quot;title&quot;).GetString(),\r\n                    Completed = element.GetProperty(&quot;completed&quot;).GetBoolean()\r\n                });\r\n            }\r\n\r\n            Log.Information(&quot;Yap\u0131lacaklar listesi \u00e7ekildi...&quot;);\r\n            return usersData;\r\n        }\r\n    }\r\n<\/pre>\n<\/div>\n<p>Ard\u0131ndan bu plugin&#8217;i a\u015fa\u011f\u0131daki gibi Semantic Kernel ile yap\u0131land\u0131r\u0131p bir yandan da MCP Server&#8217;a yans\u0131tabiliriz;<\/p>\n<div style=\"font-size:12px;\">\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\nLog.Logger = new LoggerConfiguration()\r\n    .MinimumLevel.Verbose()\r\n    .WriteTo.File(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, &quot;logs&quot;, &quot;MCP.Server.Log&quot;))\r\n    .WriteTo.Debug()\r\n    .WriteTo.Console()\r\n    .CreateLogger();\r\n\r\nLog.Information(&quot;Server ba\u015flat\u0131l\u0131yor...&quot;);\r\n\r\nvar builder = Host.CreateApplicationBuilder(args);\r\n\r\nbuilder.Services\r\n.AddKernel()\r\n.Plugins.AddFromType&lt;TodoPlugin&gt;();\r\n\r\nbuilder.Services.AddHttpClient();\r\n\r\nbuilder.Services\r\n    .AddMcpServer()\r\n    .WithStdioServerTransport()\r\n    .WithToolsFromAssembly()\r\n    .WithTools(builder.Services.BuildServiceProvider().GetService&lt;Kernel&gt;().Plugins);\r\n\r\nawait builder.Build().RunAsync();\r\n<\/pre>\n<\/div>\n<p>Burada bizim i\u00e7in 22. sat\u0131r \u00f6nem arz etmektedir. Bu sat\u0131rda dikkat ederseniz, kernel i\u00e7erisindeki plugin&#8217;ler MCP Server&#8217;a tool olarak dahil edilmektedir. Tabi bu i\u015flemi yaparken <code>WithTools<\/code> metodunun verilen parametreyi kar\u015f\u0131layan bir overload&#8217;\u0131 olmad\u0131\u011f\u0131n\u0131 g\u00f6recek ve bir hatayla kar\u015f\u0131la\u015facaks\u0131n\u0131z. Gayet do\u011fal&#8230; Bu yap\u0131land\u0131rman\u0131n ba\u015far\u0131l\u0131 bir \u015fekilde ger\u00e7ekle\u015ftirilebilmesi i\u00e7in ilgili metot ad\u0131na \u00f6zel a\u015fa\u011f\u0131daki extension metodunun geli\u015ftirilmesi gerekmektedir.<\/p>\n<div style=\"font-size:12px;\">\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n    public static class ToolExtensions\r\n    {\r\n        public static IMcpServerBuilder WithTools(this IMcpServerBuilder builder, KernelPluginCollection plugins)\r\n        {\r\n            foreach (var plugin in plugins)\r\n            {\r\n                foreach (var function in plugin)\r\n                    builder.Services.AddSingleton(service =&gt; McpServerTool.Create(function.AsAIFunction()));\r\n            }\r\n\r\n            return builder;\r\n        }\r\n    }\r\n<\/pre>\n<\/div>\n<p>Yukar\u0131daki extension metot tan\u0131m\u0131na dikkat ederseniz e\u011fer <code>WithTools<\/code> metoduna yeni bir overload kazand\u0131r\u0131lmakta ve kernel i\u00e7erisindeki plugin&#8217;lerin MCP Server taraf\u0131ndan alg\u0131lanan tool&#8217;lara d\u00f6n\u00fc\u015ft\u00fcr\u00fclerek IoC Container&#8217;a eklendi\u011fi g\u00f6r\u00fclmektedir. Evet, buradan da anla\u015f\u0131laca\u011f\u0131 \u00fczere MCP Server&#8217;larda tool&#8217;lar esas\u0131nda IoC Container&#8217;a eklenen servislerdir. Velhas\u0131l, bu i\u015flem neticesinde Semantic Kernel&#8217;da tan\u0131mlanm\u0131\u015f olan fonksiyon(lar) MCP Server a\u00e7\u0131s\u0131ndan tool olarak yap\u0131land\u0131r\u0131lm\u0131\u015f olmaktad\u0131r(lar). Ee b\u00f6ylece art\u0131k, bu MCP Server&#8217;\u0131 kullanan herhangi bir MCP Client taraf\u0131ndan bu tool AI ile etkile\u015fim s\u00fcrecinde rahatl\u0131kla tetiklenebilir vaziyettedir diyebiliriz.<\/p>\n<p>\u015eimdi gelin, bu MCP Server&#8217;a yukar\u0131da olu\u015fturdu\u011fumuz MCP Host uygulamas\u0131 i\u00e7erisinde \u00fcretece\u011fimiz bir MCP Client ile ba\u011flanal\u0131m ve bar\u0131nd\u0131rd\u0131\u011f\u0131 tool&#8217;lar\u0131 Semantic Kernal&#8217;a aktararak AI modelle etkile\u015fim s\u00fcrecinde kullanmaya odaklanal\u0131m.<\/p>\n<div style=\"font-size:12px;\">\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n.\r\n.\r\n.\r\nGoogleGeminiAIMCPClient mcpClient = new(&quot;MCP.Server&quot;, Path.Combine(&quot;..&quot;, &quot;MCP.Server&quot;, &quot;bin&quot;, &quot;Debug&quot;, &quot;net9.0&quot;, &quot;MCP.Server.exe&quot;));\r\n\r\nGoogleGeminiAIMCPClient mcpClient2 = new(&quot;MCP.Server.SK&quot;, Path.Combine(&quot;..&quot;, &quot;MCP.Server.SK&quot;, &quot;bin&quot;, &quot;Debug&quot;, &quot;net9.0&quot;, &quot;MCP.Server.SK.exe&quot;));\r\n\r\nIList&lt;McpClientTool&gt; tools = await mcpClient.GetToolListAsync();\r\n\r\nforeach (var tool in await mcpClient2.GetToolListAsync())\r\n    tools.Add(tool);\r\n\r\nbuilder.Services\r\n    .AddKernel()\r\n    .AddOpenAIChatCompletion(\r\n        modelId: &quot;google\/gemini-2.0-flash-exp:free&quot;,\r\n        openAIClient: new OpenAIClient(\r\n                credential: new ApiKeyCredential(&quot;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&quot;),\r\n                options: new OpenAIClientOptions\r\n                {\r\n                    Endpoint = new Uri(&quot;https:\/\/openrouter.ai\/api\/v1&quot;),\r\n                }\r\n            )\r\n    )\r\n    .Plugins.AddFromFunctions(&quot;UserTool&quot;, tools.Select(_tool =&gt; _tool.AsKernelFunction()));\r\n.\r\n.\r\n.\r\n<\/pre>\n<\/div>\n<p>Yukar\u0131daki \u00e7al\u0131\u015fmay\u0131 incelerseniz e\u011fer 6. sat\u0131rda biraz \u00f6nce olu\u015fturdu\u011fumuz MCP Server&#8217;a ba\u011flanan yeni bir MCP Client olu\u015fturulmakta ve akabinde t\u00fcm MCP Client&#8217;lar \u00fczerinden MCP Server&#8217;lardaki tool&#8217;lar elde edilip birle\u015ftirilmekte ve bunlar Semantic Kernel&#8217;\u0131n plugin&#8217;lerine function olarak d\u00f6n\u00fc\u015ft\u00fcr\u00fcl\u00fcp, eklenmektedir.<\/p>\n<p>Art\u0131k bu \u00e7al\u0131\u015fmadan sonra a\u015fa\u011f\u0131daki gibi bir prompt e\u015fli\u011finde AI modelle testimizi ger\u00e7ekle\u015ftirebilir ve \u00fcretilecek cevap \u00fczerinden g\u00f6zlemde bulunabiliriz.<\/p>\n<div style=\"font-size:12px;\">\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n.\r\n.\r\n.\r\napp.MapGet(&quot;\/&quot;, async (IChatCompletionService chatCompletionService, Kernel kernel) =&gt;\r\n{\r\n    ChatMessageContent content = await chatCompletionService.GetChatMessageContentAsync(\r\n        prompt: &quot;T\u00fcm kullan\u0131c\u0131lar\u0131 ve bu kullan\u0131c\u0131lar\u0131n yap\u0131lacak listelerini istiyorum. bunlar\u0131 ekranda &#x5B;kullan\u0131c\u0131 ad\u0131 - yap\u0131lacak] \u015feklinde listelemeni istiyorum!&quot;,\r\n        executionSettings: new OpenAIPromptExecutionSettings()\r\n        {\r\n            FunctionChoiceBehavior = FunctionChoiceBehavior.Auto(options: new() { }),\r\n        },\r\n        kernel: kernel);\r\n\r\n    return content.Content.ToString();\r\n});\r\n<\/pre>\n<\/div>\n<p><a href=\"https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2025\/04\/Model-Context-Protocol-MCPunun-Semantic-Kernel-Ile-Birlikte-Kullanimi-2.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2025\/04\/Model-Context-Protocol-MCPunun-Semantic-Kernel-Ile-Birlikte-Kullanimi-2.png\" alt=\"Model Context Protocol (MCP)&#039;\u00fcn\u00fcn Semantic Kernel \u0130le Birlikte Kullan\u0131m\u0131\" width=\"900\" height=\"905\" class=\"aligncenter size-full wp-image-27768\" srcset=\"https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2025\/04\/Model-Context-Protocol-MCPunun-Semantic-Kernel-Ile-Birlikte-Kullanimi-2.png 900w, https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2025\/04\/Model-Context-Protocol-MCPunun-Semantic-Kernel-Ile-Birlikte-Kullanimi-2-298x300.png 298w, https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2025\/04\/Model-Context-Protocol-MCPunun-Semantic-Kernel-Ile-Birlikte-Kullanimi-2-150x150.png 150w, https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2025\/04\/Model-Context-Protocol-MCPunun-Semantic-Kernel-Ile-Birlikte-Kullanimi-2-768x772.png 768w, https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2025\/04\/Model-Context-Protocol-MCPunun-Semantic-Kernel-Ile-Birlikte-Kullanimi-2-80x80.png 80w\" sizes=\"auto, (max-width: 900px) 100vw, 900px\" \/><\/a>Dikkat ederseniz, AI modele g\u00f6nderilen prompt&#8217;ta hem t\u00fcm kullan\u0131c\u0131lara hem de bu kullan\u0131c\u0131lar\u0131n yap\u0131lacak listesine at\u0131fta bulunulmaktad\u0131r. Dolay\u0131s\u0131yla bu iki veri esas\u0131nda farkl\u0131 MCP Server&#8217;lardaki ayr\u0131 tool&#8217;lardan elde edilebilmektedir. Haliyle AI modelimiz laz\u0131m olan t\u00fcm verileri farkl\u0131 tool&#8217;lardan elde edip ihtiyac\u0131m\u0131z olan cevab\u0131 olu\u015fturup taraf\u0131m\u0131za sunmaktad\u0131r. Ve daha da ilginci, bu veriler aras\u0131nda mant\u0131ksal\u0131n d\u0131\u015f\u0131nda herhangi bir fiziksel ili\u015fki bulunmad\u0131\u011f\u0131 halde kulland\u0131\u011f\u0131m\u0131z AI modeli bu ili\u015fkileri de ger\u00e7ekle\u015ftirmi\u015f ve bir agent mantalitesinde elde etti\u011fi ayr\u0131 verileri birle\u015ftirerek k\u00fcm\u00fclatif bir netice sentezlemi\u015ftir.<\/p>\n<p>Harika de\u011fil mi? \ud83d\ude42<\/p>\n<p>Evet, b\u00f6ylece Semantic Kernel&#8217;da tasarlanm\u0131\u015f olan plugin&#8217;leri de farkl\u0131 MCP Client&#8217;lar\u0131n istifade edebilmesi i\u00e7in bu \u015fekilde tool&#8217;lara d\u00f6n\u00fc\u015ft\u00fcrebilmekte ve sistemi yetenek a\u00e7\u0131s\u0131ndan b\u00fct\u00fcnsel eri\u015febilir hale getirebilmekteyiz.<\/p>\n<p>Nihai olarak;<br \/>\nBu i\u00e7eri\u011fimizde, MCP protokol\u00fcn\u00fc Semantic Kernel ile birlikte AI modelleriyle etkile\u015fime sokarak \u00e7al\u0131\u015fma s\u00fcre\u00e7lerine MCP Server&#8217;lardaki harici servisleri dahil etmi\u015f ve b\u00f6ylece \u00fcretilecek cevaplar\u0131 \u00f6zelle\u015ftirerek bir agent mant\u0131\u011f\u0131nda uygulama geli\u015ftirmeyi tecr\u00fcbe etmi\u015f bulunuyoruz.<\/p>\n<p>\u0130lgilenenlerin faydalanmas\u0131 dile\u011fiyle&#8230;<br \/>\nSonraki yaz\u0131lar\u0131mda g\u00f6r\u00fc\u015fmek \u00fczere&#8230;<br \/>\n\u0130yi \u00e7al\u0131\u015fmalar&#8230;<\/p>\n<p>Not : \u00d6rnek \u00e7al\u0131\u015fmaya a\u015fa\u011f\u0131daki GitHub adresinden eri\u015febilirsiniz.<br \/>\n<a href=\"https:\/\/github.com\/gncyyldz\/Semantic_Kernel_With_MCP\" target=\"_blank\">https:\/\/github.com\/gncyyldz\/Semantic_Kernel_With_MCP<\/a><\/p>\n<!-- AddThis Advanced Settings generic via filter on the_content --><!-- AddThis Share Buttons generic via filter on the_content -->","protected":false},"excerpt":{"rendered":"<p>Merhaba, Bir \u00f6nceki Model Context Protocol (MCP) Nedir? Derinlemesine De\u011ferlendirelim\u2026 ba\u015fl\u0131kl\u0131 i\u00e7eri\u011fimizde MCP&#8217;ye dair tam teferruatl\u0131 bir incelemede bulunmu\u015f ve \u00f6zelle\u015ftirilmi\u015f MCP Server&#8217;lar e\u015fli\u011finde MCP Client&#8217;lar\u0131n nas\u0131l olu\u015fturulabilece\u011fini ele alm\u0131\u015ft\u0131k. Bu i\u00e7eri\u011fimizde ise Semantic&#46;&#46;&#46;<!-- AddThis Advanced Settings generic via filter on get_the_excerpt --><!-- AddThis Share Buttons generic via filter on get_the_excerpt --><\/p>\n","protected":false},"author":1,"featured_media":27759,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5206,5222,5220],"tags":[5291,5290,5221,5297],"class_list":["post-27751","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-net","category-llm","category-yapay-zeka-ai","tag-mcp","tag-model-context-protocol","tag-semantic-kernel","tag-semantic-kernel-mcp"],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/posts\/27751","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/comments?post=27751"}],"version-history":[{"count":15,"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/posts\/27751\/revisions"}],"predecessor-version":[{"id":27770,"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/posts\/27751\/revisions\/27770"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/media\/27759"}],"wp:attachment":[{"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/media?parent=27751"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/categories?post=27751"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/tags?post=27751"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}