McpServer SamplingWithTools
No description available
Ask AI about McpServer SamplingWithTools
Powered by Claude · Grounded in docs
I know everything about McpServer SamplingWithTools. Ask me about installation, configuration, usage, or troubleshooting.
0/500
Reviews
Documentation
MCP Server - Sampling With Tools
Demo of how to use native sampling with tools in an MCP Server, using the C# MCP SDK v1.2.0 and the MCP 2025-11-25 specification.
This is an updated version of an earlier demo that used a workaround (JSON-based tool calling via prompt instructions) because native tool support in sampling was not yet available. A LinkedIn post with a short video that demonstrates this in (a custom fork of) VS Code can bed found here.
What changed
The original demo instructed the LLM to return JSON {"call":"...", "args":"..."} objects which the server parsed manually in a loop. With SEP-1577 (Sampling With Tools) now part of the MCP specification and implemented in the C# SDK, tools are declared natively in the sampling request via ChatOptions.Tools. The LLM returns proper FunctionCallContent objects through the protocol, and the server responds with FunctionResultContent messages -- no JSON string parsing needed.
How it works
The MCP Server exposes a single tool (SampleLlm) that uses sampling to interact with the client's LLM. During sampling, two internal tools are declared:
- GetDataFromCrm - Retrieves data from Dataverse. Internally uses additional sampling calls to convert natural language to FetchXml and format the results.
- CreateExcel - Creates an Excel file. Internally uses sampling to convert data to CSV format.
The LLM can call these tools natively during the sampling session. The server executes each tool and feeds the result back, looping until the LLM produces a final text response.
Prerequisites
- .NET 9.0
- A Dataverse/Dynamics 365 environment (update credentials in
GetOrganizationService()) - An MCP client that supports sampling with tools.
Running
cd SamplingMcpServer
dotnet run
The server starts on http://localhost:3001.
MCP Client support
Note that sampling with tools requires the MCP client to advertise the sampling.tools capability. As of March 2026, client support for this specific capability is not really available -- this project serves as a test bed to verify client compatibility.
