
Pkgdiet
io.github.om-tajne由 GitHub 帳號 om-tajne 發布v2.0.1更新於 Oct 30, 2026
Dependency policy and MCP server to stop AI coding agents from installing risky npm packages.
概覽
本機 MCP 伺服器,依儲存庫相依性政策檢查 npm 套件,在 AI 代理安裝前回傳 ALLOW、WARN 或 BLOCK 結論。
- 可以做什麼
- 依本機政策評估單一 npm 套件,回傳附證據的 ALLOW、WARN 或 BLOCK 結構化結論
- 一次呼叫批次檢查最多 50 個相依套件
- 為被封鎖或不建議的套件查詢精選的現代、更輕量替代方案
- 讀取目前儲存庫的相依性政策規則與門檻
- 詳細解釋某個結論,包括評分、維護訊號與診斷代碼
- 適用情境
- 當 AI 編碼代理撰寫 JavaScript 或 TypeScript、可能提出不存在、已棄用、有漏洞或仿冒名稱的 npm 套件時適用,可用統一政策攔阻安裝。也適合希望以代理鉤子和 CI 關卡執行同一套規則的團隊。
- 執行需求
- 透過 npm 套件 pkgdiet 以本機 stdio 程序執行,需要 Node.js 20 或更新版本。專案中需有 .pkgdietrc.json 政策檔定義規則。漏洞與來源驗證需連線 npm 註冊表與公開的 OSV 公告 API,除非以 PKGDIET_NO_NETWORK 啟用離線模式。不需帳號或 API 金鑰。
安裝
在 SourceWeft 中
- 開啟 儀表板中的 Pkgdiet,將其新增到工作區。
- 為需要使用其工具的對話啟用該服務。
Desktop only,透過 STDIO。 STDIO 服務會啟動本機處理程序,因此需要 SourceWeft 桌面主機。
其他 MCP 客戶端
參照 儲存庫 中的啟動說明。
README
🥗 PkgDiet
Dependency policy for AI-assisted JavaScript and TypeScript development.
Put your node_modules on a diet.
[npm version]
[npm downloads]
[Audited by PkgDiet]
[CI Status]
[Node.js]
[TypeScript]
[GitHub Issues]
[PRs Welcome]
[License]
[Powered by MCP]
[Glama MCP Server]
[Listed on mcpservers.org]
The Problem: AI coding agents (Claude Code, Codex, Cursor, Windsurf, Cline) propose nonexistent, deprecated, vulnerable, or typosquatted packages. There is no built-in mechanism to stop them from running the install.
The Solution: PkgDiet intercepts every npm install / pnpm add / yarn add command your AI agent generates — using native agent hook APIs — and blocks unapproved installs before they execute.
🔒 Live Proof
Run this to see PkgDiet block real risky AI-generated dependencies in your terminal:
Example output:
For machine-readable CI proof:
🚀 One-Command Setup
This single command creates:
🛡️ Enforcement by Agent
PkgDiet uses each agent's native hook API to block installs — not just advisory rules:
How PreToolUse hooks work: When Claude Code or Codex generates a Bash tool call containing
npm install, the registered hook script runs first. If PkgDiet returns a non-zero exit code (exit code 2 for Claude Code), the agent sees the denial reason and aborts the install — the command never runs.
Claude Code Plugin
PkgDiet is packaged as a Claude Code plugin featuring bundled MCP tools, slash commands (/pkgdiet:check, /pkgdiet:audit), skill definitions, and PreToolUse execution hooks:
(Or /plugin install pkgdiet@claude-plugins-official once listed in the official directory)
🔄 The 3-Phase Policy Loop
PkgDiet uses a shared core engine (@pkgdiet/core) so all interfaces apply the same evaluation logic.
- Repository Policy: A single
.pkgdietrc.jsonfile dictates what is allowed, warned, or blocked for your project. - Agent Hook (Enforce): Native PreToolUse hooks for Claude Code and Codex intercept install commands before execution. MCP
check_dependencyinstructs other agents before they write the command. - CI Gate (Fallback):
npx pkgdiet ciruns in GitHub Actions, diffspackage.jsonagainst the base commit, and fails the PR if any added package violates policy.
🛠️ CLI Commands
⚙️ Configuration (.pkgdietrc.json)
🤖 MCP Integration
PkgDiet acts as a local Model Context Protocol (MCP) server over stdio.
When your AI coding agent connects to PkgDiet, it gains access to 5 read-only tools:
check_dependency: Evaluates an npm package against your local.pkgdietrc.jsonpolicy and returns structuredALLOW,WARN, orBLOCKverdicts with evidence.check_dependencies: Bounded batch evaluation of up to 50 dependencies in a single tool call.suggest_alternative: Queries PkgDiet's curated dataset to find modern, lighter, and maintained alternatives for blocked packages.get_policy: Retrieves the active repository dependency policy rules and thresholds.explain_verdict: Detailed breakdown of package scoring, maintenance signals, and diagnostic codes.
Built-in Verification (all free, zero paid API keys):
- OSV vulnerability database — checks known CVEs via the public OSV advisory API
- npm registry provenance — verifies signed npm attestations
- Typosquat detection — edit-distance checks against popular package namespaces
- Lockfile pinning validation — enforces deterministic package resolution
- Dependency confusion detection — blocks internal-prefix packages found on public registries
💻 Requirements & Runtime Controls
- Node.js: Requires Node.js 20 or later (Node.js >=20).
PKGDIET_NO_NETWORK=1: Runs completely offline using cached metadata; never contacts the external registry.PKGDIET_TELEMETRY_DISABLED=1: Disables local telemetry and metrics collection.PKGDIET_REGISTRY_URL: Overrides the default npm registry with a custom or private enterprise registry endpoint..pkgdiet-cache.json: Local cache file storing validated package metadata and advisory results..pkgdiet-metrics.json: Local metrics file for tracking audit performance and check history.
📦 Monorepo Architecture
⚖️ Legal, Privacy & Trademark Notice
- Advisory Tooling: PkgDiet is open-source software provided under the MIT License. It evaluates publicly available npm metadata and local project configurations according to user-defined policy. It provides advisory analysis only and does not constitute formal legal, cybersecurity, compliance, or procurement advice.
- Nominative Fair Use & Trademarks: All third-party trademarks, product names, logos, and brands (including npm, GitHub, GitHub Copilot, Claude / Claude Code, Cursor, Windsurf, Cline, Codex / OpenAI, and Google) are the property of their respective owners. Their mention in this repository is strictly for integration identification and compatibility under nominative fair use. No affiliation, endorsement, sponsorship, or partnership is claimed or implied.
- Local-First Privacy: PkgDiet operates locally via stdio and local caching. It does not inspect, collect, or transmit proprietary codebase source code or credentials. For full terms, see
LEGAL.md.
🔗 Documentation & Support
-
Legal & Privacy Notice:
LEGAL.md -
Architecture Guide:
ARCHITECTURE.md -
Threat Model & Security:
docs/THREAT-MODEL.md&SECURITY.md -
Enterprise Adoption:
docs/ENTERPRISE-ADOPTION.md -
CI Integration:
docs/CI.md -
MCP Integration Guide:
docs/MCP.md -
GitHub Repository: om-tajne/pkgdiet
-
Report an Issue: Issue Tracker
-
License: MIT
來源:README.md,提交 64ffcc9
工具
0版本歷史
2- v2.0.1最新Oct 30, 2026
- v1.2.1Sep 16, 2026
評分
已滿足適用檢查項的 50%
該評分衡量此收錄條目的完整程度,依據註冊中心條目、端點與公開來源計算得出。它不是對伺服器本身的評價,也不表示伺服器安全或目前可用:可連通性是帶日期的檢查結果,評分也不包含安裝量或使用者評價。
- 近 30 天內可連通25 分
請保持端點能夠回應 MCP 握手;SourceWeft 每 30 天探測一次。
- 已宣告認證方式10 分
請在註冊中心條目中宣告憑證請求標頭,或保持端點能夠回應探測,以便判定其認證方式。
- 已列出工具15 分
請讓伺服器在無憑證時回應 tools/list,或發布可在沙箱中無憑證啟動的軟體包。
- 描述必需15 分
- 圖示10 分
- 文件15 分
- 授權條款10 分