subscribe-mcp
Exposes subscription insights to AI clients, including platform statistics and subscription plan information.
README
Subscribe MCP - SaaS Subscription Backend
A TypeScript/Express backend for a SaaS subscription workflow with Razorpay test payments, PostgreSQL persistence, Redis-backed background jobs, invoice emails, cached platform statistics, and an MCP server that exposes subscription insights to AI clients.
What This Project Includes
- Plan catalog seeded with Basic, Pro, and Premium subscription plans.
- Checkout API that creates Razorpay test orders.
- Verified Razorpay webhook endpoint for successful payment events.
- Subscription lifecycle handling with trial, active, failed, refunded, and expired states.
- PDF invoice generation and Mailtrap email delivery.
- Daily renewal scanner plus a BullMQ worker for renewal reminder emails.
- Redis-cached platform statistics.
- MCP tools for AI clients:
get_platform_statsget_plans
Tech Stack
| Area | Technology |
|---|---|
| Runtime | Node.js, TypeScript |
| API | Express |
| Database | PostgreSQL, Prisma |
| Cache and jobs | Redis, BullMQ |
| Payments | Razorpay test mode |
| Email testing | Mailtrap SMTP |
| Background scheduling | node-cron |
| AI integration | Model Context Protocol over stdio |
Prerequisites
Install these before running the project:
- Node.js 20 or newer
- npm, which is installed with Node.js
- Docker Desktop
- A free Razorpay test account
- A free Mailtrap account
- ngrok, only if you want to test live webhooks from Razorpay
Local Setup
- Install dependencies:
npm install
- Start PostgreSQL and Redis:
docker compose up -d
The Compose file starts:
| Service | Host URL |
|---|---|
| PostgreSQL | localhost:5433 |
| Redis | localhost:6379 |
- Create your local environment file:
cp .env.example .env
On Windows PowerShell:
Copy-Item .env.example .env
-
Fill in
.envusing the credential guide below. -
Apply database migrations:
npx prisma migrate deploy
- Seed the subscription plans:
npx prisma db seed
- Start the API server:
npm run dev
The server runs at:
http://localhost:3000
Environment Configuration
Use .env.example as the safe template. Never commit your real .env file.
Database and Redis
These values work with the included Docker Compose setup:
DATABASE_URL="postgresql://saas_user:saas_password@localhost:5433/saas_db?schema=public"
REDIS_URL="redis://localhost:6379"
Razorpay Test Credentials
- Create or log in to a Razorpay account.
- Switch to test mode in the Razorpay dashboard.
- Go to Account & Settings > API Keys.
- Generate a test key pair.
- Copy the values into
.env:
RAZORPAY_KEY_ID="rzp_test_xxxxxxxxxxxxx"
RAZORPAY_KEY_SECRET="your_test_secret"
For webhook testing, first run the API and ngrok tunnel. For the complete payment test, see Webhook Flow. ngrok prints a public Forwarding URL in the terminal, for example:
Forwarding https://abc123.ngrok-free.app -> http://localhost:3000
Copy that HTTPS URL and add /api/webhooks/payment at the end. Then add the full URL in the Razorpay dashboard:
Webhook URL: https://abc123.ngrok-free.app/api/webhooks/payment
Events: payment.captured, payment.failed
You can also see the full step-by-step Razorpay webhook instructions in .env.example.
Then copy the webhook signing secret into:
RAZORPAY_WEBHOOK_SECRET="your_webhook_secret"
Mailtrap SMTP Credentials
- Create or log in to Mailtrap.
- Open an Email Testing inbox.
- Copy the SMTP host, port, username, and password.
- Add them to
.env:
MAILTRAP_HOST="sandbox.smtp.mailtrap.io"
MAILTRAP_PORT="2525"
MAILTRAP_USER="your_mailtrap_username"
MAILTRAP_PASS="your_mailtrap_password"
MAILTRAP_FROM="billing@taskflow-demo.test"
Running the Application
Always open Docker Desktop first. PostgreSQL and Redis must be running before the app starts:
docker compose up -d
For the complete local demo, run everything together with one command:
npm run dev:all
This starts:
- API server on
http://localhost:3000 - ngrok tunnel for Razorpay webhooks
- renewal reminder worker
If you want to run each process separately, use the commands below.
Run the API only:
npm run dev
Run the renewal reminder worker in a separate terminal:
npm run worker
Run the ngrok tunnel in another terminal:
npm run tunnel
Open Prisma Studio to view database tables in the browser:
npx prisma studio
Build and run production output:
npm run build
npm start
Verify Everything Works
1. Check infrastructure
docker compose ps
You should see saas_postgres and saas_redis running.
2. Check the API
curl http://localhost:3000/health
Expected response:
{
"status": "ok",
"timestamp": "..."
}
You can also open the application in your browser:
http://localhost:3000
From there, select a plan and complete a Razorpay test payment. After payment succeeds, Razorpay sends the webhook to the ngrok URL, and the backend activates the subscription, generates the invoice, and sends the confirmation email.
3. Confirm plans were seeded
curl http://localhost:3000/api/plans
You should see the Basic, Pro, and Premium plans.
4. Create a checkout order
curl -X POST http://localhost:3000/api/checkout \
-H "Content-Type: application/json" \
-d "{\"name\":\"Demo User\",\"email\":\"demo@example.com\",\"planName\":\"Pro\"}"
Expected result:
- A new pending subscription is stored in PostgreSQL.
- A Razorpay test order is returned.
- The response includes the public Razorpay key id.
5. Verify platform stats
curl http://localhost:3000/api/stats
The first request computes stats from PostgreSQL. Repeated requests within 30 seconds should return cached stats from Redis.
6. Verify background processes
Start the worker:
npm run worker
In another terminal, manually trigger the renewal scanner:
curl -X POST http://localhost:3000/api/dev/trigger-renewal-scan
Expected behavior:
- The API activates any expired trials.
- Subscriptions expiring within 3 days are queued in Redis.
- The worker processes queued renewal reminders.
- Renewal emails appear in Mailtrap.
Webhook Flow
For a full payment test:
- Start the API:
npm run dev
- Start ngrok:
npm run tunnel
- Copy the HTTPS
ForwardingURL printed by ngrok:
Forwarding https://abc123.ngrok-free.app -> http://localhost:3000
- Add
/api/webhooks/paymentto that URL and paste it into the Razorpay webhook settings:
https://abc123.ngrok-free.app/api/webhooks/payment
- Select these webhook events:
payment.captured
payment.failed
- Save the webhook and copy the webhook signing secret into
RAZORPAY_WEBHOOK_SECRETin.env. - Restart the API after changing
.env. - Create a checkout order through
POST /api/checkout. - Complete the payment in Razorpay test mode.
- Razorpay sends the webhook to the public ngrok URL, and ngrok forwards it to
http://localhost:3000/api/webhooks/payment. - The API verifies the signature, activates the subscription, generates an invoice, and sends a confirmation email through Mailtrap.
API Reference
| Method | Endpoint | Purpose |
|---|---|---|
GET |
/health |
Health check |
GET |
/api/plans |
List available plans |
POST |
/api/checkout |
Create a subscription and Razorpay order |
POST |
/api/webhooks/payment |
Receive Razorpay webhook events |
GET |
/api/stats |
Get cached platform statistics |
POST |
/api/dev/trigger-renewal-scan |
Manually run the renewal scanner |
Checkout request body:
{
"name": "Demo User",
"email": "demo@example.com",
"planName": "Pro"
}
Expose the MCP Tool to an AI Client
The MCP server runs over stdio and uses the same .env values as the API.
Run it directly:
npm run mcp
You do not need to run this every time. Run npm run mcp only when you want to test the MCP server directly or connect it to an AI client.
Supported AI Desktop Clients
The easiest desktop app for this setup is Claude Desktop, because it supports local stdio MCP servers with an mcpServers JSON config.
Other MCP-compatible tools may also work, such as Claude Code, Cursor, Windsurf, VS Code MCP extensions, or any AI client that supports local stdio MCP servers. Their setup screens may be different, but the same command, args, and cwd values are used.
Add This MCP Server in Claude Desktop
- Make sure the backend setup is complete:
docker compose up -d
npx prisma migrate deploy
npx prisma db seed
-
Make sure
.envexists and has the required database, Redis, Razorpay, and Mailtrap values. -
Open Claude Desktop.
-
Open Settings > Developer > Edit Config.
On Windows, Claude Desktop opens this file:
%APPDATA%\Claude\claude_desktop_config.json
- Add this MCP server config:
{
"mcpServers": {
"saas-platform-stats": {
"command": "npm",
"args": ["run", "mcp"],
"cwd": "/absolute/path/to/saas-backend"
}
}
}
On this machine, the project path is:
D:\Bitcot-Task\saas-backend
For Windows-based clients, use escaped backslashes:
{
"mcpServers": {
"saas-platform-stats": {
"command": "npm",
"args": ["run", "mcp"],
"cwd": "D:\\Bitcot-Task\\saas-backend"
}
}
}
-
Save the config file.
-
Fully quit and reopen Claude Desktop.
-
Start a new Claude chat and ask:
Use the saas-platform-stats MCP server and show me the available subscription plans.
You should see Claude use the get_plans tool.
Example AI prompts you can ask:
How many active subscribers do we have right now?
What subscription plans do we offer?
What's the price of the Pro plan?
How much total revenue have we generated so far?
You do not need to run npm run mcp manually when Claude Desktop is configured. Claude Desktop starts the MCP server automatically from the config. Run npm run mcp manually only when you want to test the MCP server directly from the terminal.
Available MCP tools:
| Tool | Description |
|---|---|
get_platform_stats |
Returns active subscribers, trialing subscribers, total revenue, and revenue by plan |
get_plans |
Returns the available subscription plans with pricing, trials, and features |
Before using MCP, make sure PostgreSQL and Redis are running and the database has been migrated and seeded.
Project Structure
src/
config/ Environment and Redis configuration
controllers/ Express request handlers
db/ Prisma client
jobs/ Cron scanner, BullMQ queue, and worker
mcp/ MCP stdio server
routes/ API route registration
services/ Business logic for payments, subscriptions, stats, invoices, email
prisma/
schema.prisma Database schema
seed.ts Default plan seed data
public/ Static assets
storage/ Generated invoice files
Troubleshooting
| Problem | Fix |
|---|---|
Missing required environment variable |
Confirm .env exists and all required keys from .env.example are filled in |
| Cannot connect to PostgreSQL | Run docker compose up -d and confirm the database is on port 5433 |
| Cannot connect to Redis | Confirm saas_redis is running and REDIS_URL is redis://localhost:6379 |
| No plans returned | Run npx prisma migrate deploy and npx prisma db seed |
| Razorpay webhook rejected | Confirm RAZORPAY_WEBHOOK_SECRET matches the webhook secret in Razorpay |
| Emails not appearing | Confirm Mailtrap SMTP credentials and keep npm run worker running for renewal reminders |
| MCP client cannot start server | Use an absolute cwd, confirm .env is present, and test npm run mcp manually |
Author
For any queries, contact sharifasheriff26@gmail.com.
LinkedIn: sharifa-sheriff
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。