DEV Community

Mazen Atlas
Mazen Atlas

Posted on

How to Monetize a Streamable HTTP MCP Server in Node.js (Zero Dependencies)

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:

  1. Hash API keys with SHA-256 and compare with crypto.timingSafeEqual so timing attacks can't leak valid tokens, and map each key to a plan tier (free, pro, enterprise).
  2. Enforce sliding-window rate limits per key based on plan tier and return standard 429 + X-RateLimit-* and Retry-After headers.
  3. Verify Stripe webhooks with raw-body HMAC-SHA256 + timestamp tolerance, provisioning a new mcp_live_... API key on checkout.session.completed and revoking it automatically on customer.subscription.deleted.
  4. Ship with end-to-end node:test integration tests covering auth rejection (401/403), Stripe checkout -> live MCP tools/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)