feat(#9): add bearer token auth for HTTP transport (#12)

* feat(#9): add bearer token auth for HTTP transport

Adds NPM_MCP_AUTH_TOKEN env var. When set, HTTP transport requires
Authorization: Bearer <token> on all requests except /health.
Uses timing-safe comparison via hmac.compare_digest.

Closes #9

* fix(auth): fix lifespan context and 401 status/headers spec compliance

---------

Co-authored-by: b3nw <189466+b3nw@users.noreply.github.com>
This commit is contained in:
b3nwandb3nw authored and GitHub committed 2026-08-11 19:54:01 -05:00
1 parent 2278c97d9d
commit 21bce2ad91
7 files changed
+135 -3

No files matched your search

+2
View File
@@ -18,6 +18,8 @@ services:
- NPM_MCP_PORT=8000
# Optional: Enable write/destructive operations (default: disabled)
# - NPM_MCP_ENABLE_DESTRUCTIVE_TOOLS=true
# Optional: Require bearer token for MCP HTTP clients
# - NPM_MCP_AUTH_TOKEN=your-secret-token-here
# Optional: Log access (requires volume mount below)
# - NPM_LOG_DIR=/data/npm-logs
# volumes: