Skip to main content
Any Framework

An MCP server using the MCP C# SDK.

NuGetCompare
Published
Sep 18, 2025
1y ago
Total Downloads
8.7K
8,687

Install

dotnet add package TimHeuer.SampleDotnetMcpServer --version 0.1.45-beta

No framework information available.

README

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:

  1. Set the version number as an environment variable:
$env:MCP_VERSION = "0.1.0-beta"
  1. Generate the server.json file:
pwsh .mcp/generate-server-json.ps1 -Template .mcp/server.template.json -Output .mcp/server.json
  1. Pack the NuGet package:
dotnet pack -c Release
  1. 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:

  1. Installs nbgv (Nerdbank.GitVersioning CLI)
  2. Extracts the NuGetPackageVersion and exports it as MCP_VERSION
  3. Generates .mcp/server.json from the template
  4. 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 configuration
  • Tools/RandomNumberTools.cs: Example MCP tool implementation
  • .mcp/server.json: MCP server metadata and NuGet package info
  • SampleDotnetMcpServer.csproj: Project and NuGet packaging configuration

Learn more


This project is for demonstration and reference purposes only. For feedback or contributions, see the GitHub repository.

Changes from Previous Version

No structural changes between v0.1.41-beta and v0.1.45-beta.

Adoption Assessment

Assess this package against its supported frameworks, license, maintenance signals and dependency graph before making it a project standard.

This version is marked prerelease. Validate its API and upgrade path before production use.No SPDX license expression is published. Review the license text and your organisation's policy before redistribution.No target framework metadata is available. Confirm compatibility in a representative project before standardising on this package.

Related Guides & Workflows

Learn how to evaluate, integrate, or audit this package in your .NET project.