drain-mcp 0.2.2 → 0.2.3
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 +151 -31
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
# DRAIN MCP Server
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
**Payments for AI Agents** — No API keys, no credit cards, no subscriptions.
|
|
4
|
+
|
|
5
|
+
MCP server for the DRAIN payment protocol. Agents discover service providers, open USDC payment channels on Polygon, and call any service — LLM inference, web scraping, image generation, VPN, and more.
|
|
6
|
+
|
|
7
|
+
- **One-time gas cost:** ~$0.02 to open a channel
|
|
8
|
+
- **Per request:** $0.0001–$0.01 depending on service
|
|
9
|
+
- **Setup time:** 30 seconds
|
|
4
10
|
|
|
5
11
|
## When to Use DRAIN
|
|
6
12
|
|
|
@@ -12,7 +18,6 @@ Use DRAIN when you need to:
|
|
|
12
18
|
Do NOT use DRAIN when:
|
|
13
19
|
- You already have API keys for the service you need
|
|
14
20
|
- The task doesn't require external services
|
|
15
|
-
- Cost is not a concern (DRAIN adds ~$0.04 blockchain overhead per session)
|
|
16
21
|
|
|
17
22
|
---
|
|
18
23
|
|
|
@@ -25,15 +30,57 @@ Do NOT use DRAIN when:
|
|
|
25
30
|
4. drain_approve() → Approve USDC spending (once)
|
|
26
31
|
5. drain_open_channel(...) → Deposit USDC, get channelId
|
|
27
32
|
6. drain_chat(...) → Send requests (repeat as needed)
|
|
28
|
-
7.
|
|
33
|
+
7. drain_cooperative_close(...) → Close early, instant refund (when task is done)
|
|
34
|
+
— OR after expiry —
|
|
29
35
|
8. drain_close_channel(...) → Reclaim funds (after expiry)
|
|
30
36
|
```
|
|
31
37
|
|
|
32
38
|
---
|
|
33
39
|
|
|
40
|
+
## When to Close a Channel
|
|
41
|
+
|
|
42
|
+
- **Done with your task?** → Use `drain_cooperative_close(channelId)`.
|
|
43
|
+
Instant refund of unspent deposit. Always do this when finished.
|
|
44
|
+
|
|
45
|
+
- **Planning more requests soon?** → Keep the channel open.
|
|
46
|
+
No need to close and reopen — saves $0.04 in gas fees.
|
|
47
|
+
|
|
48
|
+
- **Channel expired?** → Use `drain_close_channel(channelId)`.
|
|
49
|
+
Reclaims unspent USDC after the expiry timestamp.
|
|
50
|
+
Funds do NOT return automatically.
|
|
51
|
+
|
|
52
|
+
**Rule of thumb:** Close when the task is done. Keep open while working.
|
|
53
|
+
|
|
54
|
+
---
|
|
55
|
+
|
|
56
|
+
## Already Hit a 402?
|
|
57
|
+
|
|
58
|
+
DRAIN providers return `402 Payment Required` with headers when no payment voucher is sent:
|
|
59
|
+
|
|
60
|
+
| Header | Value |
|
|
61
|
+
|---|---|
|
|
62
|
+
| `X-Payment-Protocol` | `drain-v2` |
|
|
63
|
+
| `X-Payment-Provider` | Provider wallet address (open channel to this) |
|
|
64
|
+
| `X-Payment-Contract` | DRAIN contract address |
|
|
65
|
+
| `X-Payment-Chain` | `137` (Polygon Mainnet) |
|
|
66
|
+
| `X-Payment-Signing` | URL for EIP-712 signing parameters |
|
|
67
|
+
| `X-Payment-Docs` | Provider docs endpoint |
|
|
68
|
+
|
|
69
|
+
**Flow:**
|
|
70
|
+
1. Call a provider endpoint (no voucher) → get `402` with headers
|
|
71
|
+
2. Install `drain-mcp` or use the signing API at the `X-Payment-Signing` URL
|
|
72
|
+
3. Open a channel to the `X-Payment-Provider` address
|
|
73
|
+
4. Retry the request with an `X-DRAIN-Voucher` header
|
|
74
|
+
|
|
75
|
+
Everything you need is in the 402 response. No prior registration required.
|
|
76
|
+
|
|
77
|
+
---
|
|
78
|
+
|
|
34
79
|
## Tools Reference
|
|
35
80
|
|
|
36
|
-
###
|
|
81
|
+
### Discovery
|
|
82
|
+
|
|
83
|
+
#### drain_providers
|
|
37
84
|
Find service providers. Filter by model name, category, or online status.
|
|
38
85
|
|
|
39
86
|
```json
|
|
@@ -46,24 +93,28 @@ Find service providers. Filter by model name, category, or online status.
|
|
|
46
93
|
|
|
47
94
|
Categories: `llm`, `image`, `audio`, `code`, `scraping`, `vpn`, `multi-modal`, `other`
|
|
48
95
|
|
|
49
|
-
|
|
96
|
+
#### drain_provider_info
|
|
50
97
|
Get details about a provider including usage instructions (docs). The docs explain how to format requests for that provider.
|
|
51
98
|
|
|
52
99
|
```json
|
|
53
100
|
{ "providerId": "hs58-openai" }
|
|
54
101
|
```
|
|
55
102
|
|
|
56
|
-
###
|
|
103
|
+
### Wallet
|
|
104
|
+
|
|
105
|
+
#### drain_balance
|
|
57
106
|
Check wallet USDC balance, POL for gas, and DRAIN contract allowance.
|
|
58
107
|
|
|
59
|
-
|
|
108
|
+
#### drain_approve
|
|
60
109
|
Approve USDC spending for the DRAIN contract. Required once before opening channels.
|
|
61
110
|
|
|
62
111
|
```json
|
|
63
112
|
{ "amount": "100" }
|
|
64
113
|
```
|
|
65
114
|
|
|
66
|
-
###
|
|
115
|
+
### Channels
|
|
116
|
+
|
|
117
|
+
#### drain_open_channel
|
|
67
118
|
Open a payment channel. Locks USDC for the specified duration.
|
|
68
119
|
|
|
69
120
|
```json
|
|
@@ -74,9 +125,17 @@ Open a payment channel. Locks USDC for the specified duration.
|
|
|
74
125
|
}
|
|
75
126
|
```
|
|
76
127
|
|
|
77
|
-
Returns channelId, expiry time, and provider usage docs.
|
|
128
|
+
Returns channelId, expiry time, and provider usage docs.
|
|
129
|
+
|
|
130
|
+
#### drain_channel_status
|
|
131
|
+
Check a channel's deposit, spending, remaining balance, and expiry.
|
|
78
132
|
|
|
79
|
-
|
|
133
|
+
#### drain_channels
|
|
134
|
+
List all known channels with status (active/expired/closed). Find expired channels that need closing.
|
|
135
|
+
|
|
136
|
+
### Usage
|
|
137
|
+
|
|
138
|
+
#### drain_chat
|
|
80
139
|
Send a paid request through a channel. Works for ALL provider types:
|
|
81
140
|
|
|
82
141
|
- **LLM providers:** Standard chat messages
|
|
@@ -90,14 +149,42 @@ Send a paid request through a channel. Works for ALL provider types:
|
|
|
90
149
|
}
|
|
91
150
|
```
|
|
92
151
|
|
|
93
|
-
###
|
|
94
|
-
Check a channel's deposit, spending, remaining balance, and expiry.
|
|
152
|
+
### Settlement
|
|
95
153
|
|
|
96
|
-
|
|
97
|
-
|
|
154
|
+
#### drain_cooperative_close
|
|
155
|
+
Close a channel early with provider consent. **Use this when your task is done** — instant refund of unspent deposit. No need to wait for expiry.
|
|
156
|
+
|
|
157
|
+
```json
|
|
158
|
+
{ "channelId": "0x..." }
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
#### drain_close_channel
|
|
162
|
+
Close an expired channel and reclaim unspent USDC. Use when the channel has passed its expiry timestamp.
|
|
163
|
+
|
|
164
|
+
```json
|
|
165
|
+
{ "channelId": "0x..." }
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
---
|
|
169
|
+
|
|
170
|
+
## Economics Example
|
|
98
171
|
|
|
99
|
-
|
|
100
|
-
|
|
172
|
+
Opening a GPT-4o channel:
|
|
173
|
+
|
|
174
|
+
```
|
|
175
|
+
Gas to open channel: $0.02 (one-time)
|
|
176
|
+
Deposit: $0.50 (refundable remainder)
|
|
177
|
+
Per request: ~$0.001755
|
|
178
|
+
Requests possible: ~285
|
|
179
|
+
|
|
180
|
+
Cost for 10 requests: $0.02 gas + $0.01755 usage = $0.04
|
|
181
|
+
Refund after close: $0.50 - $0.01755 = $0.48
|
|
182
|
+
Gas to close: $0.02
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
- Protocol fee: 2% on provider claims (on-chain)
|
|
186
|
+
- Session fee: none
|
|
187
|
+
- Live pricing: `GET https://handshake58.com/api/mcp/providers`
|
|
101
188
|
|
|
102
189
|
---
|
|
103
190
|
|
|
@@ -107,11 +194,11 @@ Providers are not limited to LLM chat. Each provider has a `category` field and
|
|
|
107
194
|
|
|
108
195
|
| Category | Description | Message Format |
|
|
109
196
|
|----------|-------------|----------------|
|
|
110
|
-
| llm | Language models | Standard chat messages |
|
|
197
|
+
| llm | Language models (GPT-4o, Claude, Grok, Gemini) | Standard chat messages |
|
|
111
198
|
| image | Image generation | JSON in user content (see docs) |
|
|
112
199
|
| audio | Audio/TTS/STT | JSON in user content (see docs) |
|
|
113
200
|
| code | Code generation | Standard chat or JSON (see docs) |
|
|
114
|
-
| scraping | Web scraping | JSON in user content (see docs) |
|
|
201
|
+
| scraping | Web scraping, data extraction | JSON in user content (see docs) |
|
|
115
202
|
| vpn | VPN services | JSON in user content (see docs) |
|
|
116
203
|
| multi-modal | Multi-modal models | Standard chat messages |
|
|
117
204
|
| other | Everything else | Always check docs |
|
|
@@ -139,6 +226,16 @@ Do I have an active channel?
|
|
|
139
226
|
│ │ └── drain_chat() → Send requests
|
|
140
227
|
```
|
|
141
228
|
|
|
229
|
+
### Ending a Session
|
|
230
|
+
|
|
231
|
+
```
|
|
232
|
+
Am I done with this task?
|
|
233
|
+
├── YES → drain_cooperative_close(channelId) → Instant refund
|
|
234
|
+
└── NO →
|
|
235
|
+
├── More requests soon? → Keep channel open
|
|
236
|
+
└── Channel expired? → drain_close_channel(channelId) → Reclaim funds
|
|
237
|
+
```
|
|
238
|
+
|
|
142
239
|
### Choosing Amount and Duration
|
|
143
240
|
|
|
144
241
|
| Use Case | Amount | Duration |
|
|
@@ -175,17 +272,36 @@ Do I have an active channel?
|
|
|
175
272
|
|
|
176
273
|
## Setup
|
|
177
274
|
|
|
178
|
-
###
|
|
275
|
+
### 1. Install
|
|
276
|
+
|
|
277
|
+
```bash
|
|
278
|
+
npm install -g drain-mcp
|
|
279
|
+
```
|
|
280
|
+
|
|
281
|
+
### 2. Create a Wallet (locally)
|
|
179
282
|
|
|
180
|
-
|
|
181
|
-
2. **Create wallet** — `require('viem').generatePrivateKey()` or ask user for existing key
|
|
182
|
-
3. **Configure** — Add to MCP client config (see below)
|
|
283
|
+
Generate a key on your own machine — nothing is sent over the network:
|
|
183
284
|
|
|
184
|
-
|
|
285
|
+
```bash
|
|
286
|
+
node -e "const w=require('ethers').Wallet.createRandom();console.log('Address:', w.address, '\nKey:', w.privateKey)"
|
|
287
|
+
```
|
|
288
|
+
|
|
289
|
+
### 3. Fund the Wallet
|
|
290
|
+
|
|
291
|
+
Send **$1–5 USDC** on **Polygon Mainnet** to your wallet address.
|
|
292
|
+
Use a dedicated low-value wallet — never your main wallet.
|
|
293
|
+
|
|
294
|
+
**No POL needed** — if your wallet holds $5+ USDC, free gas is provided:
|
|
295
|
+
|
|
296
|
+
```bash
|
|
297
|
+
curl -X POST https://handshake58.com/api/gas-station \
|
|
298
|
+
-H "Content-Type: application/json" \
|
|
299
|
+
-d '{"address": "0x_your_wallet_address"}'
|
|
300
|
+
```
|
|
185
301
|
|
|
186
|
-
|
|
302
|
+
Returns 0.1 POL (~10K transactions). Sends only your public address.
|
|
187
303
|
|
|
188
|
-
### MCP
|
|
304
|
+
### 4. Configure MCP Client
|
|
189
305
|
|
|
190
306
|
```json
|
|
191
307
|
{
|
|
@@ -204,7 +320,7 @@ Do I have an active channel?
|
|
|
204
320
|
|----------|----------|---------|
|
|
205
321
|
| `DRAIN_PRIVATE_KEY` | Yes | — |
|
|
206
322
|
| `DRAIN_CHAIN_ID` | No | 137 (Polygon) |
|
|
207
|
-
| `DRAIN_RPC_URL` | No |
|
|
323
|
+
| `DRAIN_RPC_URL` | No | Public RPC |
|
|
208
324
|
|
|
209
325
|
---
|
|
210
326
|
|
|
@@ -221,7 +337,7 @@ The key is never transmitted to any server. Providers verify signatures against
|
|
|
221
337
|
Exposure is capped by the smart contract:
|
|
222
338
|
- Maximum spend = channel deposit (you choose the amount)
|
|
223
339
|
- Channel has a fixed duration (you choose)
|
|
224
|
-
- After expiry, unspent funds are reclaimable via drain_close_channel
|
|
340
|
+
- After expiry, unspent funds are reclaimable via `drain_close_channel`
|
|
225
341
|
- No recurring charges, no stored payment methods
|
|
226
342
|
|
|
227
343
|
### What Leaves Your Machine
|
|
@@ -243,14 +359,17 @@ Every network request the MCP server makes:
|
|
|
243
359
|
| handshake58.com/api/mcp/providers | GET | Nothing (public catalog) | No |
|
|
244
360
|
| handshake58.com/api/directory/config | GET | Nothing (reads fee wallet) | No |
|
|
245
361
|
| handshake58.com/api/channels/status | GET | channelId (public on-chain data) | No |
|
|
362
|
+
| handshake58.com/api/gas-station | POST | Wallet address | No |
|
|
246
363
|
| Provider apiUrl /v1/docs | GET | Nothing (fetches usage docs) | No |
|
|
247
364
|
| Provider apiUrl /v1/chat/completions | POST | Request messages + signed voucher | No |
|
|
365
|
+
| Provider apiUrl /v1/close-channel | POST | channelId + close signature | No |
|
|
248
366
|
| Polygon RPC (on-chain tx) | POST | Signed transactions | No |
|
|
249
367
|
|
|
250
368
|
### Safeguards
|
|
251
|
-
- Use a **dedicated wallet** with $1
|
|
252
|
-
- **
|
|
253
|
-
-
|
|
369
|
+
- Use a **dedicated wallet** with $1–5 USDC. Never reuse your main wallet.
|
|
370
|
+
- Always generate keys **locally**. The key stays on your machine.
|
|
371
|
+
- **Open source**: [github.com/kimbo128/DRAIN](https://github.com/kimbo128/DRAIN) (MIT licensed)
|
|
372
|
+
- Open channels with small deposits. Close promptly when done.
|
|
254
373
|
|
|
255
374
|
---
|
|
256
375
|
|
|
@@ -259,4 +378,5 @@ Every network request the MCP server makes:
|
|
|
259
378
|
- NPM: https://www.npmjs.com/package/drain-mcp
|
|
260
379
|
- GitHub: https://github.com/kimbo128/DRAIN
|
|
261
380
|
- Marketplace: https://handshake58.com
|
|
262
|
-
-
|
|
381
|
+
- Provider Directory: https://handshake58.com/directory
|
|
382
|
+
- Contract: `0x0C2B3aA1e80629D572b1f200e6DF3586B3946A8A` (Polygon Mainnet)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "drain-mcp",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.3",
|
|
4
4
|
"mcpName": "io.github.kimbo128/drain-mcp",
|
|
5
5
|
"description": "MCP server for DRAIN protocol. Agents discover providers, open USDC payment channels, and call any service — LLM, scraping, image, VPN, and more.",
|
|
6
6
|
"repository": {
|