Add sampling to a .NET MCP server | Model Context Protocol Tutorial
Authorised Territory demonstrates how to add sampling to a .NET Model Context Protocol (MCP) server so an MCP tool can call back into a client’s locally running LLM (via Ollama) using a chat client.
Overview
This tutorial shows how to implement sampling support in a .NET MCP server.
- The MCP client invokes an MCP tool.
- That tool makes a request to the client’s LLM.
- The server-side tool uses a chat client to send messages to the client’s LLM running locally in Ollama.
Related starting point
The starting solution for this tutorial is referenced here: