paygate-mcp 0.1.4 → 0.7.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 walker77
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,12 +1,19 @@
1
1
  # paygate-mcp
2
2
 
3
- Monetize any MCP server with one command. Add API key auth, per-tool pricing, rate limiting, and usage metering to any Model Context Protocol server.
3
+ [![CI](https://github.com/walker77/paygate-mcp/actions/workflows/ci.yml/badge.svg)](https://github.com/walker77/paygate-mcp/actions/workflows/ci.yml)
4
+ [![npm version](https://img.shields.io/npm/v/paygate-mcp.svg)](https://www.npmjs.com/package/paygate-mcp)
5
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
6
+
7
+ Monetize any MCP server with one command. Add API key auth, per-tool pricing, rate limiting, and usage metering to any Model Context Protocol server. Zero dependencies. Zero config. Zero code changes.
4
8
 
5
9
  ## Quick Start
6
10
 
7
11
  ```bash
8
- # Wrap any MCP server with pay-per-call billing
12
+ # Wrap a local MCP server (stdio transport)
9
13
  npx paygate-mcp wrap --server "npx @modelcontextprotocol/server-filesystem /tmp"
14
+
15
+ # Gate a remote MCP server (Streamable HTTP transport)
16
+ npx paygate-mcp wrap --remote-url "https://my-server.example.com/mcp" --price 5
10
17
  ```
11
18
 
12
19
  That's it. Your MCP server is now gated behind API keys with credit-based billing.
@@ -16,19 +23,25 @@ That's it. Your MCP server is now gated behind API keys with credit-based billin
16
23
  PayGate sits between AI agents and your MCP server:
17
24
 
18
25
  ```
19
- Agent → PayGate (auth + billing) → Your MCP Server
26
+ Agent → PayGate (auth + billing) → Your MCP Server (stdio or HTTP)
20
27
  ```
21
28
 
22
29
  - **API Key Auth** — Clients need a valid `X-API-Key` to call tools
23
30
  - **Credit Billing** — Each tool call costs credits (configurable per-tool)
24
31
  - **Rate Limiting** — Sliding window per-key rate limits
25
32
  - **Usage Metering** — Track who called what, when, and how much they spent
33
+ - **Two Transports** — Wrap local servers via stdio or remote servers via Streamable HTTP
34
+ - **Spending Limits** — Cap total spend per API key to prevent runaway costs
35
+ - **Refund on Failure** — Automatically refund credits when downstream tool calls fail
36
+ - **Webhook Events** — POST batched usage events to any URL for external billing/alerting
37
+ - **Config File Mode** — Load all settings from a JSON file (`--config`)
26
38
  - **Shadow Mode** — Log everything without enforcing payment (for testing)
27
- - **Zero Config** — Works with any MCP server that uses stdio transport
39
+ - **Persistent Storage** — Keys and credits survive restarts with `--state-file`
40
+ - **Zero Dependencies** — No external npm packages. Uses only Node.js built-ins.
28
41
 
29
42
  ## Usage
30
43
 
31
- ### Start a Gated Server
44
+ ### Wrap a Local MCP Server (stdio)
32
45
 
33
46
  ```bash
34
47
  # Default: 1 credit per call, 60 calls/min, port 3402
@@ -50,6 +63,26 @@ npx paygate-mcp wrap \
50
63
  npx paygate-mcp wrap --server "node server.js" --shadow
51
64
  ```
52
65
 
66
+ ### Gate a Remote MCP Server (Streamable HTTP)
67
+
68
+ Gate any remote MCP server that supports the [Streamable HTTP transport](https://modelcontextprotocol.io/specification/2025-03-26/basic/transports#streamable-http) (MCP spec 2025-03-26):
69
+
70
+ ```bash
71
+ npx paygate-mcp wrap --remote-url "https://my-mcp-server.example.com/mcp"
72
+
73
+ # With custom pricing
74
+ npx paygate-mcp wrap \
75
+ --remote-url "https://api.example.com/mcp" \
76
+ --price 5 \
77
+ --tool-price "gpt4:20,search:2"
78
+ ```
79
+
80
+ The proxy handles:
81
+ - JSON-RPC forwarding via HTTP POST
82
+ - SSE (text/event-stream) response parsing
83
+ - `Mcp-Session-Id` session management
84
+ - Graceful session cleanup (HTTP DELETE on shutdown)
85
+
53
86
  When started, you'll see your admin key in the console. Save it.
54
87
 
55
88
  ### Create API Keys
@@ -87,6 +120,33 @@ curl -X POST http://localhost:3402/topup \
87
120
  -d '{"key": "CLIENT_API_KEY", "credits": 500}'
88
121
  ```
89
122
 
123
+ ### Check Balance (Client Self-Service)
124
+
125
+ ```bash
126
+ curl http://localhost:3402/balance \
127
+ -H "X-API-Key: CLIENT_API_KEY"
128
+ ```
129
+
130
+ Returns credits, total spent, call count, and last used timestamp. Clients can check their own balance without needing admin access.
131
+
132
+ ### Export Usage Data (Admin)
133
+
134
+ ```bash
135
+ # JSON export
136
+ curl http://localhost:3402/usage \
137
+ -H "X-Admin-Key: YOUR_ADMIN_KEY"
138
+
139
+ # CSV export (for spreadsheet/billing import)
140
+ curl "http://localhost:3402/usage?format=csv" \
141
+ -H "X-Admin-Key: YOUR_ADMIN_KEY"
142
+
143
+ # Filter by date
144
+ curl "http://localhost:3402/usage?since=2025-01-01T00:00:00Z" \
145
+ -H "X-Admin-Key: YOUR_ADMIN_KEY"
146
+ ```
147
+
148
+ Returns per-call usage events with tool name, credits charged, and timestamps. API keys are masked in output.
149
+
90
150
  ### Check Status
91
151
 
92
152
  ```bash
@@ -96,16 +156,31 @@ curl http://localhost:3402/status \
96
156
 
97
157
  Returns active keys, usage stats, per-tool breakdown, and deny reasons.
98
158
 
159
+ ### Admin Dashboard
160
+
161
+ Open the web dashboard in your browser:
162
+
163
+ ```
164
+ http://localhost:3402/dashboard
165
+ ```
166
+
167
+ A real-time admin UI for managing keys, viewing usage, and monitoring tool calls. Enter your admin key to authenticate. Features auto-refresh every 30s, top tools chart, activity feed, and key creation/management.
168
+
99
169
  ## API Reference
100
170
 
101
171
  | Endpoint | Method | Auth | Description |
102
172
  |----------|--------|------|-------------|
103
173
  | `/mcp` | POST | `X-API-Key` | JSON-RPC 2.0 proxy to wrapped MCP server |
174
+ | `/balance` | GET | `X-API-Key` | Client self-service — check own credits |
104
175
  | `/keys` | POST | `X-Admin-Key` | Create a new API key with credits |
105
176
  | `/keys` | GET | `X-Admin-Key` | List all keys (masked) |
106
177
  | `/topup` | POST | `X-Admin-Key` | Add credits to an existing key |
107
178
  | `/keys/revoke` | POST | `X-Admin-Key` | Revoke an API key |
179
+ | `/usage` | GET | `X-Admin-Key` | Export usage data (JSON or CSV) |
108
180
  | `/status` | GET | `X-Admin-Key` | Full dashboard with usage stats |
181
+ | `/dashboard` | GET | None (admin key in-browser) | Real-time admin web dashboard |
182
+ | `/limits` | POST | `X-Admin-Key` | Set spending limit on a key |
183
+ | `/stripe/webhook` | POST | Stripe Signature | Auto-top-up credits on payment |
109
184
  | `/` | GET | None | Health check |
110
185
 
111
186
  ### Free Methods
@@ -116,18 +191,25 @@ These MCP methods pass through without auth or billing:
116
191
  ## CLI Options
117
192
 
118
193
  ```
119
- --server <cmd> MCP server command to wrap (required)
120
- --port <n> HTTP port (default: 3402)
121
- --price <n> Default credits per tool call (default: 1)
122
- --rate-limit <n> Max calls/min per key (default: 60, 0=unlimited)
123
- --name <s> Server display name
124
- --shadow Shadow mode log without enforcing payment
125
- --admin-key <s> Set admin key (default: auto-generated)
126
- --tool-price <t:n> Per-tool price (e.g. "search:5,generate:10")
127
- --import-key <k:c> Import existing key with credits (e.g. "pg_abc:100")
128
- --state-file <path> Persist keys/credits to a JSON file (survives restarts)
194
+ --server <cmd> MCP server command to wrap via stdio
195
+ --remote-url <url> Remote MCP server URL (Streamable HTTP transport)
196
+ --port <n> HTTP port (default: 3402)
197
+ --price <n> Default credits per tool call (default: 1)
198
+ --rate-limit <n> Max calls/min per key (default: 60, 0=unlimited)
199
+ --name <s> Server display name
200
+ --shadow Shadow mode log without enforcing payment
201
+ --admin-key <s> Set admin key (default: auto-generated)
202
+ --tool-price <t:n> Per-tool price (e.g. "search:5,generate:10")
203
+ --import-key <k:c> Import existing key with credits (e.g. "pg_abc:100")
204
+ --state-file <path> Persist keys/credits to a JSON file (survives restarts)
205
+ --stripe-secret <s> Stripe webhook signing secret (enables /stripe/webhook)
206
+ --webhook-url <url> POST batched usage events to this URL
207
+ --refund-on-failure Refund credits when downstream tool call fails
208
+ --config <path> Load settings from a JSON config file
129
209
  ```
130
210
 
211
+ > **Note:** Use `--server` OR `--remote-url`, not both.
212
+
131
213
  ### Persistent Storage
132
214
 
133
215
  Add `--state-file` to save API keys and credits to disk. Data survives server restarts.
@@ -136,11 +218,107 @@ Add `--state-file` to save API keys and credits to disk. Data survives server re
136
218
  npx paygate-mcp wrap --server "your-mcp-server" --state-file ~/.paygate/state.json
137
219
  ```
138
220
 
221
+ ### Stripe Integration
222
+
223
+ Connect Stripe to automatically top up credits when customers pay:
224
+
225
+ ```bash
226
+ npx paygate-mcp wrap \
227
+ --server "your-mcp-server" \
228
+ --state-file ~/.paygate/state.json \
229
+ --stripe-secret "whsec_your_stripe_webhook_secret"
230
+ ```
231
+
232
+ **Setup:**
233
+ 1. Create a Stripe Checkout Session with metadata:
234
+ - `paygate_api_key` — the customer's API key (e.g. `pg_abc123...`)
235
+ - `paygate_credits` — credits to add on payment (e.g. `500`)
236
+ 2. Point your Stripe webhook to `https://your-server/stripe/webhook`
237
+ 3. Subscribe to `checkout.session.completed` and `invoice.payment_succeeded` events
238
+
239
+ When a customer completes payment, credits are automatically added to their API key. Subscriptions auto-renew credits on each billing cycle.
240
+
241
+ **Security:**
242
+ - HMAC-SHA256 signature verification (Stripe's v1 scheme)
243
+ - Timing-safe comparison to prevent timing attacks
244
+ - 5-minute timestamp tolerance to prevent replay attacks
245
+ - Payment status verification (only `paid` triggers credits)
246
+ - Zero dependencies — uses Node.js built-in `crypto`
247
+
248
+ ### Spending Limits
249
+
250
+ Cap the total credits any API key can spend:
251
+
252
+ ```bash
253
+ # Set a spending limit on a key (admin only)
254
+ curl -X POST http://localhost:3402/limits \
255
+ -H "Content-Type: application/json" \
256
+ -H "X-Admin-Key: YOUR_ADMIN_KEY" \
257
+ -d '{"key": "CLIENT_API_KEY", "spendingLimit": 500}'
258
+
259
+ # Check remaining budget
260
+ curl http://localhost:3402/balance -H "X-API-Key: CLIENT_API_KEY"
261
+ # → { "spendingLimit": 500, "remainingBudget": 350, ... }
262
+ ```
263
+
264
+ Set `spendingLimit` to `0` for unlimited. When a key hits its limit, tool calls are denied with a clear error.
265
+
266
+ ### Refund on Failure
267
+
268
+ Automatically return credits when a downstream tool call fails:
269
+
270
+ ```bash
271
+ npx paygate-mcp wrap --server "node server.js" --refund-on-failure
272
+ ```
273
+
274
+ Credits are deducted before the tool call. If the wrapped server returns an error, credits are refunded and `totalSpent` / `totalCalls` are rolled back. Prevents charging users for failed operations.
275
+
276
+ ### Webhook Events
277
+
278
+ POST usage events to any external URL for billing, alerting, or analytics:
279
+
280
+ ```bash
281
+ npx paygate-mcp wrap --server "node server.js" --webhook-url "https://billing.example.com/events"
282
+ ```
283
+
284
+ Events are batched (up to 10 per POST) and flushed every 5 seconds. Each event includes tool name, credits charged, API key, and timestamp. Fire-and-forget with one retry on failure.
285
+
286
+ ### Config File Mode
287
+
288
+ Load all settings from a JSON file instead of CLI flags:
289
+
290
+ ```bash
291
+ npx paygate-mcp wrap --config paygate.json
292
+ ```
293
+
294
+ Example `paygate.json`:
295
+ ```json
296
+ {
297
+ "serverCommand": "npx",
298
+ "serverArgs": ["@modelcontextprotocol/server-filesystem", "/tmp"],
299
+ "port": 3402,
300
+ "defaultCreditsPerCall": 2,
301
+ "globalRateLimitPerMin": 30,
302
+ "webhookUrl": "https://billing.example.com/events",
303
+ "refundOnFailure": true,
304
+ "stateFile": "~/.paygate/state.json",
305
+ "toolPricing": {
306
+ "premium_analyze": { "creditsPerCall": 10 }
307
+ },
308
+ "importKeys": {
309
+ "pg_abc123def456": 500
310
+ }
311
+ }
312
+ ```
313
+
314
+ CLI flags override config file values when both are specified.
315
+
139
316
  ## Programmatic API
140
317
 
141
318
  ```typescript
142
- import { PayGateServer } from 'paygate-mcp';
319
+ import { PayGateServer, HttpMcpProxy } from 'paygate-mcp';
143
320
 
321
+ // Wrap a local server (stdio)
144
322
  const server = new PayGateServer({
145
323
  serverCommand: 'npx',
146
324
  serverArgs: ['@modelcontextprotocol/server-filesystem', '/tmp'],
@@ -151,6 +329,13 @@ const server = new PayGateServer({
151
329
  },
152
330
  });
153
331
 
332
+ // Or gate a remote server (Streamable HTTP)
333
+ const remoteServer = new PayGateServer({
334
+ serverCommand: '',
335
+ port: 3402,
336
+ defaultCreditsPerCall: 5,
337
+ }, undefined, undefined, 'https://my-mcp-server.example.com/mcp');
338
+
154
339
  const { port, adminKey } = await server.start();
155
340
  ```
156
341
 
@@ -162,21 +347,37 @@ const { port, adminKey } = await server.start();
162
347
  - 1MB request body limit
163
348
  - Input sanitization on all endpoints
164
349
  - Admin key never exposed in responses
350
+ - API keys never forwarded to remote servers (HTTP transport)
165
351
  - Rate limiting is per-key, concurrent-safe
352
+ - Stripe webhook signature verification (HMAC-SHA256, timing-safe)
353
+ - Dashboard uses safe DOM methods (textContent/createElement) — no innerHTML
354
+ - Webhook URLs masked in status output
355
+ - Spending limits enforced with integer arithmetic (no float bypass)
356
+ - Red-teamed with 84 adversarial security tests across 11 passes
166
357
 
167
358
  ## Current Limitations
168
359
 
169
- - **In-memory by default** — Without `--state-file`, data lives in memory and is lost on restart. Use `--state-file` for persistence.
170
- - **Credits are not real money** — Credits are just integers. There is no payment processor integration yet.
171
360
  - **Single process** — No clustering or horizontal scaling.
172
- - **Stdio transport only** — The wrapped MCP server must use stdio (most do).
173
-
174
- Persistent storage and Stripe integration are on the roadmap.
361
+ - **No response size limits for HTTP transport** — Large responses from remote servers are forwarded as-is.
362
+
363
+ ## Roadmap
364
+
365
+ - [x] Persistent storage (`--state-file`)
366
+ - [x] Streamable HTTP transport (`--remote-url`)
367
+ - [x] Stripe webhook integration (`--stripe-secret`)
368
+ - [x] Client self-service balance check (`/balance`)
369
+ - [x] Usage data export — JSON and CSV (`/usage`)
370
+ - [x] Admin web dashboard (`/dashboard`)
371
+ - [x] Per-key spending limits (`/limits`)
372
+ - [x] Webhook events (`--webhook-url`)
373
+ - [x] Refund on failure (`--refund-on-failure`)
374
+ - [x] Config file mode (`--config`)
375
+ - [ ] Multi-tenant mode
175
376
 
176
377
  ## Requirements
177
378
 
178
379
  - Node.js >= 18.0.0
179
- - Any MCP server that uses stdio transport
380
+ - Zero external dependencies
180
381
 
181
382
  ## License
182
383
 
package/dist/cli.d.ts CHANGED
@@ -5,8 +5,7 @@
5
5
  * Usage:
6
6
  * npx paygate-mcp wrap --server "npx my-mcp-server" --port 3402
7
7
  * npx paygate-mcp wrap --server "python server.py" --price 2 --rate-limit 30
8
- * npx paygate-mcp keys create --name "my-client" --credits 500
9
- * npx paygate-mcp status
8
+ * npx paygate-mcp wrap --config paygate.json
10
9
  */
11
10
  export {};
12
11
  //# sourceMappingURL=cli.d.ts.map
package/dist/cli.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AACA;;;;;;;;GAQG"}
1
+ {"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AACA;;;;;;;GAOG"}
package/dist/cli.js CHANGED
@@ -6,11 +6,21 @@
6
6
  * Usage:
7
7
  * npx paygate-mcp wrap --server "npx my-mcp-server" --port 3402
8
8
  * npx paygate-mcp wrap --server "python server.py" --price 2 --rate-limit 30
9
- * npx paygate-mcp keys create --name "my-client" --credits 500
10
- * npx paygate-mcp status
9
+ * npx paygate-mcp wrap --config paygate.json
11
10
  */
12
11
  Object.defineProperty(exports, "__esModule", { value: true });
13
12
  const server_1 = require("./server");
13
+ const fs_1 = require("fs");
14
+ const path_1 = require("path");
15
+ const PKG_VERSION = (() => {
16
+ try {
17
+ const pkg = JSON.parse((0, fs_1.readFileSync)((0, path_1.join)(__dirname, '..', 'package.json'), 'utf-8'));
18
+ return pkg.version || '0.0.0';
19
+ }
20
+ catch {
21
+ return '0.0.0';
22
+ }
23
+ })();
14
24
  // ─── Helpers ─────────────────────────────────────────────────────────────────
15
25
  function parseArgs(argv) {
16
26
  const command = argv[2] || 'help';
@@ -36,33 +46,44 @@ function printUsage() {
36
46
  paygate-mcp — Monetize any MCP server with one command.
37
47
 
38
48
  USAGE:
39
- paygate-mcp wrap --server <command> [options]
49
+ paygate-mcp wrap --server <command> [options] # stdio transport
50
+ paygate-mcp wrap --remote-url <url> [options] # Streamable HTTP transport
51
+ paygate-mcp wrap --config <path> [options] # load from config file
40
52
 
41
53
  OPTIONS:
42
- --server <cmd> MCP server command to wrap (required)
43
- e.g. "npx @modelcontextprotocol/server-filesystem /"
44
- --port <n> HTTP port (default: 3402)
45
- --price <n> Default credits per tool call (default: 1)
46
- --rate-limit <n> Max calls/min per key (default: 60, 0=unlimited)
47
- --name <s> Server display name (default: "PayGate MCP Server")
48
- --shadow Shadow mode log but don't enforce payment
49
- --admin-key <s> Set admin key (default: auto-generated)
50
- --tool-price <t:n> Per-tool price override (e.g. "search:5,generate:10")
51
- --import-key <k:c> Import an existing API key with credits (e.g. "pg_abc123:100")
52
- --state-file <path> Persist keys/credits to a JSON file (survives restarts)
54
+ --server <cmd> MCP server command to wrap via stdio (required unless --remote-url or --config)
55
+ e.g. "npx @modelcontextprotocol/server-filesystem /"
56
+ --remote-url <url> Remote MCP server URL (Streamable HTTP transport)
57
+ e.g. "https://my-mcp-server.example.com/mcp"
58
+ --config <path> Load all settings from a JSON file
59
+ --port <n> HTTP port (default: 3402)
60
+ --price <n> Default credits per tool call (default: 1)
61
+ --rate-limit <n> Max calls/min per key (default: 60, 0=unlimited)
62
+ --name <s> Server display name (default: "PayGate MCP Server")
63
+ --shadow Shadow mode log but don't enforce payment
64
+ --admin-key <s> Set admin key (default: auto-generated)
65
+ --tool-price <t:n> Per-tool price override (e.g. "search:5,generate:10")
66
+ --import-key <k:c> Import an existing API key with credits (e.g. "pg_abc123:100")
67
+ --state-file <path> Persist keys/credits to a JSON file (survives restarts)
68
+ --stripe-secret <s> Stripe webhook signing secret (enables /stripe/webhook endpoint)
69
+ --webhook-url <url> POST usage events to this URL (batched)
70
+ --refund-on-failure Refund credits when downstream tool call fails
53
71
 
54
72
  EXAMPLES:
55
- # Wrap a filesystem MCP server
73
+ # Wrap a local MCP server (stdio transport)
56
74
  paygate-mcp wrap --server "npx @modelcontextprotocol/server-filesystem /tmp"
57
75
 
76
+ # Gate a remote MCP server (Streamable HTTP transport)
77
+ paygate-mcp wrap --remote-url "https://my-server.example.com/mcp" --price 5
78
+
58
79
  # Custom pricing and rate limit
59
80
  paygate-mcp wrap --server "python my-server.py" --price 2 --rate-limit 30
60
81
 
61
82
  # Shadow mode (observe without enforcing)
62
83
  paygate-mcp wrap --server "node server.js" --shadow
63
84
 
64
- # Per-tool pricing
65
- paygate-mcp wrap --server "node server.js" --tool-price "search:5,generate:10"
85
+ # Load config from file
86
+ paygate-mcp wrap --config paygate.json
66
87
  `);
67
88
  }
68
89
  function parseToolPricing(input) {
@@ -81,24 +102,48 @@ async function main() {
81
102
  const { command, flags } = parseArgs(process.argv);
82
103
  switch (command) {
83
104
  case 'wrap': {
84
- const serverCmd = flags['server'];
85
- if (!serverCmd) {
86
- console.error('Error: --server is required.\n');
105
+ // Load config file if specified
106
+ let fileConfig = {};
107
+ if (flags['config']) {
108
+ try {
109
+ const raw = (0, fs_1.readFileSync)(flags['config'], 'utf-8');
110
+ fileConfig = JSON.parse(raw);
111
+ }
112
+ catch (err) {
113
+ console.error(`Error loading config file: ${err.message}`);
114
+ process.exit(1);
115
+ }
116
+ }
117
+ const serverCmd = flags['server'] || (fileConfig.serverCommand ? [fileConfig.serverCommand, ...(fileConfig.serverArgs || [])].join(' ') : '');
118
+ const remoteUrl = flags['remote-url'] || fileConfig.remoteUrl;
119
+ if (!serverCmd && !remoteUrl) {
120
+ console.error('Error: --server, --remote-url, or --config is required.\n');
87
121
  printUsage();
88
122
  process.exit(1);
89
123
  }
90
- // Parse server command into command + args
91
- const parts = serverCmd.split(/\s+/);
92
- const serverCommand = parts[0];
93
- const serverArgs = parts.slice(1);
94
- const port = parseInt(flags['port'] || '3402', 10);
95
- const price = parseInt(flags['price'] || '1', 10);
96
- const rateLimit = parseInt(flags['rate-limit'] || '60', 10);
97
- const name = flags['name'] || 'PayGate MCP Server';
98
- const shadowMode = flags['shadow'] === 'true' || flags['shadow'] === undefined && 'shadow' in flags;
99
- const adminKey = flags['admin-key'];
100
- const toolPricing = flags['tool-price'] ? parseToolPricing(flags['tool-price']) : {};
101
- const stateFile = flags['state-file'];
124
+ if (serverCmd && remoteUrl) {
125
+ console.error('Error: use --server OR --remote-url, not both.\n');
126
+ process.exit(1);
127
+ }
128
+ // Parse server command into command + args (stdio mode)
129
+ let serverCommand = fileConfig.serverCommand || '';
130
+ let serverArgs = fileConfig.serverArgs || [];
131
+ if (flags['server']) {
132
+ const parts = flags['server'].split(/\s+/);
133
+ serverCommand = parts[0];
134
+ serverArgs = parts.slice(1);
135
+ }
136
+ const port = parseInt(flags['port'] || String(fileConfig.port || 3402), 10);
137
+ const price = parseInt(flags['price'] || String(fileConfig.defaultCreditsPerCall || 1), 10);
138
+ const rateLimit = parseInt(flags['rate-limit'] || String(fileConfig.globalRateLimitPerMin || 60), 10);
139
+ const name = flags['name'] || fileConfig.serverCommand && 'PayGate MCP Server' || 'PayGate MCP Server';
140
+ const shadowMode = flags['shadow'] === 'true' || ('shadow' in flags && flags['shadow'] === undefined) || fileConfig.shadowMode || false;
141
+ const adminKey = flags['admin-key'] || fileConfig.adminKey;
142
+ const toolPricing = flags['tool-price'] ? parseToolPricing(flags['tool-price']) : (fileConfig.toolPricing || {});
143
+ const stateFile = flags['state-file'] || fileConfig.stateFile;
144
+ const stripeSecret = flags['stripe-secret'] || fileConfig.stripeWebhookSecret;
145
+ const webhookUrl = flags['webhook-url'] || fileConfig.webhookUrl || null;
146
+ const refundOnFailure = flags['refund-on-failure'] === 'true' || 'refund-on-failure' in flags || fileConfig.refundOnFailure || false;
102
147
  const server = new server_1.PayGateServer({
103
148
  serverCommand,
104
149
  serverArgs,
@@ -108,8 +153,10 @@ async function main() {
108
153
  name,
109
154
  shadowMode: !!shadowMode,
110
155
  toolPricing,
111
- }, adminKey, stateFile);
112
- // Import keys if specified
156
+ webhookUrl,
157
+ refundOnFailure: !!refundOnFailure,
158
+ }, adminKey, stateFile, remoteUrl, stripeSecret);
159
+ // Import keys from CLI flags
113
160
  if (flags['import-key']) {
114
161
  const pairs = flags['import-key'].split(',');
115
162
  for (const pair of pairs) {
@@ -119,6 +166,12 @@ async function main() {
119
166
  }
120
167
  }
121
168
  }
169
+ // Import keys from config file
170
+ if (fileConfig.importKeys) {
171
+ for (const [key, credits] of Object.entries(fileConfig.importKeys)) {
172
+ server.gate.store.importKey(key, 'imported', credits);
173
+ }
174
+ }
122
175
  // Handle graceful shutdown
123
176
  const shutdown = async () => {
124
177
  console.log('\nShutting down...');
@@ -136,18 +189,23 @@ async function main() {
136
189
  ║ ║
137
190
  ║ Endpoint: http://localhost:${String(result.port).padEnd(5)} ║
138
191
  ║ Admin Key: ${result.adminKey.slice(0, 20)}... ║
139
- Wrapping: ${serverCmd.slice(0, 35).padEnd(35)}║
192
+ Backend: ${(remoteUrl ? 'HTTP → ' + remoteUrl.slice(0, 28) : 'stdio → ' + (serverCmd || serverCommand).slice(0, 27)).padEnd(35)}║
140
193
  ║ ║
141
194
  ║ Pricing: ${String(price).padEnd(3)} credit(s) per tool call ║
142
195
  ║ Rate Limit: ${String(rateLimit).padEnd(3)} calls/min per key ║
143
196
  ║ Shadow: ${String(!!shadowMode).padEnd(5)} ║
144
197
  ║ Persist: ${(stateFile ? stateFile.slice(0, 33) : 'off (in-memory)').padEnd(35)}║
198
+ ║ Stripe: ${(stripeSecret ? 'enabled (/stripe/webhook)' : 'off').padEnd(35)}║
199
+ ║ Refund: ${String(!!refundOnFailure).padEnd(35)}║
200
+ ║ Webhook: ${(webhookUrl ? webhookUrl.slice(0, 33) : 'off').padEnd(35)}║
145
201
  ║ ║
146
202
  ╠══════════════════════════════════════════════════╣
147
- ║ POST /mcp — JSON-RPC (X-API-Key header)
148
- ║ GET /status Dashboard (X-Admin-Key header)
149
- POST /keys Create key (X-Admin-Key header)
150
- ║ POST /topup Add credits (X-Admin-Key header)║
203
+ ║ POST /mcp — JSON-RPC (X-API-Key header)
204
+ ║ GET /dashboard Admin web UI (open in browser)║
205
+ GET /balance Client balance (X-API-Key)
206
+ ║ POST /keys Create key (X-Admin-Key)
207
+ ║ POST /topup — Add credits (X-Admin-Key) ║
208
+ ║ POST /limits — Set spending limit (Admin) ║
151
209
  ╚══════════════════════════════════════════════════╝
152
210
  `);
153
211
  console.log(` Admin key (save this): ${result.adminKey}\n`);
@@ -166,7 +224,7 @@ async function main() {
166
224
  case 'version':
167
225
  case '--version':
168
226
  case '-v':
169
- console.log('paygate-mcp v0.1.4');
227
+ console.log(`paygate-mcp v${PKG_VERSION}`);
170
228
  break;
171
229
  default:
172
230
  console.error(`Unknown command: ${command}\n`);
package/dist/cli.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";;AACA;;;;;;;;GAQG;;AAEH,qCAAyC;AAGzC,gFAAgF;A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,CAAC;QACd,KAAK,IAAI;YACP,UAAU,EAAE,CAAC;YACb,MAAM;QAER,KAAK,SAAS,CAAC;QACf,KAAK,WAAW,CAAC;QACjB,KAAK,IAAI;YACP,OAAO,CAAC,GAAG,CAAC,gBAAgB,WAAW,EAAE,CAAC,CAAC;YAC3C,MAAM;QAER;YACE,OAAO,CAAC,KAAK,CAAC,oBAAoB,OAAO,IAAI,CAAC,CAAC;YAC/C,UAAU,EAAE,CAAC;YACb,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IACpB,CAAC;AACH,CAAC;AAED,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE;IACrB,OAAO,CAAC,KAAK,CAAC,cAAc,EAAE,KAAK,CAAC,CAAC;IACrC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC,CAAC"}
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Admin Dashboard — Embedded HTML dashboard for PayGate MCP.
3
+ *
4
+ * Served at GET /dashboard. Admin key entered via browser prompt.
5
+ * Uses only inline CSS and vanilla JS — no external dependencies.
6
+ * All dynamic content is escaped to prevent XSS.
7
+ *
8
+ * Features:
9
+ * - Overview cards: active keys, total calls, credits spent, denied
10
+ * - Top tools breakdown (bar chart)
11
+ * - Recent activity feed
12
+ * - Key management (create, revoke, top-up)
13
+ * - Auto-refresh every 30s
14
+ */
15
+ export declare function getDashboardHtml(serverName: string): string;
16
+ //# sourceMappingURL=dashboard.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dashboard.d.ts","sourceRoot":"","sources":["../src/dashboard.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,wBAAgB,gBAAgB,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM,CAyZ3D"}