Building a Model Context Protocol Server with Semantic Kernel

Building a Model Context Protocol (MCP) Server with Semantic Kernel
Overview
This blog post demonstrates how to build an MCP server using the MCP C# SDK and Semantic Kernel (SK). It covers how to expose SK plugins as MCP tools, call the tools from the client side via SK, and the benefits of integrating SK with MCP.
Reasons for Building an MCP Server with SK
- Interoperability: Reuse existing SK plugins and expose them as MCP tools for consumption by non-SK applications or different SK platforms.
- Content Safety: Validate each tool call before execution using SK Filters.
- Observability: Collect logs, traces, and metrics related to tool calls for monitoring purposes.
Build MCP Server and Expose SK Plugins as MCP Tools
- Declare SK plugins to be exposed as MCP tools.
- Create an MCP server, import SK plugins, and convert SK plugin functions to AI functions to be exposed as MCP tools.
Build MCP Client and Use MCP Tools in SK
- Create an MCP client.
- Retrieve MCP tools from the server, import them to SK, add OpenAI chat completion service, and build the kernel.
- Prompt the AI model, which will call the imported kernel functions that delegate the calls to the MCP tools to answer the prompt.
Conclusion
Try out the sample code provided in the Semantic Kernel repository to get started. Future plans include creating more samples to showcase how to leverage Semantic Kernel for building MCP prompts and resources on the server side, as well as using them with the SK client side.