#如果需要,您可以使用以下API示例检查服务器的可用性 1.当前天气 获取http://localhost:5000/api/weatherapi/current?city=Seoul&countryCode=KR
- 3天天气
获取http://localhost:5000/api/weatherapi/forecast?city=Seoul&countryCode=KR
- 天气警报
获取http://localhost:5000/api/weatherapi/alerts?city=Seoul&countryCode=KR
MCP服务器
此README是使用C#MCP服务器项目模板创建的。它演示了如何使用C#轻松创建MCP服务器并将其发布为NuGet包。
看 aka.ms/nuget/mcp/guide 完整的指南。
请注意,此模板目前处于早期预览阶段。如果您有反馈,请接受 简要调查.
发布到NuGet.org之前的检查表
- 使用以下步骤在本地测试MCP服务器。
- 更新.csproj文件中的包元数据,特别是 `
`.
- 更新
.mcp/server.json声明MCP服务器的输入。
- 看 配置输入 了解更多详情。
- 使用打包项目
dotnet pack.
这 bin/Release 目录将包含包文件(.nupkg),它可以是 发布到NuGet.org.
在当地发展
要从源代码(本地)测试此MCP服务器,而不使用内置的MCP服务器包,您可以将IDE配置为直接使用以下命令运行项目 dotnet run.
{
"servers": {
"WeatherMcpServer": {
"type": "stdio",
"command": "dotnet",
"args": [
"run",
"--project",
"
"
]
}
}
}测试MCP服务器
配置后,您可以向Copilot Chat询问随机数,例如, Give me 3 random numbers。它应该提示您使用 get_random_number 工具上 WeatherMcpServer MCP服务器,并向您显示结果。
发布到NuGet.org
- 跑
dotnet pack -c Release创建NuGet包 - 发布到NuGet.org
dotnet nuget push bin/Release/*.nupkg --api-key --source https://api.nuget.org/v3/index.json
使用NuGet.org的MCP服务器
一旦MCP服务器包发布到NuGet.org,您就可以在首选IDE中对其进行配置。VS Code和Visual Studio都使用 dnx 命令从NuGet.org下载并安装MCP服务器包。
- VS代码:创建一个
/.vscode/mcp.json文件 - Visual Studio:创建一个
\.mcp.json文件
对于VS Code和Visual Studio,配置文件都使用以下服务器定义:
{
"servers": {
"WeatherMcpServer": {
"type": "stdio",
"command": "dnx",
"args": [
"",
"--version",
"",
"--yes"
]
}
}
}更多信息
.NET MCP服务器使用 模型上下文协议 C#SDK。有关MCP的更多信息:
有关配置和使用MCP服务器的更多信息,请参阅VS Code或Visual Studio文档:
