drain-mcp 0.1.16 → 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 +112 -273
- package/dist/index.d.ts +2 -2
- package/dist/index.js +28 -39
- package/dist/index.js.map +1 -1
- package/dist/services/channel.d.ts +14 -16
- package/dist/services/channel.d.ts.map +1 -1
- package/dist/services/channel.js +36 -30
- package/dist/services/channel.js.map +1 -1
- package/dist/services/inference.d.ts.map +1 -1
- package/dist/services/inference.js +5 -8
- package/dist/services/inference.js.map +1 -1
- package/dist/services/provider.d.ts +4 -2
- package/dist/services/provider.d.ts.map +1 -1
- package/dist/services/provider.js +4 -5
- 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 +95 -52
- 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 +17 -19
- 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 +2 -2
package/README.md
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
# DRAIN MCP Server
|
|
2
2
|
|
|
3
|
-
MCP server for
|
|
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
4
|
|
|
5
5
|
## When to Use DRAIN
|
|
6
6
|
|
|
7
7
|
Use DRAIN when you need to:
|
|
8
|
-
- Call
|
|
9
|
-
- Pay per-request with
|
|
10
|
-
-
|
|
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
11
|
|
|
12
12
|
Do NOT use DRAIN when:
|
|
13
|
-
- You already have API keys for the
|
|
14
|
-
- The task doesn't require external
|
|
13
|
+
- You already have API keys for the service you need
|
|
14
|
+
- The task doesn't require external services
|
|
15
15
|
- Cost is not a concern (DRAIN adds ~$0.04 blockchain overhead per session)
|
|
16
16
|
|
|
17
17
|
---
|
|
@@ -19,11 +19,14 @@ Do NOT use DRAIN when:
|
|
|
19
19
|
## TL;DR - Minimum Viable Workflow
|
|
20
20
|
|
|
21
21
|
```
|
|
22
|
-
1.
|
|
23
|
-
2.
|
|
24
|
-
3.
|
|
25
|
-
4.
|
|
26
|
-
5.
|
|
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)
|
|
27
30
|
```
|
|
28
31
|
|
|
29
32
|
---
|
|
@@ -31,105 +34,89 @@ Do NOT use DRAIN when:
|
|
|
31
34
|
## Tools Reference
|
|
32
35
|
|
|
33
36
|
### drain_providers
|
|
34
|
-
Find
|
|
37
|
+
Find service providers. Filter by model name, category, or online status.
|
|
35
38
|
|
|
36
39
|
```json
|
|
37
40
|
{
|
|
38
|
-
"model": "gpt-4o",
|
|
39
|
-
"
|
|
41
|
+
"model": "gpt-4o",
|
|
42
|
+
"category": "scraping",
|
|
43
|
+
"onlineOnly": true
|
|
40
44
|
}
|
|
41
45
|
```
|
|
42
46
|
|
|
43
|
-
|
|
47
|
+
Categories: `llm`, `image`, `audio`, `code`, `scraping`, `vpn`, `multi-modal`, `other`
|
|
44
48
|
|
|
45
|
-
### drain_provider_info
|
|
46
|
-
Get details about
|
|
49
|
+
### drain_provider_info
|
|
50
|
+
Get details about a provider including usage instructions (docs). The docs explain how to format requests for that provider.
|
|
47
51
|
|
|
48
52
|
```json
|
|
49
|
-
{
|
|
50
|
-
"providerId": "prov_initial_drain" // required
|
|
51
|
-
}
|
|
53
|
+
{ "providerId": "hs58-openai" }
|
|
52
54
|
```
|
|
53
55
|
|
|
54
|
-
Returns: Full provider details including all models and pricing
|
|
55
|
-
|
|
56
56
|
### drain_balance
|
|
57
|
-
Check
|
|
58
|
-
|
|
59
|
-
```json
|
|
60
|
-
{} // no parameters
|
|
61
|
-
```
|
|
62
|
-
|
|
63
|
-
Returns: `{ usdc: { balance, formatted }, native: { balance, formatted }, address }`
|
|
57
|
+
Check wallet USDC balance, POL for gas, and DRAIN contract allowance.
|
|
64
58
|
|
|
65
59
|
### drain_approve
|
|
66
|
-
|
|
60
|
+
Approve USDC spending for the DRAIN contract. Required once before opening channels.
|
|
67
61
|
|
|
68
62
|
```json
|
|
69
|
-
{
|
|
70
|
-
"amount": "100" // optional: USDC amount (default: unlimited)
|
|
71
|
-
}
|
|
63
|
+
{ "amount": "100" }
|
|
72
64
|
```
|
|
73
65
|
|
|
74
|
-
Returns: Transaction hash
|
|
75
|
-
|
|
76
66
|
### drain_open_channel
|
|
77
|
-
Open a payment channel. Locks USDC for the duration.
|
|
67
|
+
Open a payment channel. Locks USDC for the specified duration.
|
|
78
68
|
|
|
79
69
|
```json
|
|
80
70
|
{
|
|
81
|
-
"provider": "
|
|
82
|
-
"amount": "5.00",
|
|
83
|
-
"duration": "24h"
|
|
71
|
+
"provider": "hs58-openai",
|
|
72
|
+
"amount": "5.00",
|
|
73
|
+
"duration": "24h"
|
|
84
74
|
}
|
|
85
75
|
```
|
|
86
76
|
|
|
87
|
-
Returns
|
|
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.**
|
|
88
78
|
|
|
89
|
-
|
|
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.
|
|
79
|
+
### drain_chat
|
|
80
|
+
Send a paid request through a channel. Works for ALL provider types:
|
|
92
81
|
|
|
93
|
-
|
|
94
|
-
|
|
82
|
+
- **LLM providers:** Standard chat messages
|
|
83
|
+
- **Non-LLM providers:** JSON payload in the user message content (check provider docs)
|
|
95
84
|
|
|
96
85
|
```json
|
|
97
86
|
{
|
|
98
|
-
"channelId": "0x..."
|
|
87
|
+
"channelId": "0x...",
|
|
88
|
+
"model": "gpt-4o",
|
|
89
|
+
"messages": [{"role": "user", "content": "Hello"}]
|
|
99
90
|
}
|
|
100
91
|
```
|
|
101
92
|
|
|
102
|
-
|
|
93
|
+
### drain_channel_status
|
|
94
|
+
Check a channel's deposit, spending, remaining balance, and expiry.
|
|
103
95
|
|
|
104
|
-
###
|
|
105
|
-
|
|
96
|
+
### drain_channels
|
|
97
|
+
List all known channels with status (active/expired/closed). Find expired channels that need closing.
|
|
106
98
|
|
|
107
|
-
|
|
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
|
-
```
|
|
99
|
+
### drain_close_channel
|
|
100
|
+
Close an expired channel and reclaim unspent USDC.
|
|
118
101
|
|
|
119
|
-
|
|
102
|
+
---
|
|
120
103
|
|
|
121
|
-
|
|
122
|
-
Close an expired channel and get refund.
|
|
104
|
+
## Provider Categories
|
|
123
105
|
|
|
124
|
-
|
|
125
|
-
{
|
|
126
|
-
"channelId": "0x..." // required
|
|
127
|
-
}
|
|
128
|
-
```
|
|
106
|
+
Providers are not limited to LLM chat. Each provider has a `category` field and a docs endpoint explaining how to format requests.
|
|
129
107
|
|
|
130
|
-
|
|
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 |
|
|
131
118
|
|
|
132
|
-
**
|
|
119
|
+
**Rule: For any category other than `llm`, call `drain_provider_info` first to read the docs.**
|
|
133
120
|
|
|
134
121
|
---
|
|
135
122
|
|
|
@@ -140,16 +127,16 @@ Returns: `{ refunded, txHash }`
|
|
|
140
127
|
```
|
|
141
128
|
Do I have an active channel?
|
|
142
129
|
├── YES → Use drain_chat() with existing channelId
|
|
143
|
-
└── NO →
|
|
130
|
+
└── NO →
|
|
144
131
|
├── drain_balance() → Do I have USDC?
|
|
145
132
|
│ ├── NO → Cannot proceed. Need USDC on Polygon.
|
|
146
|
-
│ └── YES →
|
|
147
|
-
│ ├── drain_providers() → Find provider
|
|
148
|
-
│ │ ├── NO providers → Cannot proceed.
|
|
133
|
+
│ └── YES →
|
|
134
|
+
│ ├── drain_providers() → Find provider
|
|
135
|
+
│ │ ├── NO providers → Cannot proceed.
|
|
149
136
|
│ │ └── Found provider →
|
|
150
|
-
│ │ ├── drain_approve() → First time only
|
|
137
|
+
│ │ ├── drain_approve() → First time only
|
|
151
138
|
│ │ └── drain_open_channel() → Get channelId
|
|
152
|
-
│ │ └── drain_chat() →
|
|
139
|
+
│ │ └── drain_chat() → Send requests
|
|
153
140
|
```
|
|
154
141
|
|
|
155
142
|
### Choosing Amount and Duration
|
|
@@ -161,260 +148,112 @@ Do I have an active channel?
|
|
|
161
148
|
| Extended session | $5 - $20 | 24h |
|
|
162
149
|
| Long-running agent | $20 - $100 | 7d |
|
|
163
150
|
|
|
164
|
-
Rule of thumb: **$0.01-0.05 per message** depending on model.
|
|
165
|
-
|
|
166
151
|
### Handling Errors
|
|
167
152
|
|
|
168
153
|
```
|
|
169
154
|
"Insufficient balance"
|
|
170
|
-
→ Need more USDC. Check drain_balance()
|
|
155
|
+
→ Need more USDC. Check drain_balance().
|
|
171
156
|
|
|
172
|
-
"Insufficient allowance"
|
|
173
|
-
→ Run drain_approve()
|
|
157
|
+
"Insufficient allowance"
|
|
158
|
+
→ Run drain_approve().
|
|
174
159
|
|
|
175
160
|
"Channel not found"
|
|
176
161
|
→ channelId is wrong or channel was closed. Open new channel.
|
|
177
162
|
|
|
178
163
|
"Channel expired"
|
|
179
|
-
→ For drain_chat
|
|
180
|
-
→ For drain_close_channel
|
|
164
|
+
→ For drain_chat: Open a new channel.
|
|
165
|
+
→ For drain_close_channel: Expected. Proceed with close.
|
|
181
166
|
|
|
182
167
|
"Insufficient channel balance"
|
|
183
168
|
→ Channel deposit used up. Open new channel with more funds.
|
|
184
169
|
|
|
185
170
|
"Provider offline"
|
|
186
|
-
→
|
|
171
|
+
→ Use drain_providers() to find alternative provider.
|
|
187
172
|
```
|
|
188
173
|
|
|
189
174
|
---
|
|
190
175
|
|
|
191
|
-
##
|
|
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)
|
|
176
|
+
## Setup
|
|
256
177
|
|
|
257
178
|
### Agent Can Do
|
|
258
179
|
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
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)
|
|
262
183
|
|
|
263
|
-
|
|
264
|
-
const { generatePrivateKey } = require('viem');
|
|
265
|
-
const key = generatePrivateKey(); // 0x + 64 hex chars
|
|
266
|
-
```
|
|
184
|
+
### Requires Human
|
|
267
185
|
|
|
268
|
-
|
|
186
|
+
4. **Fund wallet** — Send $1-5 USDC + $0.10 POL on Polygon to the wallet address
|
|
269
187
|
|
|
270
|
-
|
|
188
|
+
### MCP Config
|
|
271
189
|
|
|
272
190
|
```json
|
|
273
191
|
{
|
|
274
192
|
"mcpServers": {
|
|
275
193
|
"drain": {
|
|
276
194
|
"command": "drain-mcp",
|
|
277
|
-
"env": {
|
|
278
|
-
"DRAIN_PRIVATE_KEY": "0x_the_private_key"
|
|
279
|
-
}
|
|
195
|
+
"env": { "DRAIN_PRIVATE_KEY": "0x..." }
|
|
280
196
|
}
|
|
281
197
|
}
|
|
282
198
|
}
|
|
283
199
|
```
|
|
284
200
|
|
|
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
201
|
### Environment Variables
|
|
300
202
|
|
|
301
203
|
| Variable | Required | Default |
|
|
302
204
|
|----------|----------|---------|
|
|
303
|
-
| `DRAIN_PRIVATE_KEY` |
|
|
205
|
+
| `DRAIN_PRIVATE_KEY` | Yes | — |
|
|
304
206
|
| `DRAIN_CHAIN_ID` | No | 137 (Polygon) |
|
|
305
|
-
| `DRAIN_RPC_URL` | No |
|
|
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)
|
|
207
|
+
| `DRAIN_RPC_URL` | No | polygon-rpc.com |
|
|
312
208
|
|
|
313
209
|
---
|
|
314
210
|
|
|
315
|
-
##
|
|
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
|
|
211
|
+
## Security & Privacy
|
|
341
212
|
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
-
|
|
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)
|
|
345
217
|
|
|
346
|
-
|
|
347
|
-
- Creation timestamp
|
|
348
|
-
- Expiry timestamp
|
|
349
|
-
- Provider ID
|
|
218
|
+
The key is never transmitted to any server. Providers verify signatures against on-chain state.
|
|
350
219
|
|
|
351
|
-
###
|
|
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
|
|
352
226
|
|
|
353
|
-
|
|
354
|
-
-
|
|
355
|
-
- Request
|
|
356
|
-
-
|
|
357
|
-
-
|
|
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)
|
|
358
232
|
|
|
359
|
-
|
|
233
|
+
### What Stays Local
|
|
234
|
+
- Private key (never transmitted)
|
|
235
|
+
- All cryptographic operations (signing happens in-process)
|
|
360
236
|
|
|
361
|
-
|
|
237
|
+
### External Endpoints
|
|
362
238
|
|
|
363
|
-
|
|
239
|
+
Every network request the MCP server makes:
|
|
364
240
|
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
| Endpoint | Method | Data Sent | Private Key Transmitted? |
|
|
241
|
+
| Endpoint | Method | Data Sent | Key Transmitted? |
|
|
368
242
|
|---|---|---|---|
|
|
369
|
-
|
|
|
370
|
-
|
|
|
371
|
-
|
|
|
372
|
-
| Provider
|
|
373
|
-
|
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
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
|
|
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
|
|
399
253
|
- Run in an **isolated environment** if handling sensitive data
|
|
400
254
|
|
|
401
255
|
---
|
|
402
256
|
|
|
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
257
|
## Links
|
|
419
258
|
|
|
420
259
|
- NPM: https://www.npmjs.com/package/drain-mcp
|
package/dist/index.d.ts
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
/**
|
|
3
3
|
* DRAIN MCP Server
|
|
4
4
|
*
|
|
5
|
-
* Model Context Protocol server for
|
|
6
|
-
*
|
|
5
|
+
* Model Context Protocol server for the DRAIN payment protocol.
|
|
6
|
+
* Agents discover providers, open USDC payment channels, and call any service.
|
|
7
7
|
*/
|
|
8
8
|
export {};
|
|
9
9
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
CHANGED
|
@@ -2,28 +2,22 @@
|
|
|
2
2
|
/**
|
|
3
3
|
* DRAIN MCP Server
|
|
4
4
|
*
|
|
5
|
-
* Model Context Protocol server for
|
|
6
|
-
*
|
|
5
|
+
* Model Context Protocol server for the DRAIN payment protocol.
|
|
6
|
+
* Agents discover providers, open USDC payment channels, and call any service.
|
|
7
7
|
*/
|
|
8
|
-
// Handle --help before any imports that require configuration
|
|
9
8
|
const args = process.argv.slice(2);
|
|
10
9
|
if (args.includes('--help') || args.includes('-h')) {
|
|
11
10
|
console.log(`
|
|
12
|
-
drain-mcp — MCP server for
|
|
11
|
+
drain-mcp — MCP server for the DRAIN payment protocol
|
|
13
12
|
|
|
14
13
|
WHAT IS THIS?
|
|
15
|
-
drain-mcp is a Model Context Protocol (MCP) server. It
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
14
|
+
drain-mcp is a Model Context Protocol (MCP) server. It runs inside any
|
|
15
|
+
MCP-compatible client and gives agents tools to discover service providers,
|
|
16
|
+
open USDC payment channels on Polygon, and call any service — LLM, image
|
|
17
|
+
generation, web scraping, VPN, and more. Pay per use, no API keys.
|
|
19
18
|
|
|
20
|
-
COMPATIBLE CLIENTS
|
|
21
|
-
|
|
22
|
-
- Claude Desktop Add to claude_desktop_config.json
|
|
23
|
-
- Cline Add to MCP settings
|
|
24
|
-
- Windsurf Add to MCP config
|
|
25
|
-
- OpenAI Agents Via MCP bridge
|
|
26
|
-
- Any agent that speaks Model Context Protocol
|
|
19
|
+
COMPATIBLE CLIENTS:
|
|
20
|
+
Cursor, Claude Desktop, Cline, Windsurf, OpenAI Agents, or any MCP client.
|
|
27
21
|
|
|
28
22
|
CONFIGURATION:
|
|
29
23
|
{
|
|
@@ -38,34 +32,26 @@ CONFIGURATION:
|
|
|
38
32
|
}
|
|
39
33
|
|
|
40
34
|
ENVIRONMENT VARIABLES:
|
|
41
|
-
DRAIN_PRIVATE_KEY (required) Polygon wallet private key
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
DRAIN_RPC_URL Custom RPC endpoint (default: polygon-rpc.com)
|
|
35
|
+
DRAIN_PRIVATE_KEY (required) Polygon wallet private key
|
|
36
|
+
DRAIN_CHAIN_ID 137 (Polygon, default) or 80002 (Amoy testnet)
|
|
37
|
+
DRAIN_RPC_URL Custom RPC endpoint
|
|
45
38
|
DRAIN_DIRECTORY_URL Provider directory URL
|
|
46
39
|
DRAIN_MARKETPLACE_URL Marketplace base URL
|
|
47
40
|
|
|
48
41
|
MCP TOOLS PROVIDED:
|
|
49
|
-
drain_providers List
|
|
50
|
-
drain_provider_info
|
|
42
|
+
drain_providers List service providers (filter by model, category)
|
|
43
|
+
drain_provider_info Provider details + usage instructions (docs)
|
|
51
44
|
drain_balance Check wallet USDC balance and allowance
|
|
52
45
|
drain_approve Approve USDC spending for the DRAIN contract
|
|
53
46
|
drain_open_channel Open a payment channel with a provider
|
|
54
|
-
drain_close_channel Close
|
|
55
|
-
drain_channel_status Check
|
|
56
|
-
|
|
47
|
+
drain_close_channel Close expired channel and reclaim funds
|
|
48
|
+
drain_channel_status Check channel status and balance
|
|
49
|
+
drain_channels List all known channels with status
|
|
50
|
+
drain_chat Send a paid request to a provider
|
|
57
51
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
2. Create a Polygon wallet key programmatically:
|
|
62
|
-
JavaScript: require('viem').generatePrivateKey()
|
|
63
|
-
Or ask user for an existing wallet key
|
|
64
|
-
3. Configure MCP client with the key
|
|
65
|
-
|
|
66
|
-
REQUIRES HUMAN (the one thing agents cannot do):
|
|
67
|
-
4. Fund the wallet on Polygon: $1-5 USDC + $0.10 POL for gas
|
|
68
|
-
Give the user the wallet address and ask them to send funds
|
|
52
|
+
PROVIDER CATEGORIES:
|
|
53
|
+
llm, image, audio, code, scraping, vpn, multi-modal, other
|
|
54
|
+
Each provider has a docs endpoint explaining how to format requests.
|
|
69
55
|
|
|
70
56
|
LINKS:
|
|
71
57
|
Marketplace: https://handshake58.com
|
|
@@ -86,7 +72,7 @@ import { ProviderService } from './services/provider.js';
|
|
|
86
72
|
import { InferenceService } from './services/inference.js';
|
|
87
73
|
import { providerTools, listProviders, getProvider } from './tools/providers.js';
|
|
88
74
|
import { balanceTools, getBalance, approveUsdc } from './tools/balance.js';
|
|
89
|
-
import { channelTools, openChannel, closeChannel, getChannelStatus } from './tools/channel.js';
|
|
75
|
+
import { channelTools, openChannel, closeChannel, getChannelStatus, listChannels } from './tools/channel.js';
|
|
90
76
|
import { chatTools, chat } from './tools/chat.js';
|
|
91
77
|
// ============================================================================
|
|
92
78
|
// SERVER SETUP
|
|
@@ -112,7 +98,7 @@ class DrainMcpServer {
|
|
|
112
98
|
// Create MCP server
|
|
113
99
|
this.server = new Server({
|
|
114
100
|
name: 'drain-mcp',
|
|
115
|
-
version: '0.
|
|
101
|
+
version: '0.2.0',
|
|
116
102
|
}, {
|
|
117
103
|
capabilities: {
|
|
118
104
|
tools: {},
|
|
@@ -161,6 +147,9 @@ class DrainMcpServer {
|
|
|
161
147
|
case 'drain_channel_status':
|
|
162
148
|
result = await getChannelStatus(this.channelService, args);
|
|
163
149
|
break;
|
|
150
|
+
case 'drain_channels':
|
|
151
|
+
result = await listChannels(this.channelService);
|
|
152
|
+
break;
|
|
164
153
|
// Chat tools
|
|
165
154
|
case 'drain_chat':
|
|
166
155
|
result = await chat(this.channelService, this.providerService, this.inferenceService, args);
|
|
@@ -191,8 +180,8 @@ class DrainMcpServer {
|
|
|
191
180
|
},
|
|
192
181
|
{
|
|
193
182
|
uri: 'drain://providers',
|
|
194
|
-
name: '
|
|
195
|
-
description: '
|
|
183
|
+
name: 'Service Providers',
|
|
184
|
+
description: 'Available service providers with categories, pricing, and docs URLs',
|
|
196
185
|
mimeType: 'text/markdown',
|
|
197
186
|
},
|
|
198
187
|
],
|