
mcplock
io.github.apexhive-hq/mcplock
Runtime lock, SHA-256 digest & drift/poisoning detection for MCP tool lists (SARIF 2.1.0 & MCP).
Documentation
mcplock
Runtime lock and verification for Model Context Protocol tool lists.
mcplock records a SHA-256 digest of each MCP tool's name, description, inputSchema, and annotations, then fail-closes when a previously trusted server silently changes that contract. It is a runtime lock and change detector, not a static linter.
What it detects
- Silent rug pull — a trusted server later changes tool names, descriptions, schemas, or annotations without an explicit re-approval
- Description poisoning — hidden instruction language, prompt hijacking, policy override text, or stealth Unicode in tool text
- Dangerous parameter additions — new schema fields that look like shell, credential, or path-control knobs
- Schema drift — any
inputSchemachange against the lockfile
Reports can be printed as a human-readable diff, JSON, or SARIF 2.1.0. Lock history is kept for at least 30 days in a local SQLite store (Node.js 24 built-in node:sqlite).
Requirements
- Node.js 24 or later (
node:sqliteis used; no native addons)
Install
Run directly from any directory via npm (no cloning required):
npx -y @apexhive.hq/mcplock --demo
npx -y @apexhive.hq/mcplock --help
Or install globally from npm:
npm install -g @apexhive.hq/mcplock
Or install from source: npm install -g ./mcplock must be run from the parent directory of the mcplock package folder (the directory that contains the mcplock folder, not from inside the package itself):
npm install -g ./mcplock
From inside the package folder, install the current directory instead:
npm install -g .
Or run from the project root without a global install:
node bin/mcplock.js --help
Quick start
Lock a static tool list (MCP tools/list shape or { "tools": [ ... ] }):
node bin/mcplock.js lock --input examples/clean-tools.json
This writes mcplock.lock.json in the current directory and records an approved snapshot in .mcplock/store.sqlite.
Verify a later list against that lockfile:
node bin/mcplock.js verify --input examples/poisoned-tools.json
node bin/mcplock.js verify --input examples/rugpull-tools.json --format json
node bin/mcplock.js verify --input examples/schema-drift-tools.json --format sarif --out verify.sarif
verify exits 1 when any error-level finding is present, including without --ci. --ci is the non-interactive CI mode and uses the same fail-closed exit code:
node bin/mcplock.js verify --input examples/rugpull-tools.json --ci --format json
Lock or verify a local stdio MCP server (the command is executed locally, never fetched remotely):
node bin/mcplock.js lock --stdio "node examples/demo-server.js"
node bin/mcplock.js verify --stdio "node examples/demo-server.js"
After a legitimate change, re-approve a new baseline explicitly. Verification stays fail-closed until you do:
node bin/mcplock.js unlock --input examples/schema-drift-tools.json --approve
Inspect state and the audit log:
node bin/mcplock.js status
node bin/mcplock.js audit
Built-in demo
The demo walks through a clean lock followed by poisoned, rug-pulled, drifted, and dangerous-parameter lists. It uses the bundled examples and a temporary store, and it exits 0 only when every expected finding is detected.
node bin/mcplock.js --demo
node bin/mcplock.js demo
CLI
--help output (kept 1:1 with node bin/mcplock.js --help):
mcplock 1.0.0
Runtime lock and verification for Model Context Protocol tool lists.
Records SHA-256 digests of tool names, descriptions, inputSchema, and annotations,
then fail-closes on silent changes, description poisoning, dangerous parameter
additions, and schema drift.
Usage:
mcplock <command> [options]
Commands:
init Create the local SQLite store
lock Snapshot and lock the current tool list
verify Compare the current tool list to the lockfile (fail-closed; exits 1 on error-level findings)
status Show lockfile, store, and recent history
audit Show the audit log
unlock Explicitly approve a new baseline after review
demo Run the built-in detection walkthrough
Input:
--input <path> Static tools JSON (tools/list shape or { "tools": [...] })
--stdio <command> Launch a local stdio MCP server and call tools/list
--cwd <path> Working directory for --stdio
Output and paths:
--format <type> human | json | sarif (default: human)
--out <path> Write the report to a file
--ci Non-interactive CI mode; exit 1 on error-level findings
--lockfile <path> Lockfile path (default: mcplock.lock.json)
--store <path> SQLite store path (default: .mcplock/store.sqlite)
--approve Required for unlock
--timeout <ms> Stdio handshake timeout in milliseconds (default: 15000, min: 1, max: 300000)
Other:
--help, -h Show this help
--version, -v Show the version
--demo Alias for the demo command
Examples:
mcplock lock --input examples/clean-tools.json
mcplock verify --input examples/poisoned-tools.json
mcplock verify --input examples/rugpull-tools.json --format sarif --out verify.sarif
mcplock verify --input examples/schema-drift-tools.json --ci --format json
mcplock lock --stdio "node examples/demo-server.js"
mcplock unlock --input examples/schema-drift-tools.json --approve
mcplock --demo
Lockfile format
mcplock.lock.json is a standalone, reproducible snapshot. Each tool digest is SHA-256 over a canonical encoding of:
namedescriptioninputSchemaannotations(default{}when omitted)
Canonical encoding uses sorted object keys and stable array order. The lockfile also stores a top-level lockDigest over the ordered list of tool digests.
stdio MCP server
mcplock can run as a stdio MCP server and expose lock, verify, status, audit, and unlock tools to an agent:
node bin/mcplock-mcp.js
Examples
| File | Purpose |
|---|---|
examples/clean-tools.json | Trusted baseline |
examples/poisoned-tools.json | Description / hidden-instruction injection |
examples/rugpull-tools.json | Silent tool rename and description change |
examples/schema-drift-tools.json | inputSchema type and property drift |
examples/dangerous-params-tools.json | Newly added dangerous parameters |
examples/stealth-unicode-tools.json | Zero-width and bidirectional stealth characters |
examples/demo-server.js | Minimal stdio MCP server (profile via MCPLOCK_DEMO_PROFILE) |
Tests
npm test
npm run test:e2e
npm run typecheck
npm run build:prod
Requires Node.js 24+. npm test runs the unit and integration suite (poison detection, rug-pull fail-closed behavior, 30-day history, the CLI, the stdio MCP server, SARIF 2.1.0 output, and the MIT LICENSE). npm run test:e2e is a separate end-to-end entry that walks the documented CLI, examples, stdio, unlock, and --demo flows in a temporary directory. typecheck runs the TypeScript compiler (tsc --noEmit --checkJs). build:prod is a separate production build that writes runtime files and apexhive.hq-mcplock-1.0.0.tgz under dist/. The same typecheck, production build, unit, and end-to-end commands run in CI (.github/workflows/ci.yml) on Node.js 24.20.0 with pnpm 12.5.1, followed by pnpm pack --dry-run (this does not publish the package).
License
MIT. See LICENSE. How to report vulnerabilities is described in SECURITY.md. Changes are recorded in CHANGELOG.md.
@apexhive.hq/mcplocknpm install @apexhive.hq/mcplockRelated Servers
io.github.apexhive-hq/burnguard
Local AI API & agent spend circuit breaker: HTTP gateway, SQLite ledger, KILL file & MCP.
io.github.apexhive-hq/slimmcp-proxy
Meta-MCP proxy for stdio and HTTP/SSE upstreams with BM25 discovery and secret redaction.
io.github.apexhive-hq/slimquant
Deterministic quant risk gate, purged walk-forward backtest, and audit ledger MCP server.