paygate-mcp 0.1.0 → 0.1.2
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 +165 -0
- package/dist/cli.js +1 -1
- package/package.json +1 -3
package/README.md
ADDED
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
# paygate-mcp
|
|
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.
|
|
4
|
+
|
|
5
|
+
## Quick Start
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
# Wrap any MCP server with pay-per-call billing
|
|
9
|
+
npx paygate-mcp wrap --server "npx @modelcontextprotocol/server-filesystem /tmp"
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
That's it. Your MCP server is now gated behind API keys with credit-based billing.
|
|
13
|
+
|
|
14
|
+
## What It Does
|
|
15
|
+
|
|
16
|
+
PayGate sits between AI agents and your MCP server:
|
|
17
|
+
|
|
18
|
+
```
|
|
19
|
+
Agent → PayGate (auth + billing) → Your MCP Server
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
- **API Key Auth** — Clients need a valid `X-API-Key` to call tools
|
|
23
|
+
- **Credit Billing** — Each tool call costs credits (configurable per-tool)
|
|
24
|
+
- **Rate Limiting** — Sliding window per-key rate limits
|
|
25
|
+
- **Usage Metering** — Track who called what, when, and how much they spent
|
|
26
|
+
- **Shadow Mode** — Log everything without enforcing payment (for testing)
|
|
27
|
+
- **Zero Config** — Works with any MCP server that uses stdio transport
|
|
28
|
+
|
|
29
|
+
## Usage
|
|
30
|
+
|
|
31
|
+
### Start a Gated Server
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
# Default: 1 credit per call, 60 calls/min, port 3402
|
|
35
|
+
npx paygate-mcp wrap --server "npx @modelcontextprotocol/server-filesystem /tmp"
|
|
36
|
+
|
|
37
|
+
# Custom pricing and limits
|
|
38
|
+
npx paygate-mcp wrap \
|
|
39
|
+
--server "python my-server.py" \
|
|
40
|
+
--price 2 \
|
|
41
|
+
--rate-limit 30 \
|
|
42
|
+
--port 8080
|
|
43
|
+
|
|
44
|
+
# Per-tool pricing
|
|
45
|
+
npx paygate-mcp wrap \
|
|
46
|
+
--server "node server.js" \
|
|
47
|
+
--tool-price "search:1,generate:5,premium_analyze:20"
|
|
48
|
+
|
|
49
|
+
# Shadow mode (observe without enforcing)
|
|
50
|
+
npx paygate-mcp wrap --server "node server.js" --shadow
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
When started, you'll see your admin key in the console. Save it.
|
|
54
|
+
|
|
55
|
+
### Create API Keys
|
|
56
|
+
|
|
57
|
+
```bash
|
|
58
|
+
curl -X POST http://localhost:3402/keys \
|
|
59
|
+
-H "Content-Type: application/json" \
|
|
60
|
+
-H "X-Admin-Key: YOUR_ADMIN_KEY" \
|
|
61
|
+
-d '{"name": "my-client", "credits": 100}'
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
### Call Tools
|
|
65
|
+
|
|
66
|
+
```bash
|
|
67
|
+
curl -X POST http://localhost:3402/mcp \
|
|
68
|
+
-H "Content-Type: application/json" \
|
|
69
|
+
-H "X-API-Key: CLIENT_API_KEY" \
|
|
70
|
+
-d '{
|
|
71
|
+
"jsonrpc": "2.0",
|
|
72
|
+
"id": 1,
|
|
73
|
+
"method": "tools/call",
|
|
74
|
+
"params": {
|
|
75
|
+
"name": "read_file",
|
|
76
|
+
"arguments": {"path": "/tmp/test.txt"}
|
|
77
|
+
}
|
|
78
|
+
}'
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
### Top Up Credits
|
|
82
|
+
|
|
83
|
+
```bash
|
|
84
|
+
curl -X POST http://localhost:3402/topup \
|
|
85
|
+
-H "Content-Type: application/json" \
|
|
86
|
+
-H "X-Admin-Key: YOUR_ADMIN_KEY" \
|
|
87
|
+
-d '{"key": "CLIENT_API_KEY", "credits": 500}'
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
### Check Status
|
|
91
|
+
|
|
92
|
+
```bash
|
|
93
|
+
curl http://localhost:3402/status \
|
|
94
|
+
-H "X-Admin-Key: YOUR_ADMIN_KEY"
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
Returns active keys, usage stats, per-tool breakdown, and deny reasons.
|
|
98
|
+
|
|
99
|
+
## API Reference
|
|
100
|
+
|
|
101
|
+
| Endpoint | Method | Auth | Description |
|
|
102
|
+
|----------|--------|------|-------------|
|
|
103
|
+
| `/mcp` | POST | `X-API-Key` | JSON-RPC 2.0 proxy to wrapped MCP server |
|
|
104
|
+
| `/keys` | POST | `X-Admin-Key` | Create a new API key with credits |
|
|
105
|
+
| `/keys` | GET | `X-Admin-Key` | List all keys (masked) |
|
|
106
|
+
| `/topup` | POST | `X-Admin-Key` | Add credits to an existing key |
|
|
107
|
+
| `/keys/revoke` | POST | `X-Admin-Key` | Revoke an API key |
|
|
108
|
+
| `/status` | GET | `X-Admin-Key` | Full dashboard with usage stats |
|
|
109
|
+
| `/` | GET | None | Health check |
|
|
110
|
+
|
|
111
|
+
### Free Methods
|
|
112
|
+
|
|
113
|
+
These MCP methods pass through without auth or billing:
|
|
114
|
+
`initialize`, `initialized`, `ping`, `tools/list`, `resources/list`, `prompts/list`
|
|
115
|
+
|
|
116
|
+
## CLI Options
|
|
117
|
+
|
|
118
|
+
```
|
|
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
|
+
```
|
|
129
|
+
|
|
130
|
+
## Programmatic API
|
|
131
|
+
|
|
132
|
+
```typescript
|
|
133
|
+
import { PayGateServer } from 'paygate-mcp';
|
|
134
|
+
|
|
135
|
+
const server = new PayGateServer({
|
|
136
|
+
serverCommand: 'npx',
|
|
137
|
+
serverArgs: ['@modelcontextprotocol/server-filesystem', '/tmp'],
|
|
138
|
+
port: 3402,
|
|
139
|
+
defaultCreditsPerCall: 1,
|
|
140
|
+
toolPricing: {
|
|
141
|
+
'premium_analyze': { creditsPerCall: 10 }
|
|
142
|
+
},
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
const { port, adminKey } = await server.start();
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
## Security
|
|
149
|
+
|
|
150
|
+
- Cryptographic API key generation (`pg_` prefix, 48 hex chars)
|
|
151
|
+
- Keys masked in list endpoints
|
|
152
|
+
- Integer-only credits (no float precision attacks)
|
|
153
|
+
- 1MB request body limit
|
|
154
|
+
- Input sanitization on all endpoints
|
|
155
|
+
- Admin key never exposed in responses
|
|
156
|
+
- Rate limiting is per-key, concurrent-safe
|
|
157
|
+
|
|
158
|
+
## Requirements
|
|
159
|
+
|
|
160
|
+
- Node.js >= 18.0.0
|
|
161
|
+
- Any MCP server that uses stdio transport
|
|
162
|
+
|
|
163
|
+
## License
|
|
164
|
+
|
|
165
|
+
MIT
|
package/dist/cli.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "paygate-mcp",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "Pay-per-tool-call gating proxy for MCP servers. Wrap any MCP server with API key auth, per-tool pricing, rate limiting, and usage metering.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -25,7 +25,5 @@
|
|
|
25
25
|
},
|
|
26
26
|
"keywords": ["mcp", "paygate", "monetize", "pay-per-call", "api-key", "rate-limit", "model-context-protocol", "ai-agent", "billing"],
|
|
27
27
|
"license": "MIT",
|
|
28
|
-
"repository": { "type": "git", "url": "https://github.com/walker77/AgentEscrow.git" },
|
|
29
|
-
"homepage": "https://payproof.dev",
|
|
30
28
|
"engines": { "node": ">=18.0.0" }
|
|
31
29
|
}
|