paygate-mcp 8.18.0 → 8.20.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 +47 -0
- package/dist/server.d.ts +2 -0
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +147 -0
- package/dist/server.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -125,6 +125,8 @@ Agent → PayGate (auth + billing) → Your MCP Server (stdio or HTTP)
|
|
|
125
125
|
- **Capacity Planning** — `GET /admin/capacity` system capacity analysis with credit burn rates, utilization percentages, top consumers, per-namespace breakdown, and scaling recommendations
|
|
126
126
|
- **Key Dependency Map** — `GET /admin/dependencies` tool-to-key relationship map with tool usage popularity, unique key counts per tool, per-key tool lists, and used/unused tool identification
|
|
127
127
|
- **Tool Latency Analysis** — `GET /admin/latency` per-tool response time metrics with avg/p95/min/max durations, slowest tools ranking, and per-key latency breakdown
|
|
128
|
+
- **Error Rate Trends** — `GET /admin/error-trends` denial rate trends with per-tool error rates, denial reason breakdown, worst-performing tools, and trend direction
|
|
129
|
+
- **Credit Flow Analysis** — `GET /admin/credit-flow` credit inflow/outflow analysis with utilization percentage, top spenders, and per-tool spend breakdown
|
|
128
130
|
- **Config Hot Reload** — `POST /config/reload` reloads pricing, rate limits, webhooks, quotas, and behavior flags from config file without server restart
|
|
129
131
|
- **Webhook Events** — POST batched usage events to any URL for external billing/alerting
|
|
130
132
|
- **Config File Mode** — Load all settings from a JSON file (`--config`)
|
|
@@ -2893,6 +2895,51 @@ curl http://localhost:3000/admin/latency -H "X-Admin-Key: YOUR_ADMIN_KEY"
|
|
|
2893
2895
|
|
|
2894
2896
|
Per-tool response time metrics: average, p95, min, and max durations for each tool sorted by slowest average first, top 10 slowest tools ranking, per-key latency breakdown, and global summary. Only counts successful (allowed) calls. Read-only.
|
|
2895
2897
|
|
|
2898
|
+
### Error Rate Trends
|
|
2899
|
+
|
|
2900
|
+
```bash
|
|
2901
|
+
curl http://localhost:3000/admin/error-trends -H "X-Admin-Key: YOUR_ADMIN_KEY"
|
|
2902
|
+
```
|
|
2903
|
+
|
|
2904
|
+
```json
|
|
2905
|
+
{
|
|
2906
|
+
"summary": { "totalCalls": 500, "totalDenials": 45, "overallErrorRate": 9, "trend": "improving" },
|
|
2907
|
+
"byTool": [
|
|
2908
|
+
{ "tool": "translate", "totalCalls": 200, "denials": 30, "errorRate": 15 },
|
|
2909
|
+
{ "tool": "search", "totalCalls": 300, "denials": 15, "errorRate": 5 }
|
|
2910
|
+
],
|
|
2911
|
+
"denialReasons": [
|
|
2912
|
+
{ "reason": "insufficient_credits", "count": 30 },
|
|
2913
|
+
{ "reason": "rate_limited", "count": 15 }
|
|
2914
|
+
],
|
|
2915
|
+
"generatedAt": "2025-01-15T14:30:00Z"
|
|
2916
|
+
}
|
|
2917
|
+
```
|
|
2918
|
+
|
|
2919
|
+
Denial rate trends: overall error rate, per-tool error rates sorted by worst-performing, denial reason breakdown, and trend direction (improving/degrading/stable based on first-half vs second-half comparison). Read-only.
|
|
2920
|
+
|
|
2921
|
+
### Credit Flow Analysis
|
|
2922
|
+
|
|
2923
|
+
```bash
|
|
2924
|
+
curl http://localhost:3000/admin/credit-flow -H "X-Admin-Key: YOUR_ADMIN_KEY"
|
|
2925
|
+
```
|
|
2926
|
+
|
|
2927
|
+
```json
|
|
2928
|
+
{
|
|
2929
|
+
"summary": { "totalAllocated": 10000, "totalSpent": 3500, "totalRemaining": 6500, "utilizationPct": 35 },
|
|
2930
|
+
"topSpenders": [
|
|
2931
|
+
{ "keyName": "heavy-user", "creditsSpent": 2000, "creditsRemaining": 500, "callCount": 200 }
|
|
2932
|
+
],
|
|
2933
|
+
"byTool": [
|
|
2934
|
+
{ "tool": "search", "creditsSpent": 2000, "callCount": 400 },
|
|
2935
|
+
{ "tool": "translate", "creditsSpent": 1500, "callCount": 150 }
|
|
2936
|
+
],
|
|
2937
|
+
"generatedAt": "2025-01-15T14:30:00Z"
|
|
2938
|
+
}
|
|
2939
|
+
```
|
|
2940
|
+
|
|
2941
|
+
Credit inflow/outflow analysis: total credits allocated (initial + spent) vs spent vs remaining, utilization percentage, top 10 spenders ranked by credits consumed, and per-tool spend breakdown sorted by revenue. Read-only.
|
|
2942
|
+
|
|
2896
2943
|
### IP Allowlisting
|
|
2897
2944
|
|
|
2898
2945
|
Restrict API keys to specific IP addresses or CIDR ranges:
|
package/dist/server.d.ts
CHANGED
|
@@ -260,6 +260,8 @@ export declare class PayGateServer {
|
|
|
260
260
|
private handleCapacityPlanning;
|
|
261
261
|
private handleDependencyMap;
|
|
262
262
|
private handleLatencyAnalysis;
|
|
263
|
+
private handleErrorTrends;
|
|
264
|
+
private handleCreditFlow;
|
|
263
265
|
private handleGetNotes;
|
|
264
266
|
private handleAddNote;
|
|
265
267
|
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,OAAO,EAAE,aAAa,EAAkB,mBAAmB,EAAkB,MAAM,SAAS,CAAC;AAU7F,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAC9B,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACnC,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAE7C,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AACxC,OAAO,EAAE,cAAc,EAAqD,MAAM,WAAW,CAAC;AAC9F,OAAO,EAAE,WAAW,EAAmB,MAAM,SAAS,CAAC;AACvD,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC1C,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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
|
@@ -906,6 +906,18 @@ class PayGateServer {
|
|
|
906
906
|
res.writeHead(405, { 'Content-Type': 'application/json' });
|
|
907
907
|
res.end(JSON.stringify({ error: 'Method not allowed. Use GET.' }));
|
|
908
908
|
return;
|
|
909
|
+
case '/admin/error-trends':
|
|
910
|
+
if (req.method === 'GET')
|
|
911
|
+
return this.handleErrorTrends(req, res);
|
|
912
|
+
res.writeHead(405, { 'Content-Type': 'application/json' });
|
|
913
|
+
res.end(JSON.stringify({ error: 'Method not allowed. Use GET.' }));
|
|
914
|
+
return;
|
|
915
|
+
case '/admin/credit-flow':
|
|
916
|
+
if (req.method === 'GET')
|
|
917
|
+
return this.handleCreditFlow(req, res);
|
|
918
|
+
res.writeHead(405, { 'Content-Type': 'application/json' });
|
|
919
|
+
res.end(JSON.stringify({ error: 'Method not allowed. Use GET.' }));
|
|
920
|
+
return;
|
|
909
921
|
// ─── Plugin endpoints ──────────────────────────────────────────────
|
|
910
922
|
case '/plugins':
|
|
911
923
|
return this.handleListPlugins(req, res);
|
|
@@ -1464,6 +1476,8 @@ class PayGateServer {
|
|
|
1464
1476
|
capacityPlanning: 'GET /admin/capacity — Capacity planning with credit burn rates, utilization percentages, top consumers, per-namespace breakdown, and scaling recommendations (requires X-Admin-Key)',
|
|
1465
1477
|
dependencyMap: 'GET /admin/dependencies — Tool-to-key dependency map with tool usage popularity, unique key counts, per-key tool lists, and used/unused tool identification (requires X-Admin-Key)',
|
|
1466
1478
|
latencyAnalysis: 'GET /admin/latency — Per-tool response time metrics with avg/p95/min/max, slowest tools ranking, and per-key latency breakdown (requires X-Admin-Key)',
|
|
1479
|
+
errorTrends: 'GET /admin/error-trends — Denial rate trends with per-tool error rates, denial reason breakdown, and trend direction (requires X-Admin-Key)',
|
|
1480
|
+
creditFlow: 'GET /admin/credit-flow — Credit inflow/outflow analysis with utilization, top spenders, and per-tool spend breakdown (requires X-Admin-Key)',
|
|
1467
1481
|
...(this.oauth ? {
|
|
1468
1482
|
oauthMetadata: 'GET /.well-known/oauth-authorization-server — OAuth 2.1 server metadata',
|
|
1469
1483
|
oauthRegister: 'POST /oauth/register — Register OAuth client',
|
|
@@ -6194,6 +6208,139 @@ class PayGateServer {
|
|
|
6194
6208
|
generatedAt: new Date().toISOString(),
|
|
6195
6209
|
}));
|
|
6196
6210
|
}
|
|
6211
|
+
// ─── /admin/error-trends — Error Rate Trends ─────────────────────────────
|
|
6212
|
+
handleErrorTrends(req, res) {
|
|
6213
|
+
if (!this.checkAdmin(req, res))
|
|
6214
|
+
return;
|
|
6215
|
+
const entries = this.requestLog;
|
|
6216
|
+
if (entries.length === 0) {
|
|
6217
|
+
res.writeHead(200, { 'Content-Type': 'application/json' });
|
|
6218
|
+
res.end(JSON.stringify({
|
|
6219
|
+
summary: { totalCalls: 0, totalDenials: 0, overallErrorRate: 0, trend: 'stable' },
|
|
6220
|
+
byTool: [],
|
|
6221
|
+
denialReasons: [],
|
|
6222
|
+
generatedAt: new Date().toISOString(),
|
|
6223
|
+
}));
|
|
6224
|
+
return;
|
|
6225
|
+
}
|
|
6226
|
+
const totalCalls = entries.length;
|
|
6227
|
+
const denied = entries.filter(e => e.status === 'denied');
|
|
6228
|
+
const totalDenials = denied.length;
|
|
6229
|
+
const overallErrorRate = Math.round((totalDenials / totalCalls) * 10000) / 100; // 2 decimal places
|
|
6230
|
+
// ── Trend direction: compare first half vs second half error rates ──
|
|
6231
|
+
let trend = 'stable';
|
|
6232
|
+
if (entries.length >= 4) {
|
|
6233
|
+
const mid = Math.floor(entries.length / 2);
|
|
6234
|
+
const firstHalf = entries.slice(0, mid);
|
|
6235
|
+
const secondHalf = entries.slice(mid);
|
|
6236
|
+
const firstRate = firstHalf.filter(e => e.status === 'denied').length / firstHalf.length;
|
|
6237
|
+
const secondRate = secondHalf.filter(e => e.status === 'denied').length / secondHalf.length;
|
|
6238
|
+
const diff = secondRate - firstRate;
|
|
6239
|
+
if (diff > 0.05)
|
|
6240
|
+
trend = 'degrading';
|
|
6241
|
+
else if (diff < -0.05)
|
|
6242
|
+
trend = 'improving';
|
|
6243
|
+
}
|
|
6244
|
+
// ── Per-tool breakdown ──
|
|
6245
|
+
const toolMap = new Map();
|
|
6246
|
+
for (const e of entries) {
|
|
6247
|
+
if (!toolMap.has(e.tool))
|
|
6248
|
+
toolMap.set(e.tool, { total: 0, denied: 0 });
|
|
6249
|
+
const t = toolMap.get(e.tool);
|
|
6250
|
+
t.total++;
|
|
6251
|
+
if (e.status === 'denied')
|
|
6252
|
+
t.denied++;
|
|
6253
|
+
}
|
|
6254
|
+
const byTool = Array.from(toolMap.entries())
|
|
6255
|
+
.map(([tool, stats]) => ({
|
|
6256
|
+
tool,
|
|
6257
|
+
totalCalls: stats.total,
|
|
6258
|
+
denials: stats.denied,
|
|
6259
|
+
errorRate: Math.round((stats.denied / stats.total) * 10000) / 100,
|
|
6260
|
+
}))
|
|
6261
|
+
.sort((a, b) => b.errorRate - a.errorRate);
|
|
6262
|
+
// ── Denial reasons breakdown ──
|
|
6263
|
+
const reasonMap = new Map();
|
|
6264
|
+
for (const e of denied) {
|
|
6265
|
+
const reason = e.denyReason || 'unknown';
|
|
6266
|
+
reasonMap.set(reason, (reasonMap.get(reason) || 0) + 1);
|
|
6267
|
+
}
|
|
6268
|
+
const denialReasons = Array.from(reasonMap.entries())
|
|
6269
|
+
.map(([reason, count]) => ({ reason, count }))
|
|
6270
|
+
.sort((a, b) => b.count - a.count);
|
|
6271
|
+
res.writeHead(200, { 'Content-Type': 'application/json' });
|
|
6272
|
+
res.end(JSON.stringify({
|
|
6273
|
+
summary: { totalCalls, totalDenials, overallErrorRate, trend },
|
|
6274
|
+
byTool,
|
|
6275
|
+
denialReasons,
|
|
6276
|
+
generatedAt: new Date().toISOString(),
|
|
6277
|
+
}));
|
|
6278
|
+
}
|
|
6279
|
+
// ─── /admin/credit-flow — Credit Flow Analysis ──────────────────────────
|
|
6280
|
+
handleCreditFlow(req, res) {
|
|
6281
|
+
if (!this.checkAdmin(req, res))
|
|
6282
|
+
return;
|
|
6283
|
+
const records = this.gate.store.getAllRecords().filter(r => r.active);
|
|
6284
|
+
if (records.length === 0) {
|
|
6285
|
+
res.writeHead(200, { 'Content-Type': 'application/json' });
|
|
6286
|
+
res.end(JSON.stringify({
|
|
6287
|
+
summary: { totalAllocated: 0, totalSpent: 0, totalRemaining: 0, utilizationPct: 0 },
|
|
6288
|
+
topSpenders: [],
|
|
6289
|
+
byTool: [],
|
|
6290
|
+
generatedAt: new Date().toISOString(),
|
|
6291
|
+
}));
|
|
6292
|
+
return;
|
|
6293
|
+
}
|
|
6294
|
+
// ── Summary from key records ──
|
|
6295
|
+
let totalAllocated = 0;
|
|
6296
|
+
let totalSpent = 0;
|
|
6297
|
+
let totalRemaining = 0;
|
|
6298
|
+
for (const r of records) {
|
|
6299
|
+
totalAllocated += r.credits + r.totalSpent;
|
|
6300
|
+
totalSpent += r.totalSpent;
|
|
6301
|
+
totalRemaining += r.credits;
|
|
6302
|
+
}
|
|
6303
|
+
const utilizationPct = totalAllocated > 0
|
|
6304
|
+
? Math.round((totalSpent / totalAllocated) * 100)
|
|
6305
|
+
: 0;
|
|
6306
|
+
// ── Top spenders ranked by credits spent (top 10) ──
|
|
6307
|
+
const topSpenders = records
|
|
6308
|
+
.filter(r => r.totalSpent > 0)
|
|
6309
|
+
.map(r => ({
|
|
6310
|
+
keyName: r.name,
|
|
6311
|
+
creditsSpent: r.totalSpent,
|
|
6312
|
+
creditsRemaining: r.credits,
|
|
6313
|
+
callCount: r.totalCalls,
|
|
6314
|
+
}))
|
|
6315
|
+
.sort((a, b) => b.creditsSpent - a.creditsSpent)
|
|
6316
|
+
.slice(0, 10);
|
|
6317
|
+
// ── Per-tool spend breakdown from allowed events ──
|
|
6318
|
+
const events = this.gate.meter.getEvents();
|
|
6319
|
+
const toolSpend = new Map();
|
|
6320
|
+
for (const e of events) {
|
|
6321
|
+
if (!e.allowed || !e.tool)
|
|
6322
|
+
continue;
|
|
6323
|
+
if (!toolSpend.has(e.tool))
|
|
6324
|
+
toolSpend.set(e.tool, { credits: 0, calls: 0 });
|
|
6325
|
+
const t = toolSpend.get(e.tool);
|
|
6326
|
+
t.credits += e.creditsCharged;
|
|
6327
|
+
t.calls++;
|
|
6328
|
+
}
|
|
6329
|
+
const byTool = Array.from(toolSpend.entries())
|
|
6330
|
+
.map(([tool, stats]) => ({
|
|
6331
|
+
tool,
|
|
6332
|
+
creditsSpent: stats.credits,
|
|
6333
|
+
callCount: stats.calls,
|
|
6334
|
+
}))
|
|
6335
|
+
.sort((a, b) => b.creditsSpent - a.creditsSpent);
|
|
6336
|
+
res.writeHead(200, { 'Content-Type': 'application/json' });
|
|
6337
|
+
res.end(JSON.stringify({
|
|
6338
|
+
summary: { totalAllocated, totalSpent, totalRemaining, utilizationPct },
|
|
6339
|
+
topSpenders,
|
|
6340
|
+
byTool,
|
|
6341
|
+
generatedAt: new Date().toISOString(),
|
|
6342
|
+
}));
|
|
6343
|
+
}
|
|
6197
6344
|
// ─── /keys/notes — Timestamped notes on API keys ─────────────────────────
|
|
6198
6345
|
handleGetNotes(req, res) {
|
|
6199
6346
|
if (!this.checkAdmin(req, res))
|