Drop-in billing, paywalls & credit middleware for MCP servers with Dodo & Stripe
About
Drop-in billing, credit tracking, and paywall middleware for Model Context Protocol (MCP) servers. Enables AI agent developers to monetize tools in Claude Desktop, Cursor, and Windsurf with usage quotas, sub-0.2ms PASETO v4 capability tokens, and interactive in-chat payment links via Dodo Payments and Stripe.
Security Report
Valid MCP server (1 strong, 3 medium validity signals). No known CVEs in dependencies. Package registry verified. Imported from the Official MCP Registry.
12 files analyzed ยท 1 issue found
Security scores are indicators to help you make informed decisions, not guarantees. Always review permissions before connecting any MCP server.
Permissions Required
This plugin requests these system permissions. Most are normal for its category.
What You'll Need
Set these up before or after installing:
Environment variable: MCP_MONETIZE_SECRET
Sign up freeEnvironment variable: DODO_PAYMENTS_WEBHOOK_KEY
Sign up freeHow to Install
Add this to your MCP configuration file:
{
"mcpServers": {
"mcp-monetize": {
"command": "npx",
"args": [
"-y",
"@ritualdev-lab/mcp-monetize@0.1.0"
],
"env": {
"MCP_MONETIZE_SECRET": "your-mcp-monetize-secret-here",
"DODO_PAYMENTS_WEBHOOK_KEY": "your-dodo-payments-webhook-key-here"
}
}
}
}Some servers take additional arguments. See the repository for details.
Getting Started
Once installed, try these example prompts and explore these capabilities:
- 1"Check remaining MCP credit balance: get_balance"
- 2"Generate an in-chat top-up checkout link: create_checkout"
- 3"Verify PASETO capability token: verify_token <token>"
- 4Tool: check_quota: Checks real-time tool invocation allowances and credits
Documentation
View on GitHubFrom the project's GitHub README.
Drop-in billing, credit tracking, and paywall middleware for Model Context Protocol (MCP) servers.
Monetize your AI agent tools in 3 lines of code with Dodo Payments & Stripe.
โก The Problem
Developers are publishing thousands of Model Context Protocol (MCP) servers for Claude Desktop, Cursor, and Windsurf. But until now:
- There was no standard way to charge users per tool invocation or per month.
- Tool creators bear the heavy server, LLM API, and scraping costs while users consume unlimited queries for free.
mcp-monetize solves this by giving MCP server creators an effortless 3-line drop-in middleware that manages quotas, verifies credits, and returns interactive payment links directly inside the agent chat when quotas run out.
mcp-monetize vs. mcp-builder-kit
| Package | Role | When to Use |
|---|---|---|
mcp-monetize (this repo) | Commercial Billing Clearinghouse & Paywall SDK | Monetizing MCP tool invocations with Universal Pre-Paid MCP Credits, usage quotas, Dodo Payments / Stripe checkout links, and webhook-driven credit settlement. |
@ritualdev-lab/mcp-builder-kit (RitualDev-Lab/mcp-builder-kit) | Free Open-Source (Apache-2.0) MCP Scaffolding CLI | Bootstrapping TypeScript/Python MCP servers (stdio / streamable-http), wrapping tools with --with-agentshield redaction, converting OpenAPI/GraphQL/Protobuf specs, and running protocol conformance tests. |
๐ Quickstart (3 Lines of Code)
1. Install
npm install @ritualdev-lab/mcp-monetize
# or
pnpm add @ritualdev-lab/mcp-monetize
2. Wrap your MCP tool handler
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
import { withMcpMonetization } from "@ritualdev-lab/mcp-monetize";
import { z } from "zod";
const server = new McpServer({ name: "market-oracle", version: "1.0.0" });
server.tool(
"query_stock_valuation",
{ ticker: z.string() },
withMcpMonetization(
async ({ ticker }) => {
const data = await fetchValuation(ticker);
return { content: [{ type: "text", text: `Valuation for ${ticker}: $142.50` }] };
},
{
// Your Dodo Payments or Stripe payment link
checkoutUrl: "https://checkout.dodopayments.com/buy/pdt_0NpjONGugY5QkrFDUaPva",
priceLabel: "$5 for 1,000 queries",
freeTierCalls: 5 // 5 free queries for every new user
}
)
);
๐ผ๏ธ How the Agent Sees the Paywall
When a user in Claude Desktop, Cursor, or Windsurf exhausts their free calls, the agent automatically receives structured markdown prompting the user to top up:
๐ Usage Limit Reached for `query_stock_valuation`
Your complimentary tool credits have been exhausted. To continue executing queries with uninterrupted speed:
### ๐ณ Unlock Instant Access ($5 for 1,000 queries)
๐ [Click Here to Activate / Top-Up Credits via Secure Checkout](https://checkout.dodopayments.com/buy/pdt_xyz)
---
*User Ref: `dev_client_01` โข Payments securely powered by Dodo Payments & Stripe.*
Once the user completes payment via UPI, Credit Card, or Apple Pay, their webhook or API key activates paid credits and execution resumes seamlessly!
โ๏ธ Configuration Options
| Option | Type | Default | Description |
|---|---|---|---|
checkoutUrl | string | (userId: string) => string | Required | Dodo Payments product link or Stripe Payment link. Can be dynamic function. |
freeTierCalls | number | 5 | Number of free calls given to each new user before paywall triggers. |
priceLabel | string | "$0.05 / call" | Pricing description displayed inside the paywall message. |
provider | "dodo" | "stripe" | "custom" | "dodo" | Payment provider tag. |
store | TokenStore | MemoryTokenStore | Storage engine (MemoryTokenStore or JsonFileTokenStore). |
getUserId | (args, extra) => string | Automatic | Custom function to extract workspace or user ID. |
customPaywallMessage | (info) => string | Standard template | Optional custom paywall markdown generator. |
๐พ Storage Adapters
1. In-Memory (Default)
Fastest, zero-dependency. Great for local desktop tools.
import { MemoryTokenStore } from "mcp-monetize";
const store = new MemoryTokenStore(5);
2. SQLite Database Persistence
Built-in node:sqlite store with zero native dependencies. Supports thread-safe transactions and atomic balances.
import { SqliteTokenStore } from "mcp-monetize/adapters/sqlite";
const store = new SqliteTokenStore("./data/mcp-credits.sqlite", 10);
3. Serverless Redis / Upstash
Designed for cloud-hosted MCP servers (Render, Fly.io, Railway, AWS Lambda).
import { RedisTokenStore } from "mcp-monetize/adapters/redis";
const store = new RedisTokenStore({
url: process.env.UPSTASH_REDIS_REST_URL!,
token: process.env.UPSTASH_REDIS_REST_TOKEN!,
defaultFreeCredits: 10
});
4. JSON File Persistence
Zero database dependencies; persists user credits across server restarts in mcp-credits.json.
import { JsonFileTokenStore } from "mcp-monetize";
const store = new JsonFileTokenStore("./data/credits.json", 10);
๐ค Webhook Fulfillment Engine (Turnkey Dodo & Stripe)
Use the built-in PaymentWebhookHandler to process checkouts and replenish user credits automatically:
import { PaymentWebhookHandler, SqliteTokenStore } from "mcp-monetize";
const store = new SqliteTokenStore("./data/tokens.sqlite");
const webhooks = new PaymentWebhookHandler({
store,
dodoWebhookSecret: process.env.DODO_WEBHOOK_SECRET || process.env.DODO_PAYMENTS_WEBHOOK_KEY,
stripeWebhookSecret: process.env.STRIPE_WEBHOOK_SECRET
});
// In your Express or Fastify server:
app.post("/api/webhooks/dodo", async (req, res) => {
const result = await webhooks.handleDodoWebhook(req.body, req.headers["x-dodo-signature"]);
res.status(result.success ? 200 : 400).json(result);
});
๐ Cryptographic License Key Verification
For off-line or client-side MCP distribution (where users supply a license key in claude_desktop_config.json):
import { McpLicenseValidator } from "mcp-monetize";
const validator = new McpLicenseValidator("your_hmac_secret_key_min_32_chars");
// Issue a 30-day license key:
const token = validator.generateLicenseKey("user_456", 30);
// Verify inside your tool:
const check = validator.verifyLicense(token);
if (check.valid) {
console.log(`Verified user ${check.userId}, expires: ${check.expiresAt}`);
}
๐ฆ Turnkey Starter Kit & Production Examples
Looking for ready-to-deploy boilerplates? Check the examples/ directory:
examples/01-weather-api-server.tsโ Pay-per-query API ($5 for 500 calls).examples/02-sql-agent-server.tsโ Monthly recurring subscription with HMAC license verification.examples/03-web-scraper-server.tsโ Usage credits with turnkey Dodo checkout webhook.
๐ Get the complete package with instant setup at ritualdev.in/mcp-starter-kit.
๐ License
MIT ยฉ RitualDev Lab
๐ Sponsor & Support
If you find this project valuable, consider supporting our open-source development:
๐ก๏ธ Community & Governance
Reviews
No reviews yet
Be the first to review this server!
Version History
More Developer Tools MCP Servers
Rea
Freeby Morluto ยท Developer Tools
Reverse engineer anything from your terminal or agent with one CLI and MCP server.
Paperclip
Freeby Paperclipai ยท Developer Tools
Trending hip-hop artist momentum scores across four cultural dimensions.
Scrapling
Freeby D4Vinci ยท Developer Tools
Web scraping with stealth HTTP, real browsers, and Cloudflare bypass. CSS selectors supported.
Toleno
Freeby Toleno ยท Developer Tools
Toleno Network MCP Server โ Manage your Toleno mining account with Claude AI using natural language.
MCP Marketplace
Freeby mcp-marketplace ยท Developer Tools
Search and install MCP servers from inside your AI client.
mcp-creator-python
Freeby mcp-marketplace ยท Developer Tools
Create, build, and publish Python MCP servers to PyPI โ conversationally.