Sampledotnetmcpserver

io.github.timheuer由 GitHub 账号 timheuer 发布v0.1.57-beta更新于 Oct 24, 2026

Sample .NET MCP Server

已验证STDIO仅桌面位置与生活开发者工具

概览

AI 生成的概览

一个 .NET 参考示例 MCP 服务器,提供随机数、问候语和美国邮编天气等演示工具,用于学习如何用 C# 构建 MCP 服务器。

可以做什么
  • 在指定范围内生成随机整数
  • 向指定名字打招呼或道别
  • 查询美国邮编所在地的当前天气
  • 获取美国邮编所在地的多日天气预报
适用场景
适合想了解如何用 C# 和 ModelContextProtocol SDK 编写 MCP 服务器的开发者,用来测试 MCP 客户端或 IDE 集成,或查看工具注册与 NuGet 打包方式。它是演示项目,不适合作为生产工具使用。
运行要求
以 .NET 进程通过 stdio 在本地运行;从源码运行需要 .NET SDK,运行已发布的 NuGet 包需要 dnx 工具。未声明认证、环境变量或请求头。天气工具依赖 wttr.in API,需要网络访问。
安装前请注意
README 明确说明该项目仅供演示和参考,不要用于实际工作。天气查询会把邮编发送给第三方服务 wttr.in。README 中 NuGet 示例使用的包 id 与清单不一致,安装前请核实包名。

安装

在 SourceWeft 中

  1. 打开 控制台中的 Sampledotnetmcpserver,将其添加到工作区。
  2. 为需要使用其工具的对话启用该服务。

Desktop only,通过 STDIO。 STDIO 服务会启动本地进程,因此需要 SourceWeft 桌面宿主。

其他 MCP 客户端

参照 仓库 中的启动说明。

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, Tools/SayHelloName.cs, Tools/WeatherTools.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 tools demonstrate various MCP capabilities:

  • get_random_number: Generates random numbers within a specified range
  • say_hello_name and say_goodbye_name: Simple greeting tools
  • get_weather_by_zip_code: Gets current weather information for any US zip code
  • get_weather_forecast: Gets a multi-day weather forecast for any US zip code

Features

  • Implements the MCP protocol using stdio transport
  • Provides multiple sample tools:
    • get_random_number: Returns a random integer in a specified range
    • say_hello_name and say_goodbye_name: Simple greeting tools
    • get_weather_by_zip_code: Gets current weather for any US zip code using wttr.in API
    • get_weather_forecast: Gets multi-day weather forecast for any US zip code
  • 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:

shell
dotnet run --project .

Or configure your IDE to use the following MCP server definition:

json
{  "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 available tools:

Weather Tools:

  • Ask: "What's the weather like in 90210?" to get current weather
  • Ask: "Give me a 3-day forecast for 10001" to get a weather forecast
  • Ask: "Check the weather in 60601" to test with Chicago's zip code

Other Tools:

  • Ask: "Give me 3 random numbers" to use the random number generator
  • Ask: "Say hello to John" to use the greeting tools

Publish to NuGet.org

CI handles publishing to NuGet, using NuGet Trusted Publishing for the key and automatic versioning using Nerdbank.GitVersioning.

Use from NuGet.org

After publishing, configure your IDE to use the MCP server from NuGet.org. Example configuration (replace package id and version):

json
{  "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 for generating random numbers
  • Tools/SayHelloName.cs: Example MCP tools for greetings
  • Tools/WeatherTools.cs: Weather-related MCP tools for checking weather by zip code
  • .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.

来源:README.md,提交 bf81344

工具

0
SourceWeft 尚未在沙箱中启动过该软件包,因此其工具未知。

版本历史

1
  1. v0.1.57-beta最新Sep 16, 2026

评分

已满足适用检查项的 50%

该评分衡量此收录条目的完整程度,依据注册中心条目、端点与公开来源计算得出。它不是对服务器本身的评价,也不表示服务器安全或当前可用:可连通性是带日期的检查结果,评分也不包含安装量或用户评价。

  • 近 30 天内可连通25 分

    请保持端点能够响应 MCP 握手;SourceWeft 每 30 天探测一次。

  • 已声明认证方式10 分

    请在注册中心条目中声明凭据请求头,或保持端点能够响应探测,以便判定其认证方式。

  • 已列出工具15 分

    请让服务器在无凭据时响应 tools/list,或发布可在沙箱中无凭据启动的软件包。

  • 描述必需15 分
  • 图标10 分
  • 文档15 分
  • 许可证10 分