drain-mcp 0.1.9 → 0.1.11
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 +423 -421
- package/dist/config.d.ts.map +1 -1
- package/dist/index.js +66 -66
- package/dist/index.js.map +1 -1
- package/dist/services/channel.d.ts +10 -0
- package/dist/services/channel.d.ts.map +1 -1
- package/dist/services/channel.js +15 -0
- package/dist/services/channel.js.map +1 -1
- package/dist/tools/channel.d.ts.map +1 -1
- package/dist/tools/channel.js +54 -52
- package/dist/tools/channel.js.map +1 -1
- package/dist/tools/chat.d.ts.map +1 -1
- package/dist/tools/chat.js +6 -2
- package/dist/tools/chat.js.map +1 -1
- package/package.json +50 -50
package/README.md
CHANGED
|
@@ -1,421 +1,423 @@
|
|
|
1
|
-
# DRAIN MCP Server
|
|
2
|
-
|
|
3
|
-
MCP server for AI agent payments. Works with Cursor, Claude Desktop, Cline, Windsurf, and any MCP-compatible client. Pay for AI inference with USDC on Polygon — no API keys needed.
|
|
4
|
-
|
|
5
|
-
## When to Use DRAIN
|
|
6
|
-
|
|
7
|
-
Use DRAIN when you need to:
|
|
8
|
-
- Call AI models (GPT-4, Claude, etc.) without API keys
|
|
9
|
-
- Pay per-request with cryptocurrency
|
|
10
|
-
- Operate autonomously without human payment setup
|
|
11
|
-
|
|
12
|
-
Do NOT use DRAIN when:
|
|
13
|
-
- You already have API keys for the model you need
|
|
14
|
-
- The task doesn't require external AI inference
|
|
15
|
-
- Cost is not a concern (DRAIN adds ~$0.04 blockchain overhead per session)
|
|
16
|
-
|
|
17
|
-
---
|
|
18
|
-
|
|
19
|
-
## TL;DR - Minimum Viable Workflow
|
|
20
|
-
|
|
21
|
-
```
|
|
22
|
-
1. drain_balance() → Check if you have USDC
|
|
23
|
-
2. drain_providers() → Find a provider with your model
|
|
24
|
-
3. drain_open_channel(...) → Deposit USDC (one-time per session)
|
|
25
|
-
4. drain_chat(...) → Use AI (repeat as needed)
|
|
26
|
-
5. drain_close_channel(...) → Get refund (after expiry)
|
|
27
|
-
```
|
|
28
|
-
|
|
29
|
-
---
|
|
30
|
-
|
|
31
|
-
## Tools Reference
|
|
32
|
-
|
|
33
|
-
### drain_providers
|
|
34
|
-
Find AI providers.
|
|
35
|
-
|
|
36
|
-
```json
|
|
37
|
-
{
|
|
38
|
-
"model": "gpt-4o", // optional: filter by model
|
|
39
|
-
"onlineOnly": true // optional: only online providers (default: true)
|
|
40
|
-
}
|
|
41
|
-
```
|
|
42
|
-
|
|
43
|
-
Returns: List of providers with `id`, `name`, `apiUrl`, `models[]`, `status.online`
|
|
44
|
-
|
|
45
|
-
### drain_provider_info
|
|
46
|
-
Get details about one provider.
|
|
47
|
-
|
|
48
|
-
```json
|
|
49
|
-
{
|
|
50
|
-
"providerId": "prov_initial_drain" // required
|
|
51
|
-
}
|
|
52
|
-
```
|
|
53
|
-
|
|
54
|
-
Returns: Full provider details including all models and pricing
|
|
55
|
-
|
|
56
|
-
### drain_balance
|
|
57
|
-
Check your wallet.
|
|
58
|
-
|
|
59
|
-
```json
|
|
60
|
-
{} // no parameters
|
|
61
|
-
```
|
|
62
|
-
|
|
63
|
-
Returns: `{ usdc: { balance, formatted }, native: { balance, formatted }, address }`
|
|
64
|
-
|
|
65
|
-
### drain_approve
|
|
66
|
-
Allow DRAIN contract to spend your USDC. **Required before first channel.**
|
|
67
|
-
|
|
68
|
-
```json
|
|
69
|
-
{
|
|
70
|
-
"amount": "100" // optional: USDC amount (default: unlimited)
|
|
71
|
-
}
|
|
72
|
-
```
|
|
73
|
-
|
|
74
|
-
Returns: Transaction hash
|
|
75
|
-
|
|
76
|
-
### drain_open_channel
|
|
77
|
-
Open a payment channel. Locks USDC for the duration.
|
|
78
|
-
|
|
79
|
-
```json
|
|
80
|
-
{
|
|
81
|
-
"
|
|
82
|
-
"amount": "5.00", // required: USDC to deposit
|
|
83
|
-
"duration": "24h" // required: "1h", "24h", "7d", etc.
|
|
84
|
-
}
|
|
85
|
-
```
|
|
86
|
-
|
|
87
|
-
Returns: `{ channelId, provider, amount, expiresAt }`
|
|
88
|
-
|
|
89
|
-
**Save the channelId** - you need it for all subsequent calls.
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
"
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
│
|
|
146
|
-
│
|
|
147
|
-
│
|
|
148
|
-
│ │
|
|
149
|
-
│ │
|
|
150
|
-
│ │
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
|
158
|
-
|
|
159
|
-
|
|
|
160
|
-
|
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
**
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
-
|
|
287
|
-
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
|
302
|
-
|
|
303
|
-
| `
|
|
304
|
-
| `
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
-
|
|
354
|
-
-
|
|
355
|
-
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
|
368
|
-
|
|
369
|
-
| `handshake58.com/api/
|
|
370
|
-
|
|
|
371
|
-
|
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
**
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
-
|
|
387
|
-
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
-
|
|
406
|
-
|
|
407
|
-
- **
|
|
408
|
-
- **
|
|
409
|
-
- **
|
|
410
|
-
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
-
|
|
421
|
-
-
|
|
1
|
+
# DRAIN MCP Server
|
|
2
|
+
|
|
3
|
+
MCP server for AI agent payments. Works with Cursor, Claude Desktop, Cline, Windsurf, and any MCP-compatible client. Pay for AI inference with USDC on Polygon — no API keys needed.
|
|
4
|
+
|
|
5
|
+
## When to Use DRAIN
|
|
6
|
+
|
|
7
|
+
Use DRAIN when you need to:
|
|
8
|
+
- Call AI models (GPT-4, Claude, etc.) without API keys
|
|
9
|
+
- Pay per-request with cryptocurrency
|
|
10
|
+
- Operate autonomously without human payment setup
|
|
11
|
+
|
|
12
|
+
Do NOT use DRAIN when:
|
|
13
|
+
- You already have API keys for the model you need
|
|
14
|
+
- The task doesn't require external AI inference
|
|
15
|
+
- Cost is not a concern (DRAIN adds ~$0.04 blockchain overhead per session)
|
|
16
|
+
|
|
17
|
+
---
|
|
18
|
+
|
|
19
|
+
## TL;DR - Minimum Viable Workflow
|
|
20
|
+
|
|
21
|
+
```
|
|
22
|
+
1. drain_balance() → Check if you have USDC
|
|
23
|
+
2. drain_providers() → Find a provider with your model
|
|
24
|
+
3. drain_open_channel(...) → Deposit USDC (one-time per session)
|
|
25
|
+
4. drain_chat(...) → Use AI (repeat as needed)
|
|
26
|
+
5. drain_close_channel(...) → Get refund (after expiry)
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
---
|
|
30
|
+
|
|
31
|
+
## Tools Reference
|
|
32
|
+
|
|
33
|
+
### drain_providers
|
|
34
|
+
Find AI providers.
|
|
35
|
+
|
|
36
|
+
```json
|
|
37
|
+
{
|
|
38
|
+
"model": "gpt-4o", // optional: filter by model
|
|
39
|
+
"onlineOnly": true // optional: only online providers (default: true)
|
|
40
|
+
}
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
Returns: List of providers with `id`, `name`, `apiUrl`, `models[]`, `status.online`
|
|
44
|
+
|
|
45
|
+
### drain_provider_info
|
|
46
|
+
Get details about one provider.
|
|
47
|
+
|
|
48
|
+
```json
|
|
49
|
+
{
|
|
50
|
+
"providerId": "prov_initial_drain" // required
|
|
51
|
+
}
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
Returns: Full provider details including all models and pricing
|
|
55
|
+
|
|
56
|
+
### drain_balance
|
|
57
|
+
Check your wallet.
|
|
58
|
+
|
|
59
|
+
```json
|
|
60
|
+
{} // no parameters
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
Returns: `{ usdc: { balance, formatted }, native: { balance, formatted }, address }`
|
|
64
|
+
|
|
65
|
+
### drain_approve
|
|
66
|
+
Allow DRAIN contract to spend your USDC. **Required before first channel.**
|
|
67
|
+
|
|
68
|
+
```json
|
|
69
|
+
{
|
|
70
|
+
"amount": "100" // optional: USDC amount (default: unlimited)
|
|
71
|
+
}
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
Returns: Transaction hash
|
|
75
|
+
|
|
76
|
+
### drain_open_channel
|
|
77
|
+
Open a payment channel. Locks USDC for the duration.
|
|
78
|
+
|
|
79
|
+
```json
|
|
80
|
+
{
|
|
81
|
+
"provider": "prov_initial_drain", // required: provider ID from drain_providers() (recommended) or wallet address (0x...)
|
|
82
|
+
"amount": "5.00", // required: USDC to deposit
|
|
83
|
+
"duration": "24h" // required: "1h", "24h", "7d", etc.
|
|
84
|
+
}
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
Returns: `{ channelId, provider, amount, expiresAt }`
|
|
88
|
+
|
|
89
|
+
**Save the channelId** - you need it for all subsequent calls.
|
|
90
|
+
|
|
91
|
+
**Use provider ID, not wallet address.** When multiple providers share the same wallet, using the ID ensures `drain_chat` routes to the correct provider.
|
|
92
|
+
|
|
93
|
+
### drain_channel_status
|
|
94
|
+
Check a channel's state.
|
|
95
|
+
|
|
96
|
+
```json
|
|
97
|
+
{
|
|
98
|
+
"channelId": "0x..." // required
|
|
99
|
+
}
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
Returns: `{ deposit, spent, remaining, expiresAt, isExpired }`
|
|
103
|
+
|
|
104
|
+
### drain_chat
|
|
105
|
+
Send a chat completion request. Automatically handles payment.
|
|
106
|
+
|
|
107
|
+
```json
|
|
108
|
+
{
|
|
109
|
+
"channelId": "0x...", // required
|
|
110
|
+
"model": "gpt-4o", // required
|
|
111
|
+
"messages": [ // required
|
|
112
|
+
{"role": "user", "content": "Hello"}
|
|
113
|
+
],
|
|
114
|
+
"maxTokens": 1000, // optional
|
|
115
|
+
"temperature": 0.7 // optional
|
|
116
|
+
}
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
Returns: `{ response, usage: { cost, totalSpent, remaining } }`
|
|
120
|
+
|
|
121
|
+
### drain_close_channel
|
|
122
|
+
Close an expired channel and get refund.
|
|
123
|
+
|
|
124
|
+
```json
|
|
125
|
+
{
|
|
126
|
+
"channelId": "0x..." // required
|
|
127
|
+
}
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
Returns: `{ refunded, txHash }`
|
|
131
|
+
|
|
132
|
+
**Note:** Can only close AFTER channel expires (duration ended).
|
|
133
|
+
|
|
134
|
+
---
|
|
135
|
+
|
|
136
|
+
## Decision Trees
|
|
137
|
+
|
|
138
|
+
### Starting a Session
|
|
139
|
+
|
|
140
|
+
```
|
|
141
|
+
Do I have an active channel?
|
|
142
|
+
├── YES → Use drain_chat() with existing channelId
|
|
143
|
+
└── NO →
|
|
144
|
+
├── drain_balance() → Do I have USDC?
|
|
145
|
+
│ ├── NO → Cannot proceed. Need USDC on Polygon.
|
|
146
|
+
│ └── YES →
|
|
147
|
+
│ ├── drain_providers() → Find provider with my model
|
|
148
|
+
│ │ ├── NO providers → Cannot proceed. No providers available.
|
|
149
|
+
│ │ └── Found provider →
|
|
150
|
+
│ │ ├── drain_approve() → First time only, if not already approved
|
|
151
|
+
│ │ └── drain_open_channel() → Get channelId
|
|
152
|
+
│ │ └── drain_chat() → Make requests
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
### Choosing Amount and Duration
|
|
156
|
+
|
|
157
|
+
| Use Case | Amount | Duration |
|
|
158
|
+
|----------|--------|----------|
|
|
159
|
+
| Quick test / single query | $0.50 - $1 | 1h |
|
|
160
|
+
| Short task (few queries) | $2 - $5 | 4h |
|
|
161
|
+
| Extended session | $5 - $20 | 24h |
|
|
162
|
+
| Long-running agent | $20 - $100 | 7d |
|
|
163
|
+
|
|
164
|
+
Rule of thumb: **$0.01-0.05 per message** depending on model.
|
|
165
|
+
|
|
166
|
+
### Handling Errors
|
|
167
|
+
|
|
168
|
+
```
|
|
169
|
+
"Insufficient balance"
|
|
170
|
+
→ Need more USDC. Check drain_balance() for current amount.
|
|
171
|
+
|
|
172
|
+
"Insufficient allowance"
|
|
173
|
+
→ Run drain_approve() to allow DRAIN contract to use USDC.
|
|
174
|
+
|
|
175
|
+
"Channel not found"
|
|
176
|
+
→ channelId is wrong or channel was closed. Open new channel.
|
|
177
|
+
|
|
178
|
+
"Channel expired"
|
|
179
|
+
→ For drain_chat(): Channel ended. Open new channel.
|
|
180
|
+
→ For drain_close_channel(): This is expected. Proceed with close.
|
|
181
|
+
|
|
182
|
+
"Insufficient channel balance"
|
|
183
|
+
→ Channel deposit used up. Open new channel with more funds.
|
|
184
|
+
|
|
185
|
+
"Provider offline"
|
|
186
|
+
→ Try drain_providers() to find alternative provider.
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
---
|
|
190
|
+
|
|
191
|
+
## Example Session
|
|
192
|
+
|
|
193
|
+
```
|
|
194
|
+
TASK: Analyze code using GPT-4o
|
|
195
|
+
|
|
196
|
+
STEP 1: Check wallet
|
|
197
|
+
> drain_balance()
|
|
198
|
+
← { usdc: { formatted: "50.00" }, native: { formatted: "2.5" } }
|
|
199
|
+
✓ Have funds
|
|
200
|
+
|
|
201
|
+
STEP 2: Find provider
|
|
202
|
+
> drain_providers({ model: "gpt-4o" })
|
|
203
|
+
← [{ id: "prov_initial_drain", name: "DRAIN Reference Provider",
|
|
204
|
+
models: [{ id: "gpt-4o", pricing: { input: "0.0075", output: "0.0225" }}] }]
|
|
205
|
+
✓ Found provider
|
|
206
|
+
|
|
207
|
+
STEP 3: Open channel ($5, 24 hours)
|
|
208
|
+
> drain_open_channel({ providerId: "prov_initial_drain", amount: "5.00", duration: "24h" })
|
|
209
|
+
← { channelId: "0x7f8a9b2c...", expiresAt: "2026-01-24T12:00:00Z" }
|
|
210
|
+
✓ Channel open - SAVE THIS CHANNEL ID
|
|
211
|
+
|
|
212
|
+
STEP 4: Make requests (repeat as needed)
|
|
213
|
+
> drain_chat({
|
|
214
|
+
channelId: "0x7f8a9b2c...",
|
|
215
|
+
model: "gpt-4o",
|
|
216
|
+
messages: [{ role: "user", content: "Explain this code: ..." }]
|
|
217
|
+
})
|
|
218
|
+
← { response: "This code...", usage: { cost: "0.02", remaining: "4.98" } }
|
|
219
|
+
✓ Got response
|
|
220
|
+
|
|
221
|
+
STEP 5: Check status (optional)
|
|
222
|
+
> drain_channel_status({ channelId: "0x7f8a9b2c..." })
|
|
223
|
+
← { deposit: "5.00", spent: "0.15", remaining: "4.85", isExpired: false }
|
|
224
|
+
|
|
225
|
+
STEP 6: Close after expiry (24h later)
|
|
226
|
+
> drain_close_channel({ channelId: "0x7f8a9b2c..." })
|
|
227
|
+
← { refunded: "4.85", txHash: "0x..." }
|
|
228
|
+
✓ Got refund
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
---
|
|
232
|
+
|
|
233
|
+
## Pricing Reference
|
|
234
|
+
|
|
235
|
+
| Model | Input/1k tokens | Output/1k tokens | ~Cost/message |
|
|
236
|
+
|-------|-----------------|------------------|---------------|
|
|
237
|
+
| gpt-4o | $0.0075 | $0.0225 | $0.01-0.05 |
|
|
238
|
+
| gpt-4o-mini | $0.00015 | $0.0006 | $0.001-0.005 |
|
|
239
|
+
|
|
240
|
+
Blockchain overhead: ~$0.02 per transaction (open, close, approve).
|
|
241
|
+
Marketplace session fee: $0.01 per channel opening (paid automatically).
|
|
242
|
+
|
|
243
|
+
---
|
|
244
|
+
|
|
245
|
+
## State Management
|
|
246
|
+
|
|
247
|
+
**Persist the channelId** between calls. If you lose it:
|
|
248
|
+
1. You cannot make more requests on that channel
|
|
249
|
+
2. You cannot close the channel (funds locked until provider claims or you find the ID)
|
|
250
|
+
|
|
251
|
+
Recommended: Store channelId with creation timestamp and expiry.
|
|
252
|
+
|
|
253
|
+
---
|
|
254
|
+
|
|
255
|
+
## Setup (agent does most of this autonomously)
|
|
256
|
+
|
|
257
|
+
### Agent Can Do
|
|
258
|
+
|
|
259
|
+
**1. Install** — `npm install -g drain-mcp` (ask user to approve if needed)
|
|
260
|
+
|
|
261
|
+
**2. Create wallet** — Generate a Polygon private key programmatically:
|
|
262
|
+
|
|
263
|
+
```javascript
|
|
264
|
+
const { generatePrivateKey } = require('viem');
|
|
265
|
+
const key = generatePrivateKey(); // 0x + 64 hex chars
|
|
266
|
+
```
|
|
267
|
+
|
|
268
|
+
Or ask the user for an existing wallet key (MetaMask → Account → Export Private Key).
|
|
269
|
+
|
|
270
|
+
**3. Configure** — Add to MCP client config:
|
|
271
|
+
|
|
272
|
+
```json
|
|
273
|
+
{
|
|
274
|
+
"mcpServers": {
|
|
275
|
+
"drain": {
|
|
276
|
+
"command": "drain-mcp",
|
|
277
|
+
"env": {
|
|
278
|
+
"DRAIN_PRIVATE_KEY": "0x_the_private_key"
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
```
|
|
284
|
+
|
|
285
|
+
Config locations vary by client:
|
|
286
|
+
- Cursor: `~/.cursor/mcp.json`
|
|
287
|
+
- Claude Desktop: `~/Library/Application Support/Claude/claude_desktop_config.json`
|
|
288
|
+
- Cline: MCP settings in VS Code
|
|
289
|
+
- Windsurf: MCP config
|
|
290
|
+
|
|
291
|
+
### Requires Human (the one thing agents cannot do)
|
|
292
|
+
|
|
293
|
+
**4. Fund the wallet** — Ask the user to send to the wallet address on Polygon:
|
|
294
|
+
- **$1–5 USDC** (for AI services)
|
|
295
|
+
- **$0.10 POL** (for gas, one-time)
|
|
296
|
+
|
|
297
|
+
After funding, the agent operates fully autonomously — provider discovery, channel management, payments, and AI requests are all handled by the MCP tools.
|
|
298
|
+
|
|
299
|
+
### Environment Variables
|
|
300
|
+
|
|
301
|
+
| Variable | Required | Default |
|
|
302
|
+
|----------|----------|---------|
|
|
303
|
+
| `DRAIN_PRIVATE_KEY` | ✅ | - |
|
|
304
|
+
| `DRAIN_CHAIN_ID` | No | 137 (Polygon) |
|
|
305
|
+
| `DRAIN_RPC_URL` | No | https://polygon-rpc.com |
|
|
306
|
+
| `DRAIN_MARKETPLACE_URL` | No | Auto-detected from directory |
|
|
307
|
+
|
|
308
|
+
**RPC Note:** Free RPCs have rate limits. If you get "rate limit" errors, try:
|
|
309
|
+
- `https://polygon-bor-rpc.publicnode.com` (PublicNode)
|
|
310
|
+
- `https://rpc.ankr.com/polygon` (requires free API key)
|
|
311
|
+
- Or use a paid RPC provider (Alchemy, Infura)
|
|
312
|
+
|
|
313
|
+
---
|
|
314
|
+
|
|
315
|
+
## Lessons Learned (E2E Testing)
|
|
316
|
+
|
|
317
|
+
### Cost Estimation is Conservative
|
|
318
|
+
|
|
319
|
+
The MCP server estimates costs based on message length and model pricing. Actual costs are usually **much lower** (often 10-100x less than estimate). This is intentional to prevent over-spending, but means:
|
|
320
|
+
- A $0.10 channel can handle **many more requests** than you might think
|
|
321
|
+
- Don't worry if estimate seems high - actual cost will be lower
|
|
322
|
+
|
|
323
|
+
**Example:** Estimated $0.01, actual cost $0.000005 (5 USDC wei)
|
|
324
|
+
|
|
325
|
+
### Channel "claimed" vs "spent"
|
|
326
|
+
|
|
327
|
+
When checking `drain_channel_status()`, you'll see:
|
|
328
|
+
- `claimed`: Amount provider has claimed **on-chain** (usually 0 until they claim)
|
|
329
|
+
- `remaining`: Deposit minus claimed (not minus spent)
|
|
330
|
+
|
|
331
|
+
**Important:** Vouchers are signed off-chain. The provider can claim anytime, but usually waits to accumulate multiple payments to save gas.
|
|
332
|
+
|
|
333
|
+
### RPC Rate Limits
|
|
334
|
+
|
|
335
|
+
Free public RPCs (like `polygon-rpc.com`) have rate limits. If you see errors:
|
|
336
|
+
1. Wait 10-15 seconds and retry
|
|
337
|
+
2. Switch to a different RPC (see Environment Variables above)
|
|
338
|
+
3. Use a paid RPC for production
|
|
339
|
+
|
|
340
|
+
### Channel ID is Critical
|
|
341
|
+
|
|
342
|
+
**Always persist the channelId!** If you lose it:
|
|
343
|
+
- You cannot make more requests
|
|
344
|
+
- You cannot close the channel (funds locked until expiry + provider claims)
|
|
345
|
+
|
|
346
|
+
**Best practice:** Store channelId immediately after `drain_open_channel()` with:
|
|
347
|
+
- Creation timestamp
|
|
348
|
+
- Expiry timestamp
|
|
349
|
+
- Provider ID
|
|
350
|
+
|
|
351
|
+
### Actual Costs are Tiny
|
|
352
|
+
|
|
353
|
+
Real-world example from E2E test:
|
|
354
|
+
- Channel: $0.10 USDC
|
|
355
|
+
- Request: "What is 2+2?" → "Four."
|
|
356
|
+
- Actual cost: **$0.000005** (5 USDC wei)
|
|
357
|
+
- You could make **20,000 requests** with $0.10!
|
|
358
|
+
|
|
359
|
+
This means small channels ($0.10-$0.50) are perfect for testing and light usage.
|
|
360
|
+
|
|
361
|
+
---
|
|
362
|
+
|
|
363
|
+
## External Endpoints
|
|
364
|
+
|
|
365
|
+
Every network request the MCP server makes is listed here. The private key **never** leaves your machine.
|
|
366
|
+
|
|
367
|
+
| Endpoint | Method | Data Sent | Private Key Transmitted? |
|
|
368
|
+
|---|---|---|---|
|
|
369
|
+
| `handshake58.com/api/mcp/providers` | GET | Nothing (public catalog) | No |
|
|
370
|
+
| `handshake58.com/api/directory/config` | GET | Nothing (reads fee wallet) | No |
|
|
371
|
+
| `handshake58.com/api/channels/status` | GET | channelId (public on-chain) | No |
|
|
372
|
+
| Provider `apiUrl` `/v1/chat/completions` | POST | Chat messages + signed voucher | No — only the EIP-712 **signature** is sent |
|
|
373
|
+
| Polygon RPC (on-chain tx) | POST | Signed transactions | No — key signs locally, only the signature is broadcast |
|
|
374
|
+
|
|
375
|
+
---
|
|
376
|
+
|
|
377
|
+
## Security & Privacy
|
|
378
|
+
|
|
379
|
+
**Private key handling:** `DRAIN_PRIVATE_KEY` is loaded into memory by the local MCP server process. It is used exclusively for:
|
|
380
|
+
1. **EIP-712 voucher signing** — generates a cryptographic signature (off-chain, no network call)
|
|
381
|
+
2. **On-chain transaction signing** — signs approve/open/close/transfer transactions locally before broadcasting to Polygon RPC
|
|
382
|
+
|
|
383
|
+
The private key is **never transmitted** to Handshake58 servers, AI providers, or any third party. Only the resulting signatures are sent. Providers verify signatures against the on-chain channel state — they never need or receive the key itself.
|
|
384
|
+
|
|
385
|
+
**What leaves your machine:**
|
|
386
|
+
- Public API queries to `handshake58.com` (provider list, fee wallet, channel status)
|
|
387
|
+
- Chat messages to AI providers (sent to the provider's `apiUrl`, not to Handshake58)
|
|
388
|
+
- Signed payment vouchers (contain a signature, not the key)
|
|
389
|
+
- Signed on-chain transactions (broadcast to Polygon)
|
|
390
|
+
|
|
391
|
+
**What stays local:**
|
|
392
|
+
- Your private key (never transmitted)
|
|
393
|
+
- Your wallet address derivation
|
|
394
|
+
- All cryptographic signing operations
|
|
395
|
+
|
|
396
|
+
**Recommended safeguards:**
|
|
397
|
+
- Use a **dedicated ephemeral wallet** with $1–5 USDC. Never reuse your main wallet.
|
|
398
|
+
- **Audit the source code** before installing: https://github.com/kimbo128/DRAIN
|
|
399
|
+
- Run in an **isolated environment** if handling sensitive data
|
|
400
|
+
|
|
401
|
+
---
|
|
402
|
+
|
|
403
|
+
## Compatible Clients
|
|
404
|
+
|
|
405
|
+
drain-mcp is an MCP server (not a CLI tool). It works with any MCP-compatible AI client:
|
|
406
|
+
|
|
407
|
+
- **Cursor** — Add to `.cursor/mcp.json`
|
|
408
|
+
- **Claude Desktop** — Add to `claude_desktop_config.json`
|
|
409
|
+
- **Cline** — Add to MCP settings
|
|
410
|
+
- **Windsurf** — Add to MCP config
|
|
411
|
+
- **OpenAI Agents** — Via MCP bridge
|
|
412
|
+
- Any agent that speaks Model Context Protocol
|
|
413
|
+
|
|
414
|
+
Run `drain-mcp --help` for full documentation.
|
|
415
|
+
|
|
416
|
+
---
|
|
417
|
+
|
|
418
|
+
## Links
|
|
419
|
+
|
|
420
|
+
- NPM: https://www.npmjs.com/package/drain-mcp
|
|
421
|
+
- GitHub: https://github.com/kimbo128/DRAIN
|
|
422
|
+
- Marketplace: https://handshake58.com
|
|
423
|
+
- Contract: `0x1C1918C99b6DcE977392E4131C91654d8aB71e64` (Polygon)
|