Command Palette

Search for a command to run...

UnylyUnyly
Browse all

PayGate 402

FreeNot checked

Wraps existing APIs and MCP servers to add payment monetization using HTTP 402, supporting Stripe, PayPal, and Lightning Network.

GitHubEmbed

About

Wraps existing APIs and MCP servers to add payment monetization using HTTP 402, supporting Stripe, PayPal, and Lightning Network.

README

license status typescript node PRs

Turn any API or MCP server into a paid service

table of contents

install

npm install paygate-402

usage

wrap an existing API

import { PayGate } from 'paygate-402';

const paygate = new PayGate({
  provider: 'stripe',
  apiKey: process.env.STRIPE_KEY,
  pricing: {
    perRequest: 0.01,
    perToken: 0.0001
  }
});

// wrap your express app
app.use(paygate.middleware());

// or wrap specific routes
app.get('/api/premium', paygate.protect(), (req, res) => {
  res.json({ data: 'premium content' });
});

wrap an MCP server

import { MCPPayGate } from 'paygate-402/mcp';
import { Server } from '@modelcontextprotocol/sdk/server/index.js';

const server = new Server({
  name: 'my-mcp-server',
  version: '1.0.0'
});

const paygate = new MCPPayGate({
  provider: 'stripe',
  apiKey: process.env.STRIPE_KEY,
  pricing: {
    perTool: {
      'expensive_tool': 0.10,
      'cheap_tool': 0.01
    }
  }
});

paygate.wrap(server);

client usage

import axios from 'axios';

const response = await axios.get('https://api.example.com/premium', {
  headers: {
    'Authorization': 'Bearer YOUR_PAYMENT_TOKEN'
  }
});

// handle 402 Payment Required
if (response.status === 402) {
  const paymentUrl = response.headers['payment-url'];
  console.log('Payment required:', paymentUrl);
}

api

PayGate(options)

Creates a new payment gateway instance.

Options:

Option Type Description
provider string Payment provider ('stripe', 'paypal', 'lightning')
apiKey string Provider API key
pricing PricingConfig Pricing configuration
allowCredits boolean Allow prepaid credits (default: true)
quotaLimits QuotaConfig Optional rate limits per user

paygate.middleware()

Returns Express middleware that intercepts requests and enforces payment.

paygate.protect(options?)

Returns middleware for protecting specific routes.

Options:

Option Type Description
price number Override default price for this route
creditsRequired number Require specific credit amount

paygate.createPaymentToken(userId, credits)

Generates a payment token for a user with prepaid credits.

Returns: Promise<string>

paygate.checkBalance(token)

Checks remaining balance for a payment token.

Returns: Promise<{ credits: number, spent: number }>

configuration

pricing models

// per-request pricing
{
  pricing: {
    perRequest: 0.05
  }
}

// token-based pricing (for LLM APIs)
{
  pricing: {
    perToken: 0.0001,
    perInputToken: 0.00005,
    perOutputToken: 0.00015
  }
}

// route-specific pricing
{
  pricing: {
    routes: {
      '/api/basic': 0.01,
      '/api/premium': 0.10,
      '/api/enterprise': 1.00
    }
  }
}

// credit bundles
{
  pricing: {
    bundles: [
      { credits: 100, price: 9.99 },
      { credits: 500, price: 44.99 },
      { credits: 1000, price: 79.99 }
    ]
  }
}

payment providers

stripe

{
  provider: 'stripe',
  apiKey: process.env.STRIPE_SECRET_KEY,
  webhookSecret: process.env.STRIPE_WEBHOOK_SECRET
}

paypal

{
  provider: 'paypal',
  clientId: process.env.PAYPAL_CLIENT_ID,
  clientSecret: process.env.PAYPAL_CLIENT_SECRET,
  sandbox: true
}

lightning network

{
  provider: 'lightning',
  lndHost: process.env.LND_HOST,
  macaroon: process.env.LND_MACAROON,
  cert: process.env.LND_CERT
}

http 402

This project uses HTTP status code 402 (Payment Required) as defined in RFC 7231. When a request requires payment, the server responds with:

HTTP/1.1 402 Payment Required
Payment-URL: https://pay.example.com/checkout/xyz123
Payment-Amount: 0.05
Payment-Currency: USD
Content-Type: application/json

{
  "error": "payment_required",
  "amount": 0.05,
  "currency": "USD",
  "payment_url": "https://pay.example.com/checkout/xyz123"
}

contributing

PRs welcome. Open an issue first for big changes.

Run tests:

npm test

license

MIT

from github.com/jmerelnyc/paygate-402

Installing PayGate 402

This server has no published package — it is built from source. Open the repository and follow its README.

▸ github.com/jmerelnyc/paygate-402

FAQ

Is PayGate 402 MCP free?

Yes, PayGate 402 MCP is free — one-click install via Unyly at no cost.

Does PayGate 402 need an API key?

No, PayGate 402 runs without API keys or environment variables.

Is PayGate 402 hosted or self-hosted?

Self-hosted: the server runs locally on your machine via the install command above.

How do I install PayGate 402 in Claude Desktop, Claude Code or Cursor?

Open PayGate 402 on unyly.org, pick your client tab (Claude Desktop, Claude Code, Cursor) and press Install — the config is generated automatically, no JSON editing.

Related MCPs

$5

Stripe

Payments, customers, subscriptions

Stripeby Stripe

malamutemayhem/unclick-agent-native-endpoints

110+ tools for AI agents spanning social media, finance, gaming, music, AU-specific services, and utilities. Zero-config local tools plus platform connectors. n

malamutemayhemby malamutemayhem

whiteknightonhorse/APIbase

API hub covering travel (Amadeus, Sabre), Polymarket prediction markets, crypto and weather, paid per call via x402 in USDC.

whiteknightonhorseby whiteknightonhorse

trackerfitness729-jpg/sitelauncher-mcp-server

Deploy live HTTPS websites on subdomains or custom .xyz domains, paid in USDC on Base, with templates for crypto tokens and AI agent profiles.

trackerfitness729-jpgby trackerfitness729-jpg

embeddedlayers/mcp-analytics

Statistical analysis, forecasting and ML on CSV files or live data from Shopify, Stripe, GA4 and more, with interactive HTML reports.

embeddedlayersby embeddedlayers

carrierone/verilexdata-mcp

Pay-per-query x402 datasets: NPI healthcare, SEC filings, OFAC sanctions, crypto whales, Polymarket signals, patents and economic indicators.

carrieroneby carrierone

paracetamol951/P-Link-MCP

HTTP 402 (Payment Required) implementation using Solana.

paracetamol951by paracetamol951

tipdotmd/tip-md-x402-mcp-server

Cryptocurrency tipping using the x402 payment protocol and CDP Wallet.

tipdotmdby tipdotmd

laundromatic/shopgraph

Structured product data from the open web — Schema.org + AI extraction for e-commerce enrichment. Pay per call via Stripe. [shopgraph.dev](https://shopgraph.dev

laundromaticby laundromatic

mrslbt/xendit-mcp

Xendit payment gateway for Southeast Asia: invoices, disbursements, balance checks and bank transfers.

mrslbtby mrslbt

Compare PayGate 402 with

Not sure what to pick?

Find your stack in 60 seconds

Author?

Embed badge for your README

Browse similar

All finance MCPs