Knapcode.SampleMcpServer — MCP server in C#: random numbers, weather
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.
Open on GitHubWhat Knapcode.SampleMcpServer 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 [email protected], 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.
What it helps with
- confirm an MCP client picks up the server and its tools
- pull random numbers inside a chat with an agent
- test how
WEATHER_CHOICESreaches the process - start a C# MCP server from a working template
- debug a local
stdioserver run from source
Example prompts for the agent
- Give me 3 random numbers with Knapcode.SampleMcpServer
- Ask the weather tool for a random forecast
- Run
dotnet run --project <path to project> -- mcp startand list the tools
How to install Knapcode.SampleMcpServer
Install
The MCP registry has no launch command for it: see the repository README
Step by step, with commands for each platform: How to add an MCP server to Claude Code, Codex, Cursor, VS Code, Gemini CLI and more
Questions about Knapcode.SampleMcpServer
How do I install Knapcode.SampleMcpServer in Claude Code?
The repository gives no Claude install commands. The server is a NuGet package started through dnx, and you wire the stdio entry into your MCP client's settings.
What does Knapcode.SampleMcpServer do?
It returns random numbers via get_random_number and a random weather value from WEATHER_CHOICES. It is a demo server on the MCP C# SDK.
What does the server need to run?
A .NET SDK with the dnx command and the [email protected] package. The weather list comes from the WEATHER_CHOICES environment variable.