If you're building a Model Context Protocol (MCP) server for developers or teams, the hardest part usually isn't the tool logic—it's gating access cleanly when you want to charge for it.
Here's the minimal architecture that works reliably in Node.js 20+ without heavy dependencies:
-
Hash API keys with SHA-256 and compare with
crypto.timingSafeEqualso timing attacks can't leak valid tokens, and map each key to a plan tier (free,pro,enterprise). -
Enforce sliding-window rate limits per key based on plan tier and return standard
429+X-RateLimit-*andRetry-Afterheaders. -
Verify Stripe webhooks with raw-body HMAC-SHA256 + timestamp tolerance, provisioning a new
mcp_live_...API key oncheckout.session.completedand revoking it automatically oncustomer.subscription.deleted. -
Ship with end-to-end
node:testintegration tests covering auth rejection (401/403), Stripe checkout -> live MCPtools/call-> cancellation revocation, and rate-limit enforcement (429).
If you want this full working codebase + integration test suite ready to drop your own MCP tools into and deploy in 2 minutes, I packaged it as MCP LaunchKit ($29 one-time, MIT commercial license):
https://fieldnote45.gumroad.com/l/jxzzow
Happy to answer any questions on Streamable HTTP MCP auth, rate limiting, or Stripe webhook patterns in the comments!
Top comments (0)