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 分