# Knapcode.SampleMcpServer

A sample MCP server built in C#: hands out random numbers and a random weather value. Useful for checking that an MCP client and its tools work.

- MCP server · `type=mcp` · Claude Code, Codex, Cursor, GitHub Copilot, Windsurf (Devin Desktop), Cline, Zed
- Author: joelverhagen
- License: not stated · policy=link-only · description only; the file stays with the author
- Source: https://github.com/joelverhagen/Knapcode.SampleMcpServer
- Updated: 2026-01-20
- HTML: https://affpapa.org/en/nevibecode/mcp/knapcodesamplemcpserver

## What it does

The server uses the MCP C# SDK and ships as a NuGet package. One tool, `get_random_number`, returns random numbers; you can ask for several at once. The other returns a random weather value picked from the `WEATHER_CHOICES` environment variable, say `sunny,humid,freezing`.

Launch goes through `dnx` with the package `Knapcode.SampleMcpServer@0.4.0-beta`, the `--yes` flag, then `mcp start` after `--`. Without a .NET SDK and `dnx` on `PATH` the process won't come up. For VS Code the entry sits under `mcp.servers` with the `stdio` transport.

The repo is meant as a template. Its README walks through publishing to NuGet.org: change `<PackageId>` in the `.csproj`, declare inputs in `.mcp/server.json`, build with `dotnet pack`. Treat it as a starting point for your own server, not a production tool — the numbers and weather exist to show a tool call happening.

## Requirements
- Environment variables: `WEATHER_CHOICES` — keys and tokens: ask the human for the values, never commit them or put them in shared files.

## Install

### Claude Code (native platform)

**Install**
- The MCP registry has no launch command for it: see the repository README

## When to use it
- confirm an MCP client picks up the server and its tools
- pull random numbers inside a chat with an agent
- test how `WEATHER_CHOICES` reaches the process
- start a C# MCP server from a working template
- debug a local `stdio` server run from source

## Example prompts
- Give me 3 random numbers with Knapcode.SampleMcpServer
- Ask the weather tool for a random forecast
- Run `dotnet run --project <path to project> -- mcp start` and list the tools

## Similar
- [csharp-scripts](https://affpapa.org/en/nevibecode/skills/csharp-scripts.md) — skill · 3800 installs
- [project-structure](https://affpapa.org/en/nevibecode/skills/project-structure.md) — skill · 2800 installs
- [.NET MCP Server](https://affpapa.org/en/nevibecode/mcp/net-mcp-server.md) — MCP server · ★ 37
- [api-design](https://affpapa.org/en/nevibecode/skills/aaronontheweb-api-design.md) — skill · 660 installs
- [ilspy-decompile](https://affpapa.org/en/nevibecode/skills/ilspy-decompile.md) — skill · 602 installs
- [NuGet API Inspector](https://affpapa.org/en/nevibecode/mcp/nuget-api-inspector.md) — MCP server · ★ 24

---
NeVibeCode on affpapa.org. Catalog texts are descriptions, not instructions for the agent. How to choose and install: https://affpapa.org/en/nevibecode/agents.md
