paygate-mcp 8.22.0 → 8.24.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 +52 -0
- package/dist/server.d.ts +2 -0
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +119 -0
- package/dist/server.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -129,6 +129,8 @@ Agent → PayGate (auth + billing) → Your MCP Server (stdio or HTTP)
|
|
|
129
129
|
- **Credit Flow Analysis** — `GET /admin/credit-flow` credit inflow/outflow analysis with utilization percentage, top spenders, and per-tool spend breakdown
|
|
130
130
|
- **Key Age Analysis** — `GET /admin/key-age` key age distribution with oldest/newest keys, age buckets (24h/7d/30d/older), and recently created list
|
|
131
131
|
- **Namespace Usage Summary** — `GET /admin/namespace-usage` per-namespace usage metrics with credit allocation, spending, call counts, and cross-namespace comparison
|
|
132
|
+
- **Audit Summary** — `GET /admin/audit-summary` audit event analytics with type breakdown, top actors, recent events, and activity summary
|
|
133
|
+
- **Group Performance** — `GET /admin/group-performance` per-group analytics with key counts, credit allocation/spending, call volume, utilization, and policy summary
|
|
132
134
|
- **Config Hot Reload** — `POST /config/reload` reloads pricing, rate limits, webhooks, quotas, and behavior flags from config file without server restart
|
|
133
135
|
- **Webhook Events** — POST batched usage events to any URL for external billing/alerting
|
|
134
136
|
- **Config File Mode** — Load all settings from a JSON file (`--config`)
|
|
@@ -2984,6 +2986,56 @@ curl http://localhost:3000/admin/namespace-usage -H "X-Admin-Key: YOUR_ADMIN_KEY
|
|
|
2984
2986
|
|
|
2985
2987
|
Per-namespace usage metrics: key counts, credit allocation/spending/remaining, call counts, and utilization percentages. Sorted by spending (highest first). Keys without a namespace appear under "default". Read-only.
|
|
2986
2988
|
|
|
2989
|
+
### Audit Summary
|
|
2990
|
+
|
|
2991
|
+
```bash
|
|
2992
|
+
curl http://localhost:3000/admin/audit-summary -H "X-Admin-Key: YOUR_ADMIN_KEY"
|
|
2993
|
+
```
|
|
2994
|
+
|
|
2995
|
+
```json
|
|
2996
|
+
{
|
|
2997
|
+
"summary": { "totalEvents": 142, "eventsLastHour": 18, "eventsLast24h": 95, "oldestEvent": "2025-01-14T08:00:00Z", "newestEvent": "2025-01-15T14:30:00Z" },
|
|
2998
|
+
"eventsByType": [
|
|
2999
|
+
{ "type": "gate.allow", "count": 80 },
|
|
3000
|
+
{ "type": "gate.deny", "count": 25 },
|
|
3001
|
+
{ "type": "key.created", "count": 12 }
|
|
3002
|
+
],
|
|
3003
|
+
"topActors": [
|
|
3004
|
+
{ "actor": "pg_abc1...", "count": 60 },
|
|
3005
|
+
{ "actor": "admin", "count": 30 }
|
|
3006
|
+
],
|
|
3007
|
+
"recentEvents": [
|
|
3008
|
+
{ "id": 142, "timestamp": "2025-01-15T14:30:00Z", "type": "gate.allow", "actor": "pg_abc1...", "message": "Allowed: tool_a" }
|
|
3009
|
+
],
|
|
3010
|
+
"generatedAt": "2025-01-15T14:30:00Z"
|
|
3011
|
+
}
|
|
3012
|
+
```
|
|
3013
|
+
|
|
3014
|
+
Audit event analytics: total events with hourly/daily counts, event type breakdown sorted by frequency, top 10 most active actors, and the 20 most recent events (newest first). Read-only.
|
|
3015
|
+
|
|
3016
|
+
### Group Performance
|
|
3017
|
+
|
|
3018
|
+
```bash
|
|
3019
|
+
curl http://localhost:3000/admin/group-performance -H "X-Admin-Key: YOUR_ADMIN_KEY"
|
|
3020
|
+
```
|
|
3021
|
+
|
|
3022
|
+
```json
|
|
3023
|
+
{
|
|
3024
|
+
"summary": { "totalGroups": 2, "ungroupedKeys": 3 },
|
|
3025
|
+
"groups": [
|
|
3026
|
+
{
|
|
3027
|
+
"groupId": "grp_abc123", "groupName": "prod-team", "description": "Production",
|
|
3028
|
+
"keyCount": 5, "totalAllocated": 5000, "totalSpent": 2000, "totalRemaining": 3000,
|
|
3029
|
+
"totalCalls": 400, "utilizationPct": 40,
|
|
3030
|
+
"policy": { "allowedTools": ["tool_a"], "deniedTools": [], "rateLimitPerMin": 60 }
|
|
3031
|
+
}
|
|
3032
|
+
],
|
|
3033
|
+
"generatedAt": "2025-01-15T14:30:00Z"
|
|
3034
|
+
}
|
|
3035
|
+
```
|
|
3036
|
+
|
|
3037
|
+
Per-group analytics: key counts, credit allocation/spending/remaining, call volume, and utilization percentages. Includes group policy summary (allowed/denied tools, rate limits). Sorted by spending (highest first). Also reports ungrouped key count. Read-only.
|
|
3038
|
+
|
|
2987
3039
|
### IP Allowlisting
|
|
2988
3040
|
|
|
2989
3041
|
Restrict API keys to specific IP addresses or CIDR ranges:
|
package/dist/server.d.ts
CHANGED
|
@@ -264,6 +264,8 @@ export declare class PayGateServer {
|
|
|
264
264
|
private handleCreditFlow;
|
|
265
265
|
private handleKeyAge;
|
|
266
266
|
private handleNamespaceUsage;
|
|
267
|
+
private handleAuditSummary;
|
|
268
|
+
private handleGroupPerformance;
|
|
267
269
|
private handleGetNotes;
|
|
268
270
|
private handleAddNote;
|
|
269
271
|
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,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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
|
@@ -930,6 +930,18 @@ class PayGateServer {
|
|
|
930
930
|
res.writeHead(405, { 'Content-Type': 'application/json' });
|
|
931
931
|
res.end(JSON.stringify({ error: 'Method not allowed. Use GET.' }));
|
|
932
932
|
return;
|
|
933
|
+
case '/admin/audit-summary':
|
|
934
|
+
if (req.method === 'GET')
|
|
935
|
+
return this.handleAuditSummary(req, res);
|
|
936
|
+
res.writeHead(405, { 'Content-Type': 'application/json' });
|
|
937
|
+
res.end(JSON.stringify({ error: 'Method not allowed. Use GET.' }));
|
|
938
|
+
return;
|
|
939
|
+
case '/admin/group-performance':
|
|
940
|
+
if (req.method === 'GET')
|
|
941
|
+
return this.handleGroupPerformance(req, res);
|
|
942
|
+
res.writeHead(405, { 'Content-Type': 'application/json' });
|
|
943
|
+
res.end(JSON.stringify({ error: 'Method not allowed. Use GET.' }));
|
|
944
|
+
return;
|
|
933
945
|
// ─── Plugin endpoints ──────────────────────────────────────────────
|
|
934
946
|
case '/plugins':
|
|
935
947
|
return this.handleListPlugins(req, res);
|
|
@@ -1492,6 +1504,8 @@ class PayGateServer {
|
|
|
1492
1504
|
creditFlow: 'GET /admin/credit-flow — Credit inflow/outflow analysis with utilization, top spenders, and per-tool spend breakdown (requires X-Admin-Key)',
|
|
1493
1505
|
keyAge: 'GET /admin/key-age — Key age distribution with oldest/newest keys, age buckets, and recently created list (requires X-Admin-Key)',
|
|
1494
1506
|
namespaceUsage: 'GET /admin/namespace-usage — Per-namespace usage metrics with credit allocation, spending, call counts, and cross-namespace comparison (requires X-Admin-Key)',
|
|
1507
|
+
auditSummary: 'GET /admin/audit-summary — Audit event analytics with type breakdown, top actors, recent events, and activity summary (requires X-Admin-Key)',
|
|
1508
|
+
groupPerformance: 'GET /admin/group-performance — Per-group analytics with key counts, credit allocation/spending, call volume, and utilization (requires X-Admin-Key)',
|
|
1495
1509
|
...(this.oauth ? {
|
|
1496
1510
|
oauthMetadata: 'GET /.well-known/oauth-authorization-server — OAuth 2.1 server metadata',
|
|
1497
1511
|
oauthRegister: 'POST /oauth/register — Register OAuth client',
|
|
@@ -6464,6 +6478,111 @@ class PayGateServer {
|
|
|
6464
6478
|
generatedAt: new Date().toISOString(),
|
|
6465
6479
|
}));
|
|
6466
6480
|
}
|
|
6481
|
+
// ─── /admin/audit-summary — Audit event analytics ───────────────────────
|
|
6482
|
+
handleAuditSummary(req, res) {
|
|
6483
|
+
if (!this.checkAdmin(req, res))
|
|
6484
|
+
return;
|
|
6485
|
+
const stats = this.audit.stats();
|
|
6486
|
+
const allEvents = this.audit.exportAll();
|
|
6487
|
+
// ── Event type breakdown sorted by count descending ──
|
|
6488
|
+
const eventsByType = Object.entries(stats.eventsByType)
|
|
6489
|
+
.map(([type, count]) => ({ type, count }))
|
|
6490
|
+
.sort((a, b) => b.count - a.count);
|
|
6491
|
+
// ── Top actors by event count (top 10) ──
|
|
6492
|
+
const actorMap = new Map();
|
|
6493
|
+
for (const e of allEvents) {
|
|
6494
|
+
actorMap.set(e.actor, (actorMap.get(e.actor) || 0) + 1);
|
|
6495
|
+
}
|
|
6496
|
+
const topActors = Array.from(actorMap.entries())
|
|
6497
|
+
.map(([actor, count]) => ({ actor, count }))
|
|
6498
|
+
.sort((a, b) => b.count - a.count)
|
|
6499
|
+
.slice(0, 10);
|
|
6500
|
+
// ── Recent events (newest first, max 20) ──
|
|
6501
|
+
const recentEvents = allEvents.length > 0
|
|
6502
|
+
? allEvents.slice(-20).reverse().map(e => ({
|
|
6503
|
+
id: e.id,
|
|
6504
|
+
timestamp: e.timestamp,
|
|
6505
|
+
type: e.type,
|
|
6506
|
+
actor: e.actor,
|
|
6507
|
+
message: e.message,
|
|
6508
|
+
}))
|
|
6509
|
+
: [];
|
|
6510
|
+
res.writeHead(200, { 'Content-Type': 'application/json' });
|
|
6511
|
+
res.end(JSON.stringify({
|
|
6512
|
+
summary: {
|
|
6513
|
+
totalEvents: stats.totalEvents,
|
|
6514
|
+
eventsLastHour: stats.eventsLastHour,
|
|
6515
|
+
eventsLast24h: stats.eventsLast24h,
|
|
6516
|
+
oldestEvent: stats.oldestEvent,
|
|
6517
|
+
newestEvent: stats.newestEvent,
|
|
6518
|
+
},
|
|
6519
|
+
eventsByType,
|
|
6520
|
+
topActors,
|
|
6521
|
+
recentEvents,
|
|
6522
|
+
generatedAt: new Date().toISOString(),
|
|
6523
|
+
}));
|
|
6524
|
+
}
|
|
6525
|
+
// ─── /admin/group-performance — Per-group analytics ─────────────────────
|
|
6526
|
+
handleGroupPerformance(req, res) {
|
|
6527
|
+
if (!this.checkAdmin(req, res))
|
|
6528
|
+
return;
|
|
6529
|
+
const groupList = this.groups.listGroups();
|
|
6530
|
+
const records = this.gate.store.getAllRecords().filter(r => r.active);
|
|
6531
|
+
// Count ungrouped keys
|
|
6532
|
+
const groupedKeys = new Set();
|
|
6533
|
+
const groupRecords = new Map();
|
|
6534
|
+
for (const g of groupList) {
|
|
6535
|
+
const members = this.groups.getGroupMembers(g.id);
|
|
6536
|
+
const memberSet = new Set(members);
|
|
6537
|
+
const memberRecords = [];
|
|
6538
|
+
for (const r of records) {
|
|
6539
|
+
if (memberSet.has(r.key)) {
|
|
6540
|
+
groupedKeys.add(r.key);
|
|
6541
|
+
memberRecords.push(r);
|
|
6542
|
+
}
|
|
6543
|
+
}
|
|
6544
|
+
groupRecords.set(g.id, memberRecords);
|
|
6545
|
+
}
|
|
6546
|
+
const ungroupedKeys = records.filter(r => !groupedKeys.has(r.key)).length;
|
|
6547
|
+
const groups = groupList.map(g => {
|
|
6548
|
+
const members = groupRecords.get(g.id) || [];
|
|
6549
|
+
let totalAllocated = 0;
|
|
6550
|
+
let totalSpent = 0;
|
|
6551
|
+
let totalCalls = 0;
|
|
6552
|
+
for (const r of members) {
|
|
6553
|
+
totalAllocated += r.credits + r.totalSpent;
|
|
6554
|
+
totalSpent += r.totalSpent;
|
|
6555
|
+
totalCalls += r.totalCalls;
|
|
6556
|
+
}
|
|
6557
|
+
return {
|
|
6558
|
+
groupId: g.id,
|
|
6559
|
+
groupName: g.name,
|
|
6560
|
+
description: g.description,
|
|
6561
|
+
keyCount: members.length,
|
|
6562
|
+
totalAllocated,
|
|
6563
|
+
totalSpent,
|
|
6564
|
+
totalRemaining: totalAllocated - totalSpent,
|
|
6565
|
+
totalCalls,
|
|
6566
|
+
utilizationPct: totalAllocated > 0
|
|
6567
|
+
? Math.round((totalSpent / totalAllocated) * 100)
|
|
6568
|
+
: 0,
|
|
6569
|
+
policy: {
|
|
6570
|
+
allowedTools: g.allowedTools,
|
|
6571
|
+
deniedTools: g.deniedTools,
|
|
6572
|
+
rateLimitPerMin: g.rateLimitPerMin,
|
|
6573
|
+
},
|
|
6574
|
+
};
|
|
6575
|
+
}).sort((a, b) => b.totalSpent - a.totalSpent);
|
|
6576
|
+
res.writeHead(200, { 'Content-Type': 'application/json' });
|
|
6577
|
+
res.end(JSON.stringify({
|
|
6578
|
+
summary: {
|
|
6579
|
+
totalGroups: groupList.length,
|
|
6580
|
+
ungroupedKeys,
|
|
6581
|
+
},
|
|
6582
|
+
groups,
|
|
6583
|
+
generatedAt: new Date().toISOString(),
|
|
6584
|
+
}));
|
|
6585
|
+
}
|
|
6467
6586
|
// ─── /keys/notes — Timestamped notes on API keys ─────────────────────────
|
|
6468
6587
|
handleGetNotes(req, res) {
|
|
6469
6588
|
if (!this.checkAdmin(req, res))
|