paygate-mcp 3.3.0 → 3.5.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 +191 -0
- package/dist/audit.d.ts +1 -1
- package/dist/audit.d.ts.map +1 -1
- package/dist/audit.js.map +1 -1
- package/dist/gate.d.ts +12 -1
- package/dist/gate.d.ts.map +1 -1
- package/dist/gate.js +88 -15
- package/dist/gate.js.map +1 -1
- package/dist/groups.d.ts +140 -0
- package/dist/groups.d.ts.map +1 -0
- package/dist/groups.js +258 -0
- package/dist/groups.js.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -1
- package/dist/index.js.map +1 -1
- package/dist/plugin.d.ts +172 -0
- package/dist/plugin.d.ts.map +1 -0
- package/dist/plugin.js +244 -0
- package/dist/plugin.js.map +1 -0
- package/dist/server.d.ts +25 -0
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +325 -1
- package/dist/server.js.map +1 -1
- package/dist/store.d.ts +5 -0
- package/dist/store.d.ts.map +1 -1
- package/dist/store.js +17 -0
- package/dist/store.js.map +1 -1
- package/dist/types.d.ts +2 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/plugin.js
ADDED
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Plugin System — Extensible middleware hooks for custom billing, auth,
|
|
4
|
+
* pricing, logging, and request handling logic.
|
|
5
|
+
*
|
|
6
|
+
* Plugins register named hook functions that run at key points in the
|
|
7
|
+
* request lifecycle:
|
|
8
|
+
*
|
|
9
|
+
* Gate hooks (synchronous — hot path):
|
|
10
|
+
* - beforeGate: Short-circuit gate evaluation (deny/allow early)
|
|
11
|
+
* - afterGate: Modify gate decision after evaluation
|
|
12
|
+
* - onDeny: Notification when a tool call is denied
|
|
13
|
+
* - transformPrice: Override tool pricing dynamically
|
|
14
|
+
*
|
|
15
|
+
* Tool hooks (async — wraps proxy forward):
|
|
16
|
+
* - beforeToolCall: Modify request before forwarding to MCP server
|
|
17
|
+
* - afterToolCall: Modify response after receiving from MCP server
|
|
18
|
+
*
|
|
19
|
+
* HTTP hooks (async):
|
|
20
|
+
* - onRequest: Handle custom HTTP endpoints before normal routing
|
|
21
|
+
*
|
|
22
|
+
* Lifecycle hooks (async):
|
|
23
|
+
* - onStart: Called when the server starts
|
|
24
|
+
* - onStop: Called when the server stops
|
|
25
|
+
*
|
|
26
|
+
* Plugins run in registration order. Gate hooks are sync to avoid adding
|
|
27
|
+
* latency to the critical billing path. Tool/HTTP/lifecycle hooks may be async.
|
|
28
|
+
*/
|
|
29
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
30
|
+
exports.PluginManager = void 0;
|
|
31
|
+
// ─── Plugin Manager ───────────────────────────────────────────────────────
|
|
32
|
+
class PluginManager {
|
|
33
|
+
plugins = [];
|
|
34
|
+
/** Register a plugin. Plugins run in registration order. */
|
|
35
|
+
register(plugin) {
|
|
36
|
+
if (!plugin.name) {
|
|
37
|
+
throw new Error('Plugin must have a name');
|
|
38
|
+
}
|
|
39
|
+
if (this.plugins.some(p => p.name === plugin.name)) {
|
|
40
|
+
throw new Error(`Plugin "${plugin.name}" is already registered`);
|
|
41
|
+
}
|
|
42
|
+
this.plugins.push(plugin);
|
|
43
|
+
}
|
|
44
|
+
/** Unregister a plugin by name. Returns true if found and removed. */
|
|
45
|
+
unregister(name) {
|
|
46
|
+
const idx = this.plugins.findIndex(p => p.name === name);
|
|
47
|
+
if (idx === -1)
|
|
48
|
+
return false;
|
|
49
|
+
this.plugins.splice(idx, 1);
|
|
50
|
+
return true;
|
|
51
|
+
}
|
|
52
|
+
/** List all registered plugins with their hooks. */
|
|
53
|
+
list() {
|
|
54
|
+
return this.plugins.map(p => ({
|
|
55
|
+
name: p.name,
|
|
56
|
+
version: p.version,
|
|
57
|
+
hooks: this.getPluginHooks(p),
|
|
58
|
+
}));
|
|
59
|
+
}
|
|
60
|
+
/** Number of registered plugins. */
|
|
61
|
+
get count() {
|
|
62
|
+
return this.plugins.length;
|
|
63
|
+
}
|
|
64
|
+
// ─── Gate Hook Execution (synchronous) ────────────────────────────
|
|
65
|
+
/**
|
|
66
|
+
* Execute beforeGate hooks in order.
|
|
67
|
+
* First non-null result short-circuits the gate.
|
|
68
|
+
*/
|
|
69
|
+
executeBeforeGate(context) {
|
|
70
|
+
for (const plugin of this.plugins) {
|
|
71
|
+
if (plugin.beforeGate) {
|
|
72
|
+
try {
|
|
73
|
+
const result = plugin.beforeGate(context);
|
|
74
|
+
if (result !== null && result !== undefined)
|
|
75
|
+
return result;
|
|
76
|
+
}
|
|
77
|
+
catch {
|
|
78
|
+
// Plugin errors don't break the gate
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
return null;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Execute afterGate hooks in order.
|
|
86
|
+
* Each plugin can modify the decision; changes cascade through.
|
|
87
|
+
*/
|
|
88
|
+
executeAfterGate(context, decision) {
|
|
89
|
+
let current = decision;
|
|
90
|
+
for (const plugin of this.plugins) {
|
|
91
|
+
if (plugin.afterGate) {
|
|
92
|
+
try {
|
|
93
|
+
current = plugin.afterGate(context, current);
|
|
94
|
+
}
|
|
95
|
+
catch {
|
|
96
|
+
// Plugin errors don't break the gate
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
return current;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Execute onDeny hooks (fire-and-forget).
|
|
104
|
+
*/
|
|
105
|
+
executeOnDeny(context, reason) {
|
|
106
|
+
for (const plugin of this.plugins) {
|
|
107
|
+
if (plugin.onDeny) {
|
|
108
|
+
try {
|
|
109
|
+
plugin.onDeny(context, reason);
|
|
110
|
+
}
|
|
111
|
+
catch {
|
|
112
|
+
// Plugin errors don't break the flow
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Execute transformPrice hooks. First non-null result wins.
|
|
119
|
+
*/
|
|
120
|
+
executeTransformPrice(toolName, basePrice, args) {
|
|
121
|
+
for (const plugin of this.plugins) {
|
|
122
|
+
if (plugin.transformPrice) {
|
|
123
|
+
try {
|
|
124
|
+
const result = plugin.transformPrice(toolName, basePrice, args);
|
|
125
|
+
if (result !== null && result !== undefined && typeof result === 'number') {
|
|
126
|
+
return result;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
catch {
|
|
130
|
+
// Plugin errors → fall through to default
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
return basePrice;
|
|
135
|
+
}
|
|
136
|
+
// ─── Tool Hook Execution (async) ──────────────────────────────────
|
|
137
|
+
/**
|
|
138
|
+
* Execute beforeToolCall hooks in order.
|
|
139
|
+
* Each can modify the request; changes cascade.
|
|
140
|
+
*/
|
|
141
|
+
async executeBeforeToolCall(context) {
|
|
142
|
+
let req = context.request;
|
|
143
|
+
for (const plugin of this.plugins) {
|
|
144
|
+
if (plugin.beforeToolCall) {
|
|
145
|
+
try {
|
|
146
|
+
req = await plugin.beforeToolCall({ ...context, request: req });
|
|
147
|
+
}
|
|
148
|
+
catch {
|
|
149
|
+
// Plugin errors → skip this hook
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
return req;
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Execute afterToolCall hooks in order.
|
|
157
|
+
* Each can modify the response; changes cascade.
|
|
158
|
+
*/
|
|
159
|
+
async executeAfterToolCall(context, response) {
|
|
160
|
+
let res = response;
|
|
161
|
+
for (const plugin of this.plugins) {
|
|
162
|
+
if (plugin.afterToolCall) {
|
|
163
|
+
try {
|
|
164
|
+
res = await plugin.afterToolCall(context, res);
|
|
165
|
+
}
|
|
166
|
+
catch {
|
|
167
|
+
// Plugin errors → skip this hook
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
return res;
|
|
172
|
+
}
|
|
173
|
+
// ─── HTTP Hook Execution (async) ──────────────────────────────────
|
|
174
|
+
/**
|
|
175
|
+
* Execute onRequest hooks. First handler returning true wins.
|
|
176
|
+
*/
|
|
177
|
+
async executeOnRequest(req, res) {
|
|
178
|
+
for (const plugin of this.plugins) {
|
|
179
|
+
if (plugin.onRequest) {
|
|
180
|
+
try {
|
|
181
|
+
const handled = await plugin.onRequest(req, res);
|
|
182
|
+
if (handled)
|
|
183
|
+
return true;
|
|
184
|
+
}
|
|
185
|
+
catch {
|
|
186
|
+
// Plugin errors → continue to next plugin
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
return false;
|
|
191
|
+
}
|
|
192
|
+
// ─── Lifecycle Hook Execution (async) ─────────────────────────────
|
|
193
|
+
/**
|
|
194
|
+
* Execute onStart hooks for all plugins.
|
|
195
|
+
*/
|
|
196
|
+
async executeStart() {
|
|
197
|
+
for (const plugin of this.plugins) {
|
|
198
|
+
if (plugin.onStart) {
|
|
199
|
+
await plugin.onStart();
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* Execute onStop hooks for all plugins (in reverse order for clean teardown).
|
|
205
|
+
*/
|
|
206
|
+
async executeStop() {
|
|
207
|
+
for (let i = this.plugins.length - 1; i >= 0; i--) {
|
|
208
|
+
const plugin = this.plugins[i];
|
|
209
|
+
if (plugin.onStop) {
|
|
210
|
+
try {
|
|
211
|
+
await plugin.onStop();
|
|
212
|
+
}
|
|
213
|
+
catch {
|
|
214
|
+
// Best-effort teardown
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
// ─── Private ──────────────────────────────────────────────────────
|
|
220
|
+
getPluginHooks(plugin) {
|
|
221
|
+
const hooks = [];
|
|
222
|
+
if (plugin.onStart)
|
|
223
|
+
hooks.push('onStart');
|
|
224
|
+
if (plugin.onStop)
|
|
225
|
+
hooks.push('onStop');
|
|
226
|
+
if (plugin.beforeGate)
|
|
227
|
+
hooks.push('beforeGate');
|
|
228
|
+
if (plugin.afterGate)
|
|
229
|
+
hooks.push('afterGate');
|
|
230
|
+
if (plugin.onDeny)
|
|
231
|
+
hooks.push('onDeny');
|
|
232
|
+
if (plugin.transformPrice)
|
|
233
|
+
hooks.push('transformPrice');
|
|
234
|
+
if (plugin.beforeToolCall)
|
|
235
|
+
hooks.push('beforeToolCall');
|
|
236
|
+
if (plugin.afterToolCall)
|
|
237
|
+
hooks.push('afterToolCall');
|
|
238
|
+
if (plugin.onRequest)
|
|
239
|
+
hooks.push('onRequest');
|
|
240
|
+
return hooks;
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
exports.PluginManager = PluginManager;
|
|
244
|
+
//# sourceMappingURL=plugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin.js","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;;;AAwHH,6EAA6E;AAE7E,MAAa,aAAa;IAChB,OAAO,GAAoB,EAAE,CAAC;IAEtC,4DAA4D;IAC5D,QAAQ,CAAC,MAAqB;QAC5B,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC;YACjB,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAC;QAC7C,CAAC;QACD,IAAI,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC;YACnD,MAAM,IAAI,KAAK,CAAC,WAAW,MAAM,CAAC,IAAI,yBAAyB,CAAC,CAAC;QACnE,CAAC;QACD,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IAC5B,CAAC;IAED,sEAAsE;IAC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CAAC,cAAc;YAAE,KAAK,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAC;QACxD,IAAI,MAAM,CAAC,aAAa;YAAE,KAAK,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC;QACtD,IAAI,MAAM,CAAC,SAAS;YAAE,KAAK,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;QAC9C,OAAO,KAAK,CAAC;IACf,CAAC;CACF;AAjND,sCAiNC"}
|
package/dist/server.d.ts
CHANGED
|
@@ -28,6 +28,8 @@ import { TeamManager } from './teams';
|
|
|
28
28
|
import { RedisSync } from './redis-sync';
|
|
29
29
|
import { ScopedTokenManager } from './tokens';
|
|
30
30
|
import { AdminKeyManager } from './admin-keys';
|
|
31
|
+
import { PluginManager, PayGatePlugin } from './plugin';
|
|
32
|
+
import { KeyGroupManager } from './groups';
|
|
31
33
|
/** Union type for both proxy backends */
|
|
32
34
|
type ProxyBackend = McpProxy | HttpMcpProxy;
|
|
33
35
|
export declare class PayGateServer {
|
|
@@ -63,6 +65,9 @@ export declare class PayGateServer {
|
|
|
63
65
|
readonly redisSync: RedisSync | null;
|
|
64
66
|
/** Scoped token manager for short-lived delegated tokens */
|
|
65
67
|
readonly tokens: ScopedTokenManager;
|
|
68
|
+
/** Plugin manager for extensible middleware hooks */
|
|
69
|
+
readonly plugins: PluginManager;
|
|
70
|
+
readonly groups: KeyGroupManager;
|
|
66
71
|
/** Server start time (ms since epoch) */
|
|
67
72
|
private readonly startedAt;
|
|
68
73
|
/** Whether the server is draining (shutting down gracefully) */
|
|
@@ -74,6 +79,19 @@ export declare class PayGateServer {
|
|
|
74
79
|
constructor(config: Partial<PayGateConfig> & {
|
|
75
80
|
serverCommand: string;
|
|
76
81
|
}, adminKey?: string, statePath?: string, remoteUrl?: string, stripeWebhookSecret?: string, servers?: ServerBackendConfig[], redisUrl?: string);
|
|
82
|
+
/**
|
|
83
|
+
* Register a plugin for extensible middleware hooks.
|
|
84
|
+
* Plugins run in registration order.
|
|
85
|
+
*
|
|
86
|
+
* @example
|
|
87
|
+
* ```ts
|
|
88
|
+
* server.use({
|
|
89
|
+
* name: 'custom-pricing',
|
|
90
|
+
* transformPrice: (tool, base) => tool.startsWith('premium_') ? base * 5 : null,
|
|
91
|
+
* });
|
|
92
|
+
* ```
|
|
93
|
+
*/
|
|
94
|
+
use(plugin: PayGatePlugin): this;
|
|
77
95
|
start(): Promise<{
|
|
78
96
|
port: number;
|
|
79
97
|
adminKey: string;
|
|
@@ -156,6 +174,13 @@ export declare class PayGateServer {
|
|
|
156
174
|
private handleCreateToken;
|
|
157
175
|
private handleRevokeToken;
|
|
158
176
|
private handleListRevokedTokens;
|
|
177
|
+
private handleListPlugins;
|
|
178
|
+
private handleListGroups;
|
|
179
|
+
private handleCreateGroup;
|
|
180
|
+
private handleUpdateGroup;
|
|
181
|
+
private handleDeleteGroup;
|
|
182
|
+
private handleAssignKeyToGroup;
|
|
183
|
+
private handleRemoveKeyFromGroup;
|
|
159
184
|
private handleListAdminKeys;
|
|
160
185
|
private handleCreateAdminKey;
|
|
161
186
|
private handleRevokeAdminKey;
|
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;AAKH,OAAO,EAAE,aAAa,EAAkB,mBAAmB,EAAkB,MAAM,SAAS,CAAC;AAS7F,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,C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