关于 Microsoft NuGet
Microsoft NuGet 是 NuGet 的 MCP 服务,面向使用 NuGet 包管理的开发者和 AI 编码工具。它基于已配置的 NuGet 源提供包信息,并支持漏洞修复规划、包升级规划和供应链安全检查。
主要功能
- 01基于已配置的 NuGet 源获取实时包信息
- 02规划含已知漏洞包的保守修复方案
- 03基于包依赖图与目标框架规划升级
- 04审查 Central Package Management 等供应链安全配置
- 05需要 .NET 10 Preview 6 或更高版本
适用场景
- 01检查项目依赖中是否存在已知漏洞
- 02规划 NuGet 包的升级路径
- 03审查仓库的 NuGet 供应链安全配置
MCP 相关
该项目是一个 MCP 服务,通过 dnx 从 nuget.org 运行,向 MCP 客户端暴露包查询、漏洞修复、版本升级和供应链审查等工具。
配置
本地服务的配置在各客户端中通用,复制后粘贴到客户端的 MCP 配置文件即可。
我们还没有获取到这个服务的安装包或远程地址,请按项目 README 中的说明安装。
工具
本地服务需要在你的电脑上运行后才能读取工具,维护者暂未提供工具列表。
详细介绍
NuGet MCP 服务
包含一个适用于 NuGet 的 Model Context Protocol(MCP)服务,可支持 NuGet 包管理的高级工具和自动化场景。 有关最新信息,请参阅 NuGet 官方 MCP 文档。
功能
- 使用已配置的 NuGet 源获取包的实时信息。
- 为存在已知漏洞的包提供稳妥的修复规划,包括传递依赖项。
- 根据项目的包依赖图和目标框架制定包升级规划。
- 检查存储库的 NuGet 供应链状况(中央包管理、NuGet Audit、包源映射以及
NuGet.Config的有效性),并推荐加固措施。
要求
要运行 MCP 服务,必须安装 .NET 10 Preview 6 或更高版本。
此版本的 .NET 添加了 dnx 命令,用于从 nuget.org 下载、安装和运行 MCP 服务。
要验证 .NET 版本,请在终端中运行以下命令:
dotnet --info
入门
要配置 NuGet MCP 服务,需要修改 mcp.json 文件或其他配置。
下表列出了在不同环境中配置 MCP 服务的文档链接:
| 环境 | 文档 |
|---|---|
| Visual Studio | 自动发现 MCP 配置的文件位置 |
| VS Code | VS Code 中的 MCP 配置 |
| GitHub Copilot Coding Agent | 在存储库中设置 MCP 服务 |
Visual Studio 2026
NuGet MCP 服务已随 Visual Studio 2026 一同提供。 首次使用时,必须在 GitHub Copilot 聊天工具菜单中启用它。
如果想使用比 Visual Studio 内置版本更新的 NuGet MCP 服务,可以使用以下代码片段进行配置,并将其添加到 mcp.json 中:
{
"servers": {
"nuget": {
"type": "stdio",
"command": "dnx",
"args": [ "NuGet.Mcp.Server", "--source", "https://api.nuget.org/v3/index.json", "--yes" ]
}
}
}
如果想使用特定版本的 MCP 服务,可以在包名称中指定版本,例如 [email protected]:
{
"servers": {
"nuget": {
"type": "stdio",
"command": "dnx",
"args": [ "[email protected]", "--source", "https://api.nuget.org/v3/index.json", "--yes" ]
}
}
}
采用这种配置方式后,新版本发布时需要手动更新版本。
有关适合你的 mcp.json 文件位置的更多信息,请参阅自动发现 MCP 配置的文件位置。
Visual Studio 2022
要将 MCP 服务配置为与 Visual Studio 2022 配合使用,请确保已安装 17.14 或更高版本的更新。
然后使用以下代码片段,并将其添加到 mcp.json 中:
{
"servers": {
"nuget": {
"type": "stdio",
"command": "dnx",
"args": [ "NuGet.Mcp.Server", "--source", "https://api.nuget.org/v3/index.json", "--yes" ]
}
}
}
如果想使用特定版本的 MCP 服务,可以在包名称中指定版本,例如 [email protected]:
{
"servers": {
"nuget": {
"type": "stdio",
"command": "dnx",
"args": [ "[email protected]", "--source", "https://api.nuget.org/v3/index.json", "--yes" ]
}
}
}
采用这种配置方式后,新版本发布时需要手动更新版本。
有关适合你的 mcp.json 文件位置的更多信息,请参阅自动发现 MCP 配置的文件位置。
VS Code
若要在 VS Code 中配置 NuGet MCP 服务,可以使用以下徽章快速安装 MCP 服务:
若要手动配置 MCP 服务以供 Visual Studio 或 VS Code 使用,请使用以下代码片段,并将其加入 mcp.json:
{
"servers": {
"nuget": {
"type": "stdio",
"command": "dnx",
"args": [ "NuGet.Mcp.Server", "--source", "https://api.nuget.org/v3/index.json", "--yes" ]
}
}
}
若要使用特定版本的 MCP 服务,可以在包名中指定版本,例如 [email protected]:
{
"servers": {
"nuget": {
"type": "stdio",
"command": "dnx",
"args": [ "[email protected]", "--source", "https://api.nuget.org/v3/index.json", "--yes" ]
}
}
}
采用这种配置方式后,有新版本发布时,你需要手动更新版本。
有关如何找到适用于你的 mcp.json 文件位置的更多信息,请参阅 VS Code 中的 MCP 配置。
GitHub Copilot
你还可以配置 MCP 服务,使其作为编码 Agent 与存储库中的 GitHub Copilot 配合使用。
首先,需要在 Copilot 编码 Agent 中添加 MCP 服务配置:
{
"mcpServers": {
"NuGet": {
"type": "local",
"command": "dnx",
"args": ["NuGet.Mcp.Server", "--yes"],
"tools": ["*"],
"env": {}
}
}
}
这样即可使用所有 MCP 服务工具。若要使用特定工具,可以在 "tools" 参数数组中列出它们。
你还需要确保 Copilot 安装 .NET 10 Preview 6 或更高版本,以便使用 dnx 命令并安装 MCP 服务。
.github/workflows/copilot-setup-steps.yml
name: "Copilot Setup Steps"
# Automatically run the setup steps when they are changed to allow for easy validation, and
# allow manual testing through the repository's "Actions" tab
on:
workflow_dispatch:
push:
paths:
- .github/workflows/copilot-setup-steps.yml
pull_request:
paths:
- .github/workflows/copilot-setup-steps.yml
jobs:
# The job MUST be called `copilot-setup-steps` or it will not be picked up by Copilot.
copilot-setup-steps:
runs-on: ubuntu-latest
# Set the permissions to the lowest permissions possible needed for your steps.
# Copilot will be given its own token for its operations.
permissions:
# If you want to clone the repository as part of your setup steps, for example to install dependencies, you'll need the `contents: read` permission. If you don't clone the repository in your setup steps, Copilot will do this for you automatically after the steps complete.
contents: read
# You can define any steps you want, and they will run before the agent starts.
# If you do not check out your code, Copilot will do this for you.
steps:
- name: Install .NET 10.x
uses: actions/setup-dotnet@v5
with:
dotnet-version: |
10.x
dotnet-quality: preview
- name: dotnet --info
run: dotnet --info
当前支持的工具
fix_vulnerable_packages:通过计算最小的安全版本变更,修复 NuGet 依赖项中已知的安全漏洞。upgrade_packages_to_latest:将 NuGet 包升级到已配置包源中提供的最新兼容版本。get_latest_package_version:返回 NuGet 包的最新版本。get_package_context:如果 NuGet 包有AGENTS.md上下文,则返回该上下文;否则返回包的 README。update_package_version:将一个或多个 NuGet 包更新到指定的目标版本,同时保持依赖关系图兼容。review_supply_chain_security:检查并建议强化存储库 NuGet 供应链安全状况的措施(例如,中央包管理、NuGet 审核、包源映射和 NuGet.Config 验证)。
数据收集
本软件可能会收集有关你以及你使用本软件情况的信息,并将其发送给 Microsoft。Microsoft 可能会使用这些信息来提供服务并改进产品和服务。你可以按照存储库中的说明关闭遥测。本软件中的某些功能还可能使你和 Microsoft 能够收集应用程序用户的数据。如果你使用这些功能,则必须遵守适用法律,包括向应用程序用户提供适当通知,并附上 Microsoft 的隐私声明副本。你可以在帮助文档和隐私声明中了解有关数据收集和使用的更多信息。你使用本软件即表示同意这些做法。
遥测配置
默认启用遥测收集,以帮助改进产品。如需禁用,请参阅下方的仅禁用遥测部分,了解更多详情。
仅禁用遥测
如需禁用 Microsoft 遥测收集,请将环境变量 DOTNET_CLI_TELEMETRY_OPTOUT 设置为 true 或 1:
export DOTNET_CLI_TELEMETRY_OPTOUT=true
支持
如果您在使用 NuGet MCP 服务时遇到问题,或有其他反馈,请在 NuGet GitHub 存储库中提交问题。 请在问题模板中提供所需信息,以便我们更好地了解并处理您的问题或建议。
无担保 / 责任限制
本软件按“原样”提供,不附带任何明示或暗示的担保或条件。Microsoft 对因使用、误用或错误配置本软件而造成的任何损害不承担责任。
评论
一个开放协议,规定了 AI 应用如何以统一方式连接外部工具与数据源。客户端负责与模型对话,MCP 服务负责提供工具、资源和提示模板,两者通过标准消息通信,同一个服务可以被不同客户端复用。