Knapcode.SampleMcpServer

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

A sample MCP server using the MCP C# SDK. Generates random numbers and random weather.

已验证STDIO仅桌面开发者工具

概览

AI 生成的概览

一个使用 C# SDK 构建的示例 MCP 服务器,让助手生成随机数字和随机天气值。

可以做什么
按请求生成随机数字,例如一次生成多个值,使用 README 中提到的 get_random_number 工具。生成随机天气结果,可选天气由 WEATHER_CHOICES 环境变量提供。作为将 C# MCP 服务器打包为 NuGet 包的参考示例。
适用场景
适合在 VS Code 或其他客户端中试用 MCP,或作为构建自有 C# MCP 服务器时的起始模板。它只是演示,不是真实天气或其他生产数据的来源。
运行要求
通过 stdio 在本地运行。已发布的包使用 dnx 命令启动,因此需要 .NET 工具链;从源码运行则使用 dotnet run。WEATHER_CHOICES 环境变量用于设置天气选项。未声明身份验证。
安装前请注意
它只返回随机值,因此不要将其天气输出当作真实数据。README 中的发布清单面向自行创建包的开发者,而非最终用户。

安装

在 SourceWeft 中

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

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

其他 MCP 客户端

参照 仓库 中的启动说明。

README

MCP Server - Knapcode.SampleMcpServer

This README was created using the C# MCP server template project. It demonstrates how you can easily create an MCP server using C# and then package it in a NuGet package.

See aka.ms/nuget/mcp/guide for the full guide.

Checklist before publishing to NuGet.org

  • Test the MCP server locally using the steps below.
  • Update the package metadata in the .csproj file, in particular the <PackageId>.
  • Update .mcp/server.json to declare your MCP server's inputs.
  • Pack the project using dotnet pack.

The bin/Release directory will contain the package file (.nupkg), which can be published to NuGet.org.

Using the MCP Server in VS Code

Once the MCP server package is published to NuGet.org, you can use the following VS Code user configuration to download and install the MCP server package. See Use MCP servers in VS Code (Preview) for more information about using MCP servers in VS Code.

json
{  "mcp": {    "servers": {      "Knapcode.SampleMcpServer": {        "type": "stdio",        "command": "dnx",        "args": [          "[email protected]",          "--yes",          "--",          "mcp",          "start"        ],        "env": {          "WEATHER_CHOICES": "sunny,humid,freezing"        }      }    }  }}

Now you can ask Copilot Chat for a random number, for example, Give me 3 random numbers. It should prompt you to use the get_random_number tool on the Knapcode.SampleMcpServer MCP server and show you the results.

Developing locally in VS Code

To test this MCP server from source code (locally) without using a built MCP server package, create a .vscode/mcp.json file (a VS Code workspace settings file) in your project directory and add the following configuration:

json
{  "servers": {    "Knapcode.SampleMcpServer": {      "type": "stdio",      "command": "dotnet",      "args": [        "run",        "--project",        "<RELATIVE PATH TO PROJECT DIRECTORY>",        "--",        "mcp",        "start"      ],      "env": {        "WEATHER_CHOICES": "sunny,humid,freezing"      }    }  }}

Alternatively, you can configure your VS Code user settings to use your local project:

json
{  "mcp": {    "servers": {      "Knapcode.SampleMcpServer": {        "type": "stdio",        "command": "dotnet",        "args": [          "run",          "--project",          "<FULL PATH TO PROJECT DIRECTORY>"          "--",          "mcp",          "start"        ]      },      "env": {        "WEATHER_CHOICES": "sunny,humid,freezing"      }    }  }}

来源:README.md,提交 1b6a316

工具

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

版本历史

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

评分

已满足适用检查项的 40%

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

  • 近 30 天内可连通25 分

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

  • 已声明认证方式10 分

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

  • 已列出工具15 分

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

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

    请在仓库或注册中心条目中声明许可证。