paygate-mcp 0.1.4 → 0.6.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 +21 -0
- package/README.md +166 -21
- package/dist/cli.js +47 -26
- package/dist/cli.js.map +1 -1
- package/dist/dashboard.d.ts +16 -0
- package/dist/dashboard.d.ts.map +1 -0
- package/dist/dashboard.js +431 -0
- package/dist/dashboard.js.map +1 -0
- package/dist/gate.d.ts.map +1 -1
- package/dist/gate.js +11 -1
- package/dist/gate.js.map +1 -1
- package/dist/http-proxy.d.ts +63 -0
- package/dist/http-proxy.d.ts.map +1 -0
- package/dist/http-proxy.js +303 -0
- package/dist/http-proxy.js.map +1 -0
- package/dist/index.d.ts +4 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -1
- package/dist/index.js.map +1 -1
- package/dist/server.d.ts +13 -2
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +234 -4
- package/dist/server.js.map +1 -1
- package/dist/store.d.ts +33 -1
- package/dist/store.d.ts.map +1 -1
- package/dist/store.js +103 -0
- package/dist/store.js.map +1 -1
- package/dist/stripe.d.ts +58 -0
- package/dist/stripe.d.ts.map +1 -0
- package/dist/stripe.js +175 -0
- package/dist/stripe.js.map +1 -0
- package/dist/types.d.ts +8 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +8 -1
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
|
-
|
|
3
|
+
[](https://github.com/walker77/paygate-mcp/actions/workflows/ci.yml)
|
|
4
|
+
[](https://www.npmjs.com/package/paygate-mcp)
|
|
5
|
+
[](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
|
|
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,21 @@ 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
|
|
26
34
|
- **Shadow Mode** — Log everything without enforcing payment (for testing)
|
|
27
|
-
- **
|
|
35
|
+
- **Persistent Storage** — Keys and credits survive restarts with `--state-file`
|
|
36
|
+
- **Zero Dependencies** — No external npm packages. Uses only Node.js built-ins.
|
|
28
37
|
|
|
29
38
|
## Usage
|
|
30
39
|
|
|
31
|
-
###
|
|
40
|
+
### Wrap a Local MCP Server (stdio)
|
|
32
41
|
|
|
33
42
|
```bash
|
|
34
43
|
# Default: 1 credit per call, 60 calls/min, port 3402
|
|
@@ -50,6 +59,26 @@ npx paygate-mcp wrap \
|
|
|
50
59
|
npx paygate-mcp wrap --server "node server.js" --shadow
|
|
51
60
|
```
|
|
52
61
|
|
|
62
|
+
### Gate a Remote MCP Server (Streamable HTTP)
|
|
63
|
+
|
|
64
|
+
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):
|
|
65
|
+
|
|
66
|
+
```bash
|
|
67
|
+
npx paygate-mcp wrap --remote-url "https://my-mcp-server.example.com/mcp"
|
|
68
|
+
|
|
69
|
+
# With custom pricing
|
|
70
|
+
npx paygate-mcp wrap \
|
|
71
|
+
--remote-url "https://api.example.com/mcp" \
|
|
72
|
+
--price 5 \
|
|
73
|
+
--tool-price "gpt4:20,search:2"
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
The proxy handles:
|
|
77
|
+
- JSON-RPC forwarding via HTTP POST
|
|
78
|
+
- SSE (text/event-stream) response parsing
|
|
79
|
+
- `Mcp-Session-Id` session management
|
|
80
|
+
- Graceful session cleanup (HTTP DELETE on shutdown)
|
|
81
|
+
|
|
53
82
|
When started, you'll see your admin key in the console. Save it.
|
|
54
83
|
|
|
55
84
|
### Create API Keys
|
|
@@ -87,6 +116,54 @@ curl -X POST http://localhost:3402/topup \
|
|
|
87
116
|
-d '{"key": "CLIENT_API_KEY", "credits": 500}'
|
|
88
117
|
```
|
|
89
118
|
|
|
119
|
+
### Check Balance (Client Self-Service)
|
|
120
|
+
|
|
121
|
+
```bash
|
|
122
|
+
curl http://localhost:3402/balance \
|
|
123
|
+
-H "X-API-Key: CLIENT_API_KEY"
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
Returns credits, total spent, call count, and last used timestamp. If spending limits are set, also returns current daily/monthly spend and limits. Clients can check their own balance without needing admin access.
|
|
127
|
+
|
|
128
|
+
### Set Spending Limits (Admin)
|
|
129
|
+
|
|
130
|
+
```bash
|
|
131
|
+
# Set daily and monthly credit caps for a key
|
|
132
|
+
curl -X POST http://localhost:3402/keys/limits \
|
|
133
|
+
-H "Content-Type: application/json" \
|
|
134
|
+
-H "X-Admin-Key: YOUR_ADMIN_KEY" \
|
|
135
|
+
-d '{"key": "CLIENT_API_KEY", "dailyLimit": 50, "monthlyLimit": 500}'
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
Prevents runaway AI agents from draining credits. When a key's daily or monthly spend reaches its cap, further tool calls are denied until the next day/month (UTC). Set to 0 for unlimited.
|
|
139
|
+
|
|
140
|
+
You can also set limits when creating a key:
|
|
141
|
+
|
|
142
|
+
```bash
|
|
143
|
+
curl -X POST http://localhost:3402/keys \
|
|
144
|
+
-H "Content-Type: application/json" \
|
|
145
|
+
-H "X-Admin-Key: YOUR_ADMIN_KEY" \
|
|
146
|
+
-d '{"name": "agent-key", "credits": 1000, "dailyLimit": 50, "monthlyLimit": 500}'
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
### Export Usage Data (Admin)
|
|
150
|
+
|
|
151
|
+
```bash
|
|
152
|
+
# JSON export
|
|
153
|
+
curl http://localhost:3402/usage \
|
|
154
|
+
-H "X-Admin-Key: YOUR_ADMIN_KEY"
|
|
155
|
+
|
|
156
|
+
# CSV export (for spreadsheet/billing import)
|
|
157
|
+
curl "http://localhost:3402/usage?format=csv" \
|
|
158
|
+
-H "X-Admin-Key: YOUR_ADMIN_KEY"
|
|
159
|
+
|
|
160
|
+
# Filter by date
|
|
161
|
+
curl "http://localhost:3402/usage?since=2025-01-01T00:00:00Z" \
|
|
162
|
+
-H "X-Admin-Key: YOUR_ADMIN_KEY"
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
Returns per-call usage events with tool name, credits charged, and timestamps. API keys are masked in output.
|
|
166
|
+
|
|
90
167
|
### Check Status
|
|
91
168
|
|
|
92
169
|
```bash
|
|
@@ -96,16 +173,31 @@ curl http://localhost:3402/status \
|
|
|
96
173
|
|
|
97
174
|
Returns active keys, usage stats, per-tool breakdown, and deny reasons.
|
|
98
175
|
|
|
176
|
+
### Admin Dashboard
|
|
177
|
+
|
|
178
|
+
Open the web dashboard in your browser:
|
|
179
|
+
|
|
180
|
+
```
|
|
181
|
+
http://localhost:3402/dashboard
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
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.
|
|
185
|
+
|
|
99
186
|
## API Reference
|
|
100
187
|
|
|
101
188
|
| Endpoint | Method | Auth | Description |
|
|
102
189
|
|----------|--------|------|-------------|
|
|
103
190
|
| `/mcp` | POST | `X-API-Key` | JSON-RPC 2.0 proxy to wrapped MCP server |
|
|
191
|
+
| `/balance` | GET | `X-API-Key` | Client self-service — check own credits |
|
|
104
192
|
| `/keys` | POST | `X-Admin-Key` | Create a new API key with credits |
|
|
105
193
|
| `/keys` | GET | `X-Admin-Key` | List all keys (masked) |
|
|
106
194
|
| `/topup` | POST | `X-Admin-Key` | Add credits to an existing key |
|
|
107
195
|
| `/keys/revoke` | POST | `X-Admin-Key` | Revoke an API key |
|
|
196
|
+
| `/keys/limits` | POST | `X-Admin-Key` | Set daily/monthly spending limits |
|
|
197
|
+
| `/usage` | GET | `X-Admin-Key` | Export usage data (JSON or CSV) |
|
|
108
198
|
| `/status` | GET | `X-Admin-Key` | Full dashboard with usage stats |
|
|
199
|
+
| `/dashboard` | GET | None (admin key in-browser) | Real-time admin web dashboard |
|
|
200
|
+
| `/stripe/webhook` | POST | Stripe Signature | Auto-top-up credits on payment |
|
|
109
201
|
| `/` | GET | None | Health check |
|
|
110
202
|
|
|
111
203
|
### Free Methods
|
|
@@ -116,18 +208,24 @@ These MCP methods pass through without auth or billing:
|
|
|
116
208
|
## CLI Options
|
|
117
209
|
|
|
118
210
|
```
|
|
119
|
-
--server <cmd>
|
|
120
|
-
--
|
|
121
|
-
--
|
|
122
|
-
--
|
|
123
|
-
--
|
|
124
|
-
--
|
|
125
|
-
--
|
|
126
|
-
--
|
|
127
|
-
--
|
|
128
|
-
--
|
|
211
|
+
--server <cmd> MCP server command to wrap via stdio
|
|
212
|
+
--remote-url <url> Remote MCP server URL (Streamable HTTP transport)
|
|
213
|
+
--port <n> HTTP port (default: 3402)
|
|
214
|
+
--price <n> Default credits per tool call (default: 1)
|
|
215
|
+
--rate-limit <n> Max calls/min per key (default: 60, 0=unlimited)
|
|
216
|
+
--name <s> Server display name
|
|
217
|
+
--shadow Shadow mode — log without enforcing payment
|
|
218
|
+
--admin-key <s> Set admin key (default: auto-generated)
|
|
219
|
+
--tool-price <t:n> Per-tool price (e.g. "search:5,generate:10")
|
|
220
|
+
--import-key <k:c> Import existing key with credits (e.g. "pg_abc:100")
|
|
221
|
+
--state-file <path> Persist keys/credits to a JSON file (survives restarts)
|
|
222
|
+
--stripe-secret <s> Stripe webhook signing secret (enables /stripe/webhook)
|
|
223
|
+
--daily-limit <n> Default daily credit limit per key (0=unlimited)
|
|
224
|
+
--monthly-limit <n> Default monthly credit limit per key (0=unlimited)
|
|
129
225
|
```
|
|
130
226
|
|
|
227
|
+
> **Note:** Use `--server` OR `--remote-url`, not both.
|
|
228
|
+
|
|
131
229
|
### Persistent Storage
|
|
132
230
|
|
|
133
231
|
Add `--state-file` to save API keys and credits to disk. Data survives server restarts.
|
|
@@ -136,11 +234,39 @@ Add `--state-file` to save API keys and credits to disk. Data survives server re
|
|
|
136
234
|
npx paygate-mcp wrap --server "your-mcp-server" --state-file ~/.paygate/state.json
|
|
137
235
|
```
|
|
138
236
|
|
|
237
|
+
### Stripe Integration
|
|
238
|
+
|
|
239
|
+
Connect Stripe to automatically top up credits when customers pay:
|
|
240
|
+
|
|
241
|
+
```bash
|
|
242
|
+
npx paygate-mcp wrap \
|
|
243
|
+
--server "your-mcp-server" \
|
|
244
|
+
--state-file ~/.paygate/state.json \
|
|
245
|
+
--stripe-secret "whsec_your_stripe_webhook_secret"
|
|
246
|
+
```
|
|
247
|
+
|
|
248
|
+
**Setup:**
|
|
249
|
+
1. Create a Stripe Checkout Session with metadata:
|
|
250
|
+
- `paygate_api_key` — the customer's API key (e.g. `pg_abc123...`)
|
|
251
|
+
- `paygate_credits` — credits to add on payment (e.g. `500`)
|
|
252
|
+
2. Point your Stripe webhook to `https://your-server/stripe/webhook`
|
|
253
|
+
3. Subscribe to `checkout.session.completed` and `invoice.payment_succeeded` events
|
|
254
|
+
|
|
255
|
+
When a customer completes payment, credits are automatically added to their API key. Subscriptions auto-renew credits on each billing cycle.
|
|
256
|
+
|
|
257
|
+
**Security:**
|
|
258
|
+
- HMAC-SHA256 signature verification (Stripe's v1 scheme)
|
|
259
|
+
- Timing-safe comparison to prevent timing attacks
|
|
260
|
+
- 5-minute timestamp tolerance to prevent replay attacks
|
|
261
|
+
- Payment status verification (only `paid` triggers credits)
|
|
262
|
+
- Zero dependencies — uses Node.js built-in `crypto`
|
|
263
|
+
|
|
139
264
|
## Programmatic API
|
|
140
265
|
|
|
141
266
|
```typescript
|
|
142
|
-
import { PayGateServer } from 'paygate-mcp';
|
|
267
|
+
import { PayGateServer, HttpMcpProxy } from 'paygate-mcp';
|
|
143
268
|
|
|
269
|
+
// Wrap a local server (stdio)
|
|
144
270
|
const server = new PayGateServer({
|
|
145
271
|
serverCommand: 'npx',
|
|
146
272
|
serverArgs: ['@modelcontextprotocol/server-filesystem', '/tmp'],
|
|
@@ -151,6 +277,13 @@ const server = new PayGateServer({
|
|
|
151
277
|
},
|
|
152
278
|
});
|
|
153
279
|
|
|
280
|
+
// Or gate a remote server (Streamable HTTP)
|
|
281
|
+
const remoteServer = new PayGateServer({
|
|
282
|
+
serverCommand: '',
|
|
283
|
+
port: 3402,
|
|
284
|
+
defaultCreditsPerCall: 5,
|
|
285
|
+
}, undefined, undefined, 'https://my-mcp-server.example.com/mcp');
|
|
286
|
+
|
|
154
287
|
const { port, adminKey } = await server.start();
|
|
155
288
|
```
|
|
156
289
|
|
|
@@ -162,21 +295,33 @@ const { port, adminKey } = await server.start();
|
|
|
162
295
|
- 1MB request body limit
|
|
163
296
|
- Input sanitization on all endpoints
|
|
164
297
|
- Admin key never exposed in responses
|
|
298
|
+
- API keys never forwarded to remote servers (HTTP transport)
|
|
165
299
|
- Rate limiting is per-key, concurrent-safe
|
|
300
|
+
- Stripe webhook signature verification (HMAC-SHA256, timing-safe)
|
|
301
|
+
- Per-key daily/monthly spending caps (budget protection)
|
|
302
|
+
- Dashboard uses safe DOM methods (textContent/createElement) — no innerHTML
|
|
303
|
+
- Red-teamed with 78 adversarial security tests across 9 passes
|
|
166
304
|
|
|
167
305
|
## Current Limitations
|
|
168
306
|
|
|
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
307
|
- **Single process** — No clustering or horizontal scaling.
|
|
172
|
-
- **
|
|
308
|
+
- **No response size limits for HTTP transport** — Large responses from remote servers are forwarded as-is.
|
|
309
|
+
|
|
310
|
+
## Roadmap
|
|
173
311
|
|
|
174
|
-
Persistent storage
|
|
312
|
+
- [x] Persistent storage (`--state-file`)
|
|
313
|
+
- [x] Streamable HTTP transport (`--remote-url`)
|
|
314
|
+
- [x] Stripe webhook integration (`--stripe-secret`)
|
|
315
|
+
- [x] Client self-service balance check (`/balance`)
|
|
316
|
+
- [x] Usage data export — JSON and CSV (`/usage`)
|
|
317
|
+
- [x] Admin web dashboard (`/dashboard`)
|
|
318
|
+
- [x] Per-key spending limits — daily/monthly budget caps
|
|
319
|
+
- [ ] Multi-tenant mode
|
|
175
320
|
|
|
176
321
|
## Requirements
|
|
177
322
|
|
|
178
323
|
- Node.js >= 18.0.0
|
|
179
|
-
-
|
|
324
|
+
- Zero external dependencies
|
|
180
325
|
|
|
181
326
|
## License
|
|
182
327
|
|
package/dist/cli.js
CHANGED
|
@@ -36,25 +36,34 @@ function printUsage() {
|
|
|
36
36
|
paygate-mcp — Monetize any MCP server with one command.
|
|
37
37
|
|
|
38
38
|
USAGE:
|
|
39
|
-
paygate-mcp wrap --server <command> [options]
|
|
39
|
+
paygate-mcp wrap --server <command> [options] # stdio transport
|
|
40
|
+
paygate-mcp wrap --remote-url <url> [options] # Streamable HTTP transport
|
|
40
41
|
|
|
41
42
|
OPTIONS:
|
|
42
|
-
--server <cmd>
|
|
43
|
-
|
|
44
|
-
--
|
|
45
|
-
|
|
46
|
-
--
|
|
47
|
-
--
|
|
48
|
-
--
|
|
49
|
-
--
|
|
50
|
-
--
|
|
51
|
-
--
|
|
52
|
-
--
|
|
43
|
+
--server <cmd> MCP server command to wrap via stdio (required unless --remote-url)
|
|
44
|
+
e.g. "npx @modelcontextprotocol/server-filesystem /"
|
|
45
|
+
--remote-url <url> Remote MCP server URL (Streamable HTTP transport)
|
|
46
|
+
e.g. "https://my-mcp-server.example.com/mcp"
|
|
47
|
+
--port <n> HTTP port (default: 3402)
|
|
48
|
+
--price <n> Default credits per tool call (default: 1)
|
|
49
|
+
--rate-limit <n> Max calls/min per key (default: 60, 0=unlimited)
|
|
50
|
+
--name <s> Server display name (default: "PayGate MCP Server")
|
|
51
|
+
--shadow Shadow mode — log but don't enforce payment
|
|
52
|
+
--admin-key <s> Set admin key (default: auto-generated)
|
|
53
|
+
--tool-price <t:n> Per-tool price override (e.g. "search:5,generate:10")
|
|
54
|
+
--import-key <k:c> Import an existing API key with credits (e.g. "pg_abc123:100")
|
|
55
|
+
--state-file <path> Persist keys/credits to a JSON file (survives restarts)
|
|
56
|
+
--stripe-secret <s> Stripe webhook signing secret (enables /stripe/webhook endpoint)
|
|
57
|
+
--daily-limit <n> Default daily credit limit per key (0=unlimited)
|
|
58
|
+
--monthly-limit <n> Default monthly credit limit per key (0=unlimited)
|
|
53
59
|
|
|
54
60
|
EXAMPLES:
|
|
55
|
-
# Wrap a
|
|
61
|
+
# Wrap a local MCP server (stdio transport)
|
|
56
62
|
paygate-mcp wrap --server "npx @modelcontextprotocol/server-filesystem /tmp"
|
|
57
63
|
|
|
64
|
+
# Gate a remote MCP server (Streamable HTTP transport)
|
|
65
|
+
paygate-mcp wrap --remote-url "https://my-server.example.com/mcp" --price 5
|
|
66
|
+
|
|
58
67
|
# Custom pricing and rate limit
|
|
59
68
|
paygate-mcp wrap --server "python my-server.py" --price 2 --rate-limit 30
|
|
60
69
|
|
|
@@ -82,15 +91,24 @@ async function main() {
|
|
|
82
91
|
switch (command) {
|
|
83
92
|
case 'wrap': {
|
|
84
93
|
const serverCmd = flags['server'];
|
|
85
|
-
|
|
86
|
-
|
|
94
|
+
const remoteUrl = flags['remote-url'];
|
|
95
|
+
if (!serverCmd && !remoteUrl) {
|
|
96
|
+
console.error('Error: --server or --remote-url is required.\n');
|
|
87
97
|
printUsage();
|
|
88
98
|
process.exit(1);
|
|
89
99
|
}
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
100
|
+
if (serverCmd && remoteUrl) {
|
|
101
|
+
console.error('Error: use --server OR --remote-url, not both.\n');
|
|
102
|
+
process.exit(1);
|
|
103
|
+
}
|
|
104
|
+
// Parse server command into command + args (stdio mode)
|
|
105
|
+
let serverCommand = '';
|
|
106
|
+
let serverArgs = [];
|
|
107
|
+
if (serverCmd) {
|
|
108
|
+
const parts = serverCmd.split(/\s+/);
|
|
109
|
+
serverCommand = parts[0];
|
|
110
|
+
serverArgs = parts.slice(1);
|
|
111
|
+
}
|
|
94
112
|
const port = parseInt(flags['port'] || '3402', 10);
|
|
95
113
|
const price = parseInt(flags['price'] || '1', 10);
|
|
96
114
|
const rateLimit = parseInt(flags['rate-limit'] || '60', 10);
|
|
@@ -99,6 +117,7 @@ async function main() {
|
|
|
99
117
|
const adminKey = flags['admin-key'];
|
|
100
118
|
const toolPricing = flags['tool-price'] ? parseToolPricing(flags['tool-price']) : {};
|
|
101
119
|
const stateFile = flags['state-file'];
|
|
120
|
+
const stripeSecret = flags['stripe-secret'];
|
|
102
121
|
const server = new server_1.PayGateServer({
|
|
103
122
|
serverCommand,
|
|
104
123
|
serverArgs,
|
|
@@ -108,7 +127,7 @@ async function main() {
|
|
|
108
127
|
name,
|
|
109
128
|
shadowMode: !!shadowMode,
|
|
110
129
|
toolPricing,
|
|
111
|
-
}, adminKey, stateFile);
|
|
130
|
+
}, adminKey, stateFile, remoteUrl, stripeSecret);
|
|
112
131
|
// Import keys if specified
|
|
113
132
|
if (flags['import-key']) {
|
|
114
133
|
const pairs = flags['import-key'].split(',');
|
|
@@ -136,18 +155,20 @@ async function main() {
|
|
|
136
155
|
║ ║
|
|
137
156
|
║ Endpoint: http://localhost:${String(result.port).padEnd(5)} ║
|
|
138
157
|
║ Admin Key: ${result.adminKey.slice(0, 20)}... ║
|
|
139
|
-
║
|
|
158
|
+
║ Backend: ${(remoteUrl ? 'HTTP → ' + remoteUrl.slice(0, 28) : 'stdio → ' + (serverCmd || '').slice(0, 27)).padEnd(35)}║
|
|
140
159
|
║ ║
|
|
141
160
|
║ Pricing: ${String(price).padEnd(3)} credit(s) per tool call ║
|
|
142
161
|
║ Rate Limit: ${String(rateLimit).padEnd(3)} calls/min per key ║
|
|
143
162
|
║ Shadow: ${String(!!shadowMode).padEnd(5)} ║
|
|
144
163
|
║ Persist: ${(stateFile ? stateFile.slice(0, 33) : 'off (in-memory)').padEnd(35)}║
|
|
164
|
+
║ Stripe: ${(stripeSecret ? 'enabled (/stripe/webhook)' : 'off').padEnd(35)}║
|
|
145
165
|
║ ║
|
|
146
166
|
╠══════════════════════════════════════════════════╣
|
|
147
|
-
║ POST /mcp
|
|
148
|
-
║ GET /
|
|
149
|
-
║
|
|
150
|
-
║ POST /
|
|
167
|
+
║ POST /mcp — JSON-RPC (X-API-Key header) ║
|
|
168
|
+
║ GET /dashboard — Admin web UI (open in browser)║
|
|
169
|
+
║ GET /balance — Client balance (X-API-Key) ║
|
|
170
|
+
║ POST /keys — Create key (X-Admin-Key) ║
|
|
171
|
+
║ POST /topup — Add credits (X-Admin-Key) ║
|
|
151
172
|
╚══════════════════════════════════════════════════╝
|
|
152
173
|
`);
|
|
153
174
|
console.log(` Admin key (save this): ${result.adminKey}\n`);
|
|
@@ -166,7 +187,7 @@ async function main() {
|
|
|
166
187
|
case 'version':
|
|
167
188
|
case '--version':
|
|
168
189
|
case '-v':
|
|
169
|
-
console.log('paygate-mcp v0.
|
|
190
|
+
console.log('paygate-mcp v0.6.0');
|
|
170
191
|
break;
|
|
171
192
|
default:
|
|
172
193
|
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,gF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,CAAC,MAAM,CAAC,EAAE,CAAC;mBACnE,CAAC,YAAY,CAAC,CAAC,CAAC,2BAA2B,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,EAAE,CAAC;;;;;;;;;CASjF,CAAC,CAAC;gBACK,OAAO,CAAC,GAAG,CAAC,4BAA4B,MAAM,CAAC,QAAQ,IAAI,CAAC,CAAC;YAC/D,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,OAAO,CAAC,KAAK,CAAC,yBAAyB,EAAE,KAAK,CAAC,CAAC;gBAChD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;YAClB,CAAC;YACD,MAAM;QACR,CAAC;QAED,KAAK,MAAM,CAAC;QACZ,KAAK,QAAQ,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,oBAAoB,CAAC,CAAC;YAClC,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"}
|