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