This solution demonstrates how to integrate Model Context Protocol (MCP) tools with Microsoft Semantic Kernel and it's based on https://devblogs.microsoft.com/semantic-kernel/integrating-model-context-protocol-tools-with-semantic-kernel-a-step-by-step-guide/
The example is a complete solution and it shows how to:
- Connect to an MCP Server using ModelContextProtocol
- Retrieve the list of tools the MCP Server makes available
- Convert the MCP tools to Semantic Kernel functions
- Invoke the MCP tools from Semantic Kernel in response to LLM function calling requests
- .NET 8.0 SDK or later
- Node.js and npm (for running the GitHub MCP server)
- OpenAI API key
- Clone this repository
- Add your OpenAI API key to user secrets:
dotnet user-secrets init dotnet user-secrets set "OpenAI:ApiKey" "your-api-key-here"
-
Navigate to the project directory:
cd MCPServerWithSK.ConsoleApp
-
Run the application:
dotnet run
The application will:
- Connect to the GitHub MCP server
- List all available GitHub tools
- Convert these tools to Semantic Kernel functions
- Interact with the "agent" by asking questions and git hub actions, e.g. "Tell me more about ikatic/model-context-protocol-tools-with-semantic-kernel repository."
The solution uses the ModelContextProtocol package to connect to a GitHub MCP server, which provides access to various GitHub operations. These operations are then converted into Semantic Kernel functions that can be called by the LLM.
The main components are:
- Configuration setup for OpenAI
- MCP client creation and connection
- Tool retrieval and conversion to Kernel functions
- Automatic function calling setup
- Prompt execution
- The GitHub MCP server is started using
npx
and runs as a separate process - The solution uses the stdio transport type for communication with the MCP server
- OpenAI's o3-mini-2025-01-31 model is used by default, but can be configured through settings