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

+3
View File
@@ -11,6 +11,9 @@ NPM_MCP_TRANSPORT=stdio # stdio or http
# Enable destructive/write operations (create, update, delete, enable, disable)
# NPM_MCP_ENABLE_DESTRUCTIVE_TOOLS=true
# Optional: Require bearer token for MCP HTTP clients
# NPM_MCP_AUTH_TOKEN=your-secret-token-here
# Log Access (optional)
# Mount NPM's /data/logs directory and set this to the mount path.
# Enables the get_proxy_host_logs tool for reading nginx access/error logs.