mcp-lock
mcp-lock
为你的 MCP 服务器提供 npm ci 功能。
每次你的 AI 编码工具启动时,
npx -y @scope/mcp-server都会静默下载每个 MCP 服务器的最新版本。没有版本锁定。没有哈希检查。没有关于昨天运行了什么的记录。
mcp-lock解决了这个问题。它在首次运行时记录每个 MCP 服务器的精确版本和压缩包完整性哈希值,并在后续每次运行时验证没有任何内容被篡改。
问题所在
// Your .mcp.json — right now
{
"mcpServers": {
"filesystem": {
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-filesystem"]
// ^^^
// Downloads whatever is latest. Every. Single. Time.
}
}
}2026 年 3 月的 axios 供应链攻击破坏了一个小版本更新 (1.14.1)。所有使用 ^1.14.0 的用户都静默自动升级了。恶意软件在任何人注意到之前就已经运行了。
MCP 服务器面临同样的风险。 它们是 npm 包。它们使用你的凭据运行。它们访问你的文件系统和 API。而且目前没有任何扫描器可以跟踪你今天运行的包是否与你上周审查的包相同。
Related MCP server: mcp-shield
安装与快速入门
# 1. Lock all your MCP servers (one time)
npx @mcpguards/mcp-lock init
# 2. Commit the lockfile
git add .mcp.lock && git commit -m "chore: add mcp-lock lockfile"
# 3. Verify on every CI run (exits 1 if anything changed)
npx @mcpguards/mcp-lock verify就是这样。如果包在两次运行之间发生了变化,你会在 AI 代理运行它之前就知道。
命令
mcp-lock init
发现你机器上的所有 MCP 配置,将每个服务器解析为其 npm 包,并记录精确的版本 + 压缩包完整性哈希值。
$ mcp-lock init
Found 4 server(s) across 2 config(s)
✔ filesystem 2026.1.1 sha512-xK3z… ✔ attestation
✔ github 2026.1.1 sha512-9mRq… ✔ attestation
✔ memory 2025.11.18 sha512-pL2t… ○ no attestation
~ python-server pypi registry — not lockable
─────────────────────────────────────────────────────────────────
3 locked 1 skipped
✔ Lockfile written to .mcp.lock
Tip: Run with --pin to add version pins to your MCP configs.选项:
--config <path> Scan a specific config file
--pin Rewrite configs to add @version pins
--force Overwrite existing lockfile
--global Write to ~/.mcp.lockmcp-lock verify
将你安装的包与锁文件进行比较。如果发生任何变化,则退出 1。
$ mcp-lock verify
mcp-lock .mcp.lock
────────────────────────────────────────────────────────────────
✔ filesystem
✔ github
⚠ memory INTEGRITY-CHANGED
integrity sha512-pL2t… → sha512-XXXX…
version 2025.11.18 → 2025.11.19
ACTION REQUIRED: Run `mcp-lock update memory` after manual review.
────────────────────────────────────────────────────────────────
2 clean 1 changed 0 skipped
✖ 1 server(s) changed since last lock.
Run 'mcp-lock update <server>' to review and accept changes.选项:
--sarif <path> Write SARIF 2.1.0 report for GitHub Security tab
--json Output as JSON
--global Check against ~/.mcp.lock退出代码:
代码 | 含义 |
| 清洁 — 所有服务器均与锁文件匹配 |
| 已更改 — 一个或多个服务器已更改,或锁文件被篡改 |
| 缺少锁文件 — 运行 |
| 网络 / 注册表错误 |
| 无效参数 |
mcp-lock update <server>
显示具体更改内容,请求确认,并更新锁文件。
$ mcp-lock update memory
memory
version 2025.11.18 → 2025.11.19
integrity sha512-pL2t… →
sha512-XXXX…
Accept update for memory? [y/N] y
✔ Updated 1 server(s) in .mcp.lock选项:
--all Update all servers
--to <version> Update to a specific version
--yes Skip confirmation prompt (for CI)
--pin Also update version pin in the MCP configmcp-lock list
显示所有已锁定的服务器。
$ mcp-lock list
mcp-lock list scope: project
────────────────────────────────────────────────────────────────
✔ filesystem @modelcontextprotocol/server-filesystem 2026.1.1
✔ github @modelcontextprotocol/server-github 2026.1.1
○ memory @modelcontextprotocol/server-memory 2025.11.18
────────────────────────────────────────────────────────────────
3 servers generated 4/16/2026GitHub Action
添加到任何拥有 .mcp.json 配置的仓库中。如果服务器在没有显式执行 mcp-lock update 的情况下发生更改,则会导致 PR 失败:
# .github/workflows/mcp-lock.yml
name: MCP Lock
on: [push, pull_request]
jobs:
verify:
runs-on: ubuntu-latest
permissions:
contents: read
security-events: write # for SARIF upload
steps:
- uses: actions/checkout@v4
- uses: mcpguards/mcp-lock@v0.1.1
with:
sarif-output: mcp-lock.sarif
- uses: github/codeql-action/upload-sarif@v3
if: always()
with:
sarif_file: mcp-lock.sarif发现结果会出现在 Security → Code Scanning 选项卡中:
mcp-lock: server 'memory' integrity changed
The tarball integrity hash changed since last lock.
Run: mcp-lock update memoryAction 输入:
输入 | 默认值 | 描述 |
| (自动发现) | MCP 配置路径 |
|
| 如果没有锁文件则失败 |
| (无) | 写入 SARIF 报告的路径 |
锁文件
.mcp.lock 是一个你提交到仓库的 JSON 文件。它记录了:
{
"lockfileVersion": 1,
"generatedBy": "mcp-lock@0.1.0",
"generatedAt": "2026-04-16T12:00:00.000Z",
"scope": "project",
"servers": {
"filesystem": {
"source": {
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-filesystem"],
"configPath": "/abs/path/.mcp.json"
},
"resolved": {
"registry": "npm",
"name": "@modelcontextprotocol/server-filesystem",
"version": "2026.4.10",
"tarball": "https://registry.npmjs.org/...tgz",
"integrity": "sha512-AbC...==",
"shasum": "a1b2c3...",
"publishedAt": "2026-04-10T09:12:33.000Z"
},
"attestation": {
"present": true,
"predicateTypes": ["https://slsa.dev/provenance/v1"]
},
"lockedAt": "2026-04-16T12:00:00.000Z"
}
},
"checksum": "sha256-9f86d081..."
}checksum 字段是整个锁文件内容(规范化 JSON,键已排序)的 SHA-256 哈希值。如果文件在未运行 mcp-lock update 的情况下被手动编辑,verify 将会捕获到它。
支持的 MCP 客户端
自动发现你机器上的:
客户端 | 配置路径 |
Claude Desktop (macOS) |
|
Claude Code |
|
Cursor |
|
VS Code |
|
Windsurf |
|
Amazon Q |
|
项目级 | 当前目录下的 |
它与其他工具的区别
工具 | 检查 npm 包 | 完整性哈希 | 检测版本变更 | SBOM | 锁文件 |
Snyk Agent Scan | ❌ | ❌ | ❌ | ❌ | ❌ |
Cisco mcp-scanner | ❌ | ❌ | ❌ | ❌ | ❌ |
MCPWatch | ❌ | ❌ | ❌ | ❌ | ❌ |
mcp-lock | ✅ | ✅ | ✅ | ✅ | ✅ |
其他工具扫描工具描述和配置以查找提示注入。mcp-lock 将 MCP 服务器视为 软件供应链制品 并应用包完整性验证 — 这与 npm ci 使用的方法相同。
要求
Node.js >= 18.3.0
适用于 Claude Code、Cursor、VS Code Copilot、Windsurf、Amazon Q 以及任何使用 MCP 规范的工具
许可证
MIT © Vamshidhar Reddy Parupally
This server cannot be deployed
Maintenance
Related MCP Connectors
Scan any MCP server for tool-poisoning, security, auth & license. Trust score before install.
Cloud-hosted MCP server for durable AI memory
Pre-flight MCP security. Blocks compromised deps + tool drift. HMAC-signed. Dredd judges.
Security scanner for MCP servers. Detect vulnerabilities, prompt injection, and tool poisoning.
Related MCP Servers
- AlicenseNot gradedqualityAmaintenanceScans MCP servers for prompt injection, supply chain attacks, excessive permissions, and code execution risks. Includes an offline blacklist that catches known-compromised packages like LiteLLM 1.82.7/1.82.8 and Trivy with zero latency.19MIT
- AlicenseAqualityDmaintenanceThe MCP ecosystem is growing fast. Not every server on npm is safe. mcp-shield lets Claude audit any MCP server — local or from npm — before you trust it with your files, keys, and context.460 npm2MIT
- AlicenseNot gradedqualityCmaintenanceMCP server that vets package installations and shell commands to block dangerous actions by AI coding agents.7 npm1MIT
- AlicenseNot gradedqualityDmaintenanceAn account-free MCP server that checks AI-written changes before they are committed, detecting nonexistent packages, dependency risk shapes, and hardcoded secrets.MIT