Integrating Model Context Protocol Tools with Semantic Kernel: A Step-by-Step Guide

Integrating Model Context Protocol Tools with Semantic Kernel
Overview
This post provides a step-by-step guide on how to integrate Model Context Protocol tools with Semantic Kernel. Model Context Protocol (MCP) is an open protocol that standardizes how applications provide context to LLMs. The sample described in this post focuses on connecting an AI model to an MCP tool via function calling.
Setting Up MCP Client
- Use
npx
to create an MCP Client configured to connect to a local GitHub server using the stdio transport.
npx @model-context/mcpdotnet
Retrieving MCP Tools
- Retrieve the list of tools exposed by the MCP server.
- Print out each tool name and description.
// Code to retrieve and list MCP tools
Available MCP Tools:
- List of tools exposed by the GitHub MCP server.
Adapting MCP Tools to Kernel Functions
- Convert each MCP tool to be a
KernelFunction
to be used with Semantic Kernel. - Ensure arguments are converted to the correct types supported by the sample code.
Invoking MCP Tools via Function Calling
- Add the converted MCP tools to
Kernel.Plugins
in Semantic Kernel. - MCP tools are now available for use with function calling in Semantic Kernel.
For the complete source code sample, refer to the Semantic Kernel repository.