paygate-mcp 8.10.0 → 8.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +19 -0
- package/dist/server.d.ts +1 -0
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +90 -0
- package/dist/server.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -117,6 +117,7 @@ Agent → PayGate (auth + billing) → Your MCP Server (stdio or HTTP)
|
|
|
117
117
|
- **Traffic Analysis** — `GET /admin/traffic` request volume analysis with tool popularity, hourly volume, top consumers by call count, namespace breakdown, peak hour identification, and success rates
|
|
118
118
|
- **Security Audit** — `GET /admin/security` security posture analysis identifying keys without IP allowlists, quotas, ACL restrictions, spending limits, or expiry dates, flagging high-credit keys, and computing a composite security score
|
|
119
119
|
- **Revenue Analysis** — `GET /admin/revenue` revenue metrics with per-tool revenue breakdown, per-key spending, hourly revenue trends, credit flow summary (allocated/spent/remaining), and average revenue per call
|
|
120
|
+
- **Key Portfolio Health** — `GET /admin/key-portfolio` portfolio-wide key health with active/inactive/suspended counts, stale keys, expiring-soon keys, age distribution, credit utilization, and namespace breakdown
|
|
120
121
|
- **Config Hot Reload** — `POST /config/reload` reloads pricing, rate limits, webhooks, quotas, and behavior flags from config file without server restart
|
|
121
122
|
- **Webhook Events** — POST batched usage events to any URL for external billing/alerting
|
|
122
123
|
- **Config File Mode** — Load all settings from a JSON file (`--config`)
|
|
@@ -2695,6 +2696,24 @@ curl http://localhost:3000/admin/revenue -H "X-Admin-Key: YOUR_ADMIN_KEY"
|
|
|
2695
2696
|
|
|
2696
2697
|
Returns revenue summary with total credits earned, per-tool revenue ranked by earnings with average per-call, top 10 per-key spending, hourly revenue trends (last 24 hours), and credit flow showing total allocated vs spent vs remaining across all active keys. Only counts successful (allowed) calls. Read-only.
|
|
2697
2698
|
|
|
2699
|
+
### Key Portfolio Health
|
|
2700
|
+
|
|
2701
|
+
```bash
|
|
2702
|
+
curl http://localhost:3000/admin/key-portfolio -H "X-Admin-Key: YOUR_ADMIN_KEY"
|
|
2703
|
+
```
|
|
2704
|
+
|
|
2705
|
+
```json
|
|
2706
|
+
{
|
|
2707
|
+
"summary": { "totalKeys": 10, "activeKeys": 7, "inactiveKeys": 2, "suspendedKeys": 1, "averageCreditUtilization": 0.35 },
|
|
2708
|
+
"staleKeys": [{ "name": "unused-key", "createdAt": "2025-01-01T00:00:00Z", "credits": 500, "ageDays": 30 }],
|
|
2709
|
+
"expiringSoon": [{ "name": "temp-key", "expiresAt": "2025-01-20T00:00:00Z", "hoursRemaining": 48, "credits": 100 }],
|
|
2710
|
+
"ageDistribution": { "averageAgeDays": 15, "oldestAgeDays": 60, "newestAgeDays": 0 },
|
|
2711
|
+
"byNamespace": [{ "namespace": "production", "total": 5, "active": 4, "suspended": 1 }]
|
|
2712
|
+
}
|
|
2713
|
+
```
|
|
2714
|
+
|
|
2715
|
+
Returns portfolio-wide key health: active/inactive/suspended counts, average credit utilization, stale keys (created but never used), keys expiring within 7 days sorted by urgency, age distribution statistics, and namespace breakdown. Read-only.
|
|
2716
|
+
|
|
2698
2717
|
### IP Allowlisting
|
|
2699
2718
|
|
|
2700
2719
|
Restrict API keys to specific IP addresses or CIDR ranges:
|
package/dist/server.d.ts
CHANGED
|
@@ -252,6 +252,7 @@ export declare class PayGateServer {
|
|
|
252
252
|
private handleTrafficAnalysis;
|
|
253
253
|
private handleSecurityAudit;
|
|
254
254
|
private handleRevenueAnalysis;
|
|
255
|
+
private handleLifecycleAnalysis;
|
|
255
256
|
private handleGetNotes;
|
|
256
257
|
private handleAddNote;
|
|
257
258
|
private handleDeleteNote;
|
package/dist/server.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EAAgB,eAAe,EAA0B,MAAM,MAAM,CAAC;AAI7E,OAA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,OAAO,CAAC,gBAAgB;IAcxB,OAAO,CAAC,UAAU;IAiClB,OAAO,CAAC,eAAe;YAiBT,gBAAgB;YA4ChB,gBAAgB;YA6ChB,gBAAgB;YAsChB,mBAAmB;YAsDnB,mBAAmB;IA8CjC,OAAO,CAAC,eAAe;IA8BvB,OAAO,CAAC,oBAAoB;YAgBd,iBAAiB;YAyDjB,iBAAiB;IAiE/B,OAAO,CAAC,uBAAuB;IAyB/B,OAAO,CAAC,iBAAiB;IAezB,OAAO,CAAC,gBAAgB;YAOV,iBAAiB;YA2CjB,iBAAiB;YAuDjB,iBAAiB;YAyCjB,sBAAsB;YAsDtB,wBAAwB;IAiDtC,OAAO,CAAC,mBAAmB;YAsBb,oBAAoB;YAwDpB,oBAAoB;IAwDlC,OAAO,CAAC,mBAAmB;YAQb,oBAAoB;YAsCpB,oBAAoB;IAuClC;;OAEG;IACH,OAAO,CAAC,gBAAgB;IAQxB,OAAO,CAAC,eAAe;IAUvB,iFAAiF;IACjF,OAAO,CAAC,iBAAiB;IAuBzB,OAAO,CAAC,QAAQ;IAkBV,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAqC3B;;;;;;;OAOG;IACG,YAAY,CAAC,SAAS,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC;IAgDrD,OAAO,CAAC,gBAAgB;IAuExB,OAAO,CAAC,eAAe;YA+GT,mBAAmB;YAgJnB,wBAAwB;IAoJtC,OAAO,CAAC,sBAAsB;IA0F9B,OAAO,CAAC,sBAAsB;IA6E9B,qDAAqD;IACrD,OAAO,CAAC,UAAU;CAMnB"}
|
package/dist/server.js
CHANGED
|
@@ -858,6 +858,12 @@ class PayGateServer {
|
|
|
858
858
|
res.writeHead(405, { 'Content-Type': 'application/json' });
|
|
859
859
|
res.end(JSON.stringify({ error: 'Method not allowed. Use GET.' }));
|
|
860
860
|
return;
|
|
861
|
+
case '/admin/key-portfolio':
|
|
862
|
+
if (req.method === 'GET')
|
|
863
|
+
return this.handleLifecycleAnalysis(req, res);
|
|
864
|
+
res.writeHead(405, { 'Content-Type': 'application/json' });
|
|
865
|
+
res.end(JSON.stringify({ error: 'Method not allowed. Use GET.' }));
|
|
866
|
+
return;
|
|
861
867
|
// ─── Plugin endpoints ──────────────────────────────────────────────
|
|
862
868
|
case '/plugins':
|
|
863
869
|
return this.handleListPlugins(req, res);
|
|
@@ -1408,6 +1414,7 @@ class PayGateServer {
|
|
|
1408
1414
|
trafficAnalysis: 'GET /admin/traffic — Traffic volume analysis with tool popularity, hourly volume, top consumers, namespace breakdown, and peak hour identification (requires X-Admin-Key)',
|
|
1409
1415
|
securityAudit: 'GET /admin/security — Security posture analysis with findings for missing IP allowlists, quotas, ACLs, spending limits, expiry, high-credit keys, and composite score (requires X-Admin-Key)',
|
|
1410
1416
|
revenueAnalysis: 'GET /admin/revenue — Revenue metrics with per-tool revenue, per-key spending, hourly revenue trends, credit flow summary, and average revenue per call (requires X-Admin-Key)',
|
|
1417
|
+
keyPortfolio: 'GET /admin/key-portfolio — Key portfolio health with active/inactive/suspended counts, stale keys, expiring-soon keys, age distribution, credit utilization, and namespace breakdown (requires X-Admin-Key)',
|
|
1411
1418
|
...(this.oauth ? {
|
|
1412
1419
|
oauthMetadata: 'GET /.well-known/oauth-authorization-server — OAuth 2.1 server metadata',
|
|
1413
1420
|
oauthRegister: 'POST /oauth/register — Register OAuth client',
|
|
@@ -5481,6 +5488,89 @@ class PayGateServer {
|
|
|
5481
5488
|
},
|
|
5482
5489
|
}));
|
|
5483
5490
|
}
|
|
5491
|
+
// ─── /admin/lifecycle — Key lifecycle analysis ─────────────────────────
|
|
5492
|
+
handleLifecycleAnalysis(req, res) {
|
|
5493
|
+
if (!this.checkAdmin(req, res))
|
|
5494
|
+
return;
|
|
5495
|
+
const allRecords = this.gate.store.getAllRecords();
|
|
5496
|
+
const now = Date.now();
|
|
5497
|
+
const EXPIRY_SOON_MS = 7 * 24 * 3600 * 1000; // 7 days
|
|
5498
|
+
// ── Summary counts ──
|
|
5499
|
+
const activeKeys = allRecords.filter(r => r.active && !r.suspended);
|
|
5500
|
+
const inactiveKeys = allRecords.filter(r => !r.active);
|
|
5501
|
+
const suspendedKeys = allRecords.filter(r => r.active && r.suspended);
|
|
5502
|
+
// ── Stale keys (active, never used) ──
|
|
5503
|
+
const staleKeys = allRecords
|
|
5504
|
+
.filter(r => r.active && !r.suspended && !r.lastUsedAt)
|
|
5505
|
+
.map(r => ({
|
|
5506
|
+
name: r.name,
|
|
5507
|
+
createdAt: r.createdAt,
|
|
5508
|
+
credits: r.credits,
|
|
5509
|
+
ageDays: Math.round((now - new Date(r.createdAt).getTime()) / 86400000 * 10) / 10,
|
|
5510
|
+
}));
|
|
5511
|
+
// ── Expiring soon (active, expiry within threshold) ──
|
|
5512
|
+
const expiringSoon = allRecords
|
|
5513
|
+
.filter(r => {
|
|
5514
|
+
if (!r.active || !r.expiresAt)
|
|
5515
|
+
return false;
|
|
5516
|
+
const expiresMs = new Date(r.expiresAt).getTime();
|
|
5517
|
+
return expiresMs > now && expiresMs - now <= EXPIRY_SOON_MS;
|
|
5518
|
+
})
|
|
5519
|
+
.map(r => ({
|
|
5520
|
+
name: r.name,
|
|
5521
|
+
expiresAt: r.expiresAt,
|
|
5522
|
+
hoursRemaining: Math.round((new Date(r.expiresAt).getTime() - now) / 3600000 * 10) / 10,
|
|
5523
|
+
credits: r.credits,
|
|
5524
|
+
}))
|
|
5525
|
+
.sort((a, b) => a.hoursRemaining - b.hoursRemaining);
|
|
5526
|
+
// ── Age distribution ──
|
|
5527
|
+
const ages = allRecords.map(r => (now - new Date(r.createdAt).getTime()) / 86400000);
|
|
5528
|
+
const averageAgeDays = ages.length > 0 ? Math.round(ages.reduce((s, a) => s + a, 0) / ages.length * 10) / 10 : 0;
|
|
5529
|
+
const oldestAgeDays = ages.length > 0 ? Math.round(Math.max(...ages) * 10) / 10 : 0;
|
|
5530
|
+
const newestAgeDays = ages.length > 0 ? Math.round(Math.min(...ages) * 10) / 10 : 0;
|
|
5531
|
+
// ── Credit utilization ──
|
|
5532
|
+
let totalAllocated = 0;
|
|
5533
|
+
let totalSpent = 0;
|
|
5534
|
+
for (const r of allRecords) {
|
|
5535
|
+
totalAllocated += r.credits + (r.totalSpent || 0);
|
|
5536
|
+
totalSpent += r.totalSpent || 0;
|
|
5537
|
+
}
|
|
5538
|
+
const averageCreditUtilization = totalAllocated > 0 ? Math.round(totalSpent / totalAllocated * 10000) / 10000 : 0;
|
|
5539
|
+
// ── Namespace breakdown ──
|
|
5540
|
+
const nsMap = new Map();
|
|
5541
|
+
for (const r of allRecords) {
|
|
5542
|
+
const ns = r.namespace || 'default';
|
|
5543
|
+
if (!nsMap.has(ns))
|
|
5544
|
+
nsMap.set(ns, { total: 0, active: 0, suspended: 0 });
|
|
5545
|
+
const n = nsMap.get(ns);
|
|
5546
|
+
n.total++;
|
|
5547
|
+
if (r.active && !r.suspended)
|
|
5548
|
+
n.active++;
|
|
5549
|
+
if (r.suspended)
|
|
5550
|
+
n.suspended++;
|
|
5551
|
+
}
|
|
5552
|
+
const byNamespace = Array.from(nsMap.entries())
|
|
5553
|
+
.map(([namespace, stats]) => ({ namespace, ...stats }))
|
|
5554
|
+
.sort((a, b) => b.total - a.total);
|
|
5555
|
+
res.writeHead(200, { 'Content-Type': 'application/json' });
|
|
5556
|
+
res.end(JSON.stringify({
|
|
5557
|
+
summary: {
|
|
5558
|
+
totalKeys: allRecords.length,
|
|
5559
|
+
activeKeys: activeKeys.length,
|
|
5560
|
+
inactiveKeys: inactiveKeys.length,
|
|
5561
|
+
suspendedKeys: suspendedKeys.length,
|
|
5562
|
+
averageCreditUtilization,
|
|
5563
|
+
},
|
|
5564
|
+
staleKeys,
|
|
5565
|
+
expiringSoon,
|
|
5566
|
+
ageDistribution: {
|
|
5567
|
+
averageAgeDays,
|
|
5568
|
+
oldestAgeDays,
|
|
5569
|
+
newestAgeDays,
|
|
5570
|
+
},
|
|
5571
|
+
byNamespace,
|
|
5572
|
+
}));
|
|
5573
|
+
}
|
|
5484
5574
|
// ─── /keys/notes — Timestamped notes on API keys ─────────────────────────
|
|
5485
5575
|
handleGetNotes(req, res) {
|
|
5486
5576
|
if (!this.checkAdmin(req, res))
|