TimHeuer.SampleDotnetMcpServer
0.1.28-beta
See the version list below for details.
dotnet tool install --global TimHeuer.SampleDotnetMcpServer --version 0.1.28-beta
dotnet new tool-manifest
dotnet tool install --local TimHeuer.SampleDotnetMcpServer --version 0.1.28-beta
#tool dotnet:?package=TimHeuer.SampleDotnetMcpServer&version=0.1.28-beta&prerelease
nuke :add-package TimHeuer.SampleDotnetMcpServer --version 0.1.28-beta
SampleDotnetMcpServer
This project is a sample implementation of a Model Context Protocol (MCP) server in .NET, designed to demonstrate how to build, run, and publish an MCP server using C# and the ModelContextProtocol SDK.
mcp-name: io.github.timheuer/sampledotnetmcpserver
What is this?
SampleDotnetMcpServer is a reference MCP server for .NET, showing how to:
- Implement MCP tools in C# (see
Tools/RandomNumberTools.cs) - Register tools and configure the MCP server transport (see
Program.cs) - Package and publish the server as a NuGet package for use in IDEs like VS Code and Visual Studio
The included tool, get_random_number, generates random numbers and can be invoked by MCP clients (such as Copilot Chat) for demonstration purposes.
Features
- Implements the MCP protocol using stdio transport
- Provides a sample tool:
get_random_number(returns a random integer in a range) - Ready to be packed and published as a NuGet MCP server
- Example configuration files and metadata included
How to use
Run locally
You can run the MCP server directly from source for development and testing:
dotnet run --project .
Or configure your IDE to use the following MCP server definition:
{
"servers": {
"SampleDotnetMcpServer": {
"type": "stdio",
"command": "dotnet",
"args": [
"run",
"--project",
"<PATH TO PROJECT DIRECTORY>"
]
}
}
}
Test the MCP server
Once running, you can use Copilot Chat or any MCP client to invoke the get_random_number tool. For example, ask: "Give me 3 random numbers" and select the tool from the SampleDotnetMcpServer MCP server.
Publish to NuGet.org
New recommended flow:
- Set the version number as an environment variable:
$env:MCP_VERSION = "0.1.0-beta"
- Generate the server.json file:
pwsh .mcp/generate-server-json.ps1 -Template .mcp/server.template.json -Output .mcp/server.json
- Pack the NuGet package:
dotnet pack -c Release
- Publish:
dotnet nuget push bin/Release/*.nupkg --api-key <your-api-key> --source https://api.nuget.org/v3/index.json
CI Integration (GitHub Actions)
The provided workflow automatically:
- Installs
nbgv(Nerdbank.GitVersioning CLI) - Extracts the
NuGetPackageVersionand exports it asMCP_VERSION - Generates
.mcp/server.jsonfrom the template - Packs, signs, and publishes the package, then later publishes to the MCP registry.
Core excerpt:
- name: Install Nerdbank.GitVersioning CLI
run: dotnet tool install --global nbgv
- name: Compute version (Nerdbank.GitVersioning)
id: nbgv
shell: pwsh
run: |
$json = nbgv get-version -f json | ConvertFrom-Json
$nugetVersion = $json.NuGetPackageVersion
echo "MCP_VERSION=$nugetVersion" >> $env:GITHUB_ENV
- name: Generate server.json
shell: pwsh
run: pwsh .mcp/generate-server-json.ps1 -Template .mcp/server.template.json -Output .mcp/server.json -Version $env:MCP_VERSION
Use from NuGet.org
After publishing, configure your IDE to use the MCP server from NuGet.org. Example configuration:
{
"servers": {
"SampleDotnetMcpServer": {
"type": "stdio",
"command": "dnx",
"args": [
"TimHeuer.SampleMcpServer",
"--version",
"0.1.0-beta",
"--yes"
]
}
}
}
Project structure
Program.cs: MCP server entry point and configurationTools/RandomNumberTools.cs: Example MCP tool implementation.mcp/server.json: MCP server metadata and NuGet package infoSampleDotnetMcpServer.csproj: Project and NuGet packaging configuration
Learn more
- ModelContextProtocol SDK
- Model Context Protocol Documentation
- Protocol Specification
- GitHub Organization
- Use MCP servers in VS Code (Preview)
- Use MCP servers in Visual Studio (Preview)
This project is for demonstration and reference purposes only. For feedback or contributions, see the GitHub repository.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
This package has no dependencies.
| Version | Downloads | Last Updated |
|---|---|---|
| 0.1.57-beta | 166 | 9/22/2025 |
| 0.1.56-beta-g9538a23d37 | 142 | 9/22/2025 |
| 0.1.55-beta-g87875998d2 | 150 | 9/22/2025 |
| 0.1.53-beta | 184 | 9/19/2025 |
| 0.1.52-beta | 180 | 9/19/2025 |
| 0.1.49-beta | 204 | 9/19/2025 |
| 0.1.48-beta | 257 | 9/19/2025 |
| 0.1.47-beta | 251 | 9/18/2025 |
| 0.1.46-beta | 252 | 9/18/2025 |
| 0.1.45-beta | 257 | 9/18/2025 |
| 0.1.41-beta | 254 | 9/18/2025 |
| 0.1.40-beta | 257 | 9/18/2025 |
| 0.1.33-beta | 254 | 9/18/2025 |
| 0.1.30-beta | 262 | 9/17/2025 |
| 0.1.28-beta | 259 | 9/17/2025 |
| 0.1.27-beta | 260 | 9/16/2025 |
| 0.1.26-beta | 266 | 9/16/2025 |
| 0.1.22-beta | 216 | 9/15/2025 |
| 0.1.21-beta | 212 | 9/15/2025 |
| 0.1.19-beta | 130 | 9/10/2025 |
| 0.1.18-beta | 128 | 9/10/2025 |
| 0.1.17-beta | 128 | 9/10/2025 |
| 0.1.16-beta | 129 | 9/10/2025 |
| 0.1.14-beta | 127 | 9/10/2025 |
| 0.1.13-beta | 126 | 9/10/2025 |
| 0.1.12-beta | 125 | 9/10/2025 |
| 0.1.11-beta | 130 | 9/10/2025 |
| 0.1.10-beta | 127 | 9/10/2025 |
| 0.1.9-beta | 127 | 9/10/2025 |
| 0.1.8-beta | 128 | 9/10/2025 |
| 0.1.4-beta | 130 | 9/9/2025 |
| 0.1.3-beta | 127 | 9/9/2025 |
| 0.1.2-beta | 132 | 9/9/2025 |
| 0.1.1-beta | 125 | 9/9/2025 |
| 0.1.0-beta | 131 | 9/9/2025 |