关于 NugetMcpServer
NugetMcpServer 是一个本地 MCP 服务,让 Codex、Claude Code、VS Code 等客户端在生成代码前查询 NuGet 包的元数据与公共 API。它支持 nuget.org、私有 feed 和本地包文件夹,适合需要核对包版本细节的 .NET 开发场景。
主要功能
- 01搜索 NuGet 包并查看元数据
- 02读取指定版本的公共 API 定义
- 03比较不同版本之间的 API 变化
- 04浏览包内文件
- 05支持私有 feed 与本地包文件夹
适用场景
- 01生成依赖特定包版本的代码前核对 API
- 02比较两个包版本之间的破坏性变更
- 03在私有 NuGet feed 中查找内部包的类型定义
MCP 相关
该项目是一个 MCP 服务,向 MCP 客户端暴露包搜索、元数据、类型定义、版本比较和包文件读取等工具。
配置
本地服务的配置在各客户端中通用,复制后粘贴到客户端的 MCP 配置文件即可。
我们还没有获取到这个服务的安装包或远程地址,请按项目 README 中的说明安装。
工具
本地服务需要在你的电脑上运行后才能读取工具,维护者暂未提供工具列表。
详细介绍
NugetMcpServer
错误猜测 NuGet API 的代价很高。
NugetMcpServer 让 Codex、Claude Code、VS Code、Claude Desktop 和其他 MCP 客户端在生成代码前检查真实的 NuGet 包元数据和公共 API。当包版本详情很重要,或包位于私有源中时,它尤其有用。
最快的方式:使用 codex mcp add 或 claude mcp add 安装,然后让助手在编写依赖包的代码前使用 NuGet MCP 服务。
为什么要开发它
大模型通常了解常用库,但无法可靠地掌握每个包版本的确切 API 范围。NugetMcpServer 让助手能够先检查包,而不是凭记忆填补信息空白。
NugetMcpServer 可将助手直接连接到 NuGet 包,包括私有源和本地包文件夹。
它能为助手提供什么
- 搜索 NuGet 包并检查包元数据。
- 读取真实包版本的公共 API 定义。
- 比较版本、检查包文件,并使用 nuget.org、私有源或本地包文件夹。
快速开始
这些命令使用当前发布的 NuGet 包版本 1.1.7。dnx 会从 NuGet 下载并运行 .NET 工具,因此无需单独执行 dotnet tool install。
1. 通过 Codex CLI 安装
codex mcp add nuget -- dnx [email protected] --yes
检查可用的 MCP 命令:
codex mcp --help
在 Codex TUI 中运行:
/mcp
Codex CLI 和 Codex IDE 扩展共享 MCP 配置,因此配置一次服务后,它应该会同时在两个客户端中可用。
2. 通过 Claude Code CLI 安装
claude mcp add --transport stdio nuget -- dnx [email protected] --yes
-- 后的所有内容都是实际的 MCP 服务命令及其参数。
管理并验证服务:
claude mcp list
claude mcp get nuget
在 Claude Code 中运行:
/mcp
3. 在 VS Code 中安装
打开 NuGet 包页面,选择 MCP Server 选项卡,然后复制生成的 VS Code 配置。
如需手动配置 VS Code,请将以下内容添加到 mcp.json。将 <version> 替换为你要固定使用的包版本:
{
"servers": {
"nuget": {
"type": "stdio",
"command": "dnx",
"args": ["DimonSmart.NugetMcpServer@<version>", "--yes"]
}
}
}
4. 通过 Docker 安装
当 MCP 客户端环境中没有 .NET SDK 时,请使用 Docker。
Codex:
codex mcp add nuget-docker -- docker run -i --rm ghcr.io/dimonsmart/nugetmcpserver:latest
Claude Code:
claude mcp add --transport stdio nuget-docker -- docker run -i --rm ghcr.io/dimonsmart/nugetmcpserver:latest
直接运行容器:
docker run -i --rm ghcr.io/dimonsmart/nugetmcpserver:latest
VS Code mcp.json:
{
"servers": {
"nuget": {
"type": "stdio",
"command": "docker",
"args": ["run", "-i", "--rm", "ghcr.io/dimonsmart/nugetmcpserver:latest"]
}
}
}
5. 手动配置
Codex config.toml:
[mcp_servers.nuget]
command = "dnx"
args = ["DimonSmart.NugetMcpServer@<version>", "--yes"]
Codex Docker 版本:
[mcp_servers.nuget]
command = "docker"
args = ["run", "-i", "--rm", "ghcr.io/dimonsmart/nugetmcpserver:latest"]
Claude Desktop 和使用 mcpServers JSON 格式的通用 MCP 客户端:
{
"mcpServers": {
"nuget": {
"command": "dnx",
"args": ["DimonSmart.NugetMcpServer@<version>", "--yes"]
}
}
}
6. 私有/本地 NuGet 源
使用 NUGET_SOURCES 指定一个或多个源 URL 或本地包文件夹。使用分号分隔多个源。如果希望 NuGet 读取特定的 NuGet.Config,例如其中已配置凭据或源名称,请使用 NUGET_CONFIG。
使用 NUGET_SOURCES 的 Codex:
codex mcp add nuget-private \
--env NUGET_SOURCES="C:\NuGet\LocalFeed;https://pkgs.dev.azure.com/ORG/_packaging/Feed/nuget/v3/index.json" \
-- dnx DimonSmart.NugetMcpServer@<version> --yes
使用 NUGET_SOURCES 的 Claude Code:
claude mcp add --transport stdio \
--env NUGET_SOURCES="C:\NuGet\LocalFeed;https://pkgs.dev.azure.com/ORG/_packaging/Feed/nuget/v3/index.json" \
nuget-private \
-- dnx DimonSmart.NugetMcpServer@<version> --yes
使用 NUGET_CONFIG 的 Codex:
codex mcp add nuget-config \
--env NUGET_CONFIG="/path/to/NuGet.Config" \
-- dnx DimonSmart.NugetMcpServer@<version> --yes
使用 NUGET_CONFIG 的 Claude Code:
claude mcp add --transport stdio \
--env NUGET_CONFIG="/path/to/NuGet.Config" \
nuget-config \
-- dnx DimonSmart.NugetMcpServer@<version> --yes
在 Windows 上使用 C:\path\to\NuGet.Config 这样的 Windows 路径。在 Linux 和 macOS 上使用 /path/to/NuGet.Config 这样的 Unix 风格路径。路径中包含空格时,请保留引号。
包含私有源的 VS Code mcp.json:
{
"servers": {
"nuget": {
"type": "stdio",
"command": "dnx",
"args": ["DimonSmart.NugetMcpServer@<version>", "--yes"],
"env": {
"NUGET_SOURCES": "C:\\NuGet\\LocalFeed;https://pkgs.dev.azure.com/ORG/_packaging/Feed/nuget/v3/index.json"
}
}
}
}
包含私有源的 Codex config.toml:
[mcp_servers.nuget]
command = "dnx"
args = ["DimonSmart.NugetMcpServer@<version>", "--yes"]
[mcp_servers.nuget.env]
NUGET_SOURCES = "C:\\NuGet\\LocalFeed;https://pkgs.dev.azure.com/ORG/_packaging/Feed/nuget/v3/index.json"
更多配置选项:技术详情
验证是否正常工作
MCP 客户端显示服务已连接后,请明确要求助手使用它:
Use the NuGet MCP server to inspect Dapper 2.1.66 and show the public extension methods for IDbConnection.
Before writing code, use the NuGet MCP server to inspect the real API of Microsoft.Extensions.DependencyInjection.Abstractions and use only existing public types and methods.
Use the NuGet MCP server to compare public APIs of Some.Package 1.8.0 and 2.0.0 and summarize breaking changes.
可用工具
search_packages:根据查询和关键词搜索包。search_packages_fuzzy:使用 AI 辅助的模糊包搜索。get_package_info:获取包元数据、依赖项和包结构信息。list_interfaces:列出公共接口。list_classes_records_structs:列出公共类、记录和结构体。get_interface_definition:返回 C# 接口定义。get_class_or_record_or_struct_definition:返回 C# 类、记录或结构体定义。get_enum_definition:返回 C# 枚举定义。compare_package_versions:比较不同版本之间的公共 API 变更。list_package_files:列出包中的文件。get_package_file:读取包中的文件。get_current_time:返回当前服务时间。
详细参数和开发说明:技术详情
故障排除
- 找不到
dnx:安装当前版本的 .NET SDK,并确保 shell 中可以使用 .NET 工具路径,或者使用 Docker 安装方式。 - Docker 未运行:启动 Docker Desktop 或 Docker 守护进程,然后重试 MCP 客户端命令。
- MCP 客户端显示服务,但没有工具:重启客户端,检查客户端日志,并确认在客户端之外可以成功启动服务命令。
- 私有源身份验证失败:检查当前使用的
NuGet.Config、凭据提供程序设置、源 URL,以及同一用户帐户是否能通过常规 NuGet 工具从该源还原包。 - 首次运行时还原包或搜索速度较慢:服务和 NuGet 客户端可能需要先下载包元数据和包文件,之后读取缓存内容会更快。
- Windows 路径引号处理失败:保留路径周围的引号,在 JSON/TOML 字符串中转义反斜杠;涉及复杂源路径或凭据时,优先使用
NUGET_CONFIG。 - Claude Code 或 Codex CLI 命令意外失败:确保命令在
dnx或docker前包含--分隔符;MCP 客户端选项必须放在该分隔符之前。
版本
发布版本由 GitHub Actions 流水线根据 Git 标签分配。
检查已安装的版本:
NugetMcpServer --version
发布
NuGet 版本发布由 main 分支上的版本标签触发:
.\publish-next-version.ps1
该脚本会创建并推送下一个 vMAJOR.MINOR.PATCH 标签。GitHub Actions 会构建并测试项目、更新 MCP 清单版本、打包 NuGet MCP 服务包,并将其发布到 NuGet。
WinGet 发布也会在 GitHub Release 创建后由标签触发:
.\publish-winget-version.ps1
默认情况下,WinGet 脚本使用最新的 vMAJOR.MINOR.PATCH 发布标签。传入 -Version 1.2.3 可发布指定版本。
许可证
MIT
评论
一个开放协议,规定了 AI 应用如何以统一方式连接外部工具与数据源。客户端负责与模型对话,MCP 服务负责提供工具、资源和提示模板,两者通过标准消息通信,同一个服务可以被不同客户端复用。