drain-mcp 0.1.0 → 0.1.1
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 +167 -98
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,42 +1,68 @@
|
|
|
1
1
|
# DRAIN MCP Server
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
> **For AI Agents:** This MCP server lets you pay for AI inference (GPT-4, Claude, etc.) using USDC on Polygon. No API keys needed - you pay per request through payment channels.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
## What is DRAIN?
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
DRAIN is a protocol for AI-to-AI payments. Instead of API keys, you:
|
|
8
|
+
1. Open a **payment channel** with a provider (deposit USDC)
|
|
9
|
+
2. Make requests and **sign vouchers** for each payment
|
|
10
|
+
3. Close the channel when done (get unused funds back)
|
|
8
11
|
|
|
9
|
-
|
|
10
|
-
npm install -g drain-mcp
|
|
11
|
-
```
|
|
12
|
+
This MCP server handles all of this automatically.
|
|
12
13
|
|
|
13
|
-
|
|
14
|
+
---
|
|
14
15
|
|
|
15
|
-
|
|
16
|
-
npx drain-mcp
|
|
17
|
-
```
|
|
16
|
+
## Quick Start for AI Agents
|
|
18
17
|
|
|
19
|
-
|
|
18
|
+
### Prerequisites
|
|
19
|
+
Your wallet needs:
|
|
20
|
+
- **USDC** on Polygon (for payments)
|
|
21
|
+
- **POL** on Polygon (for gas, ~0.1 POL is enough)
|
|
20
22
|
|
|
21
|
-
|
|
23
|
+
### Step-by-Step Workflow
|
|
22
24
|
|
|
23
|
-
```
|
|
24
|
-
|
|
25
|
-
|
|
25
|
+
```
|
|
26
|
+
1. CHECK PROVIDERS
|
|
27
|
+
→ drain_providers()
|
|
28
|
+
Returns list of available AI providers with models and pricing
|
|
26
29
|
|
|
27
|
-
|
|
28
|
-
|
|
30
|
+
2. CHECK YOUR BALANCE
|
|
31
|
+
→ drain_balance()
|
|
32
|
+
Shows your USDC balance and wallet address
|
|
33
|
+
|
|
34
|
+
3. APPROVE USDC (first time only)
|
|
35
|
+
→ drain_approve(amount: "100")
|
|
36
|
+
Allows DRAIN contract to use your USDC
|
|
37
|
+
|
|
38
|
+
4. OPEN A CHANNEL
|
|
39
|
+
→ drain_open_channel(
|
|
40
|
+
providerId: "prov_initial_drain",
|
|
41
|
+
amount: "5.00",
|
|
42
|
+
duration: "24h"
|
|
43
|
+
)
|
|
44
|
+
Returns channelId - save this!
|
|
45
|
+
|
|
46
|
+
5. MAKE REQUESTS
|
|
47
|
+
→ drain_chat(
|
|
48
|
+
channelId: "0x...",
|
|
49
|
+
model: "gpt-4o",
|
|
50
|
+
messages: [{"role": "user", "content": "Hello"}]
|
|
51
|
+
)
|
|
52
|
+
Automatically signs payment vouchers
|
|
53
|
+
|
|
54
|
+
6. CLOSE CHANNEL (after expiry)
|
|
55
|
+
→ drain_close_channel(channelId: "0x...")
|
|
56
|
+
Returns unused USDC to your wallet
|
|
57
|
+
```
|
|
29
58
|
|
|
30
|
-
|
|
31
|
-
export DRAIN_RPC_URL="https://polygon-rpc.com"
|
|
59
|
+
---
|
|
32
60
|
|
|
33
|
-
|
|
34
|
-
export DRAIN_DIRECTORY_URL="https://drain-marketplace.railway.app/api/mcp/providers"
|
|
35
|
-
```
|
|
61
|
+
## Installation
|
|
36
62
|
|
|
37
|
-
|
|
63
|
+
### For Cursor IDE
|
|
38
64
|
|
|
39
|
-
Add to
|
|
65
|
+
Add to `~/.cursor/mcp.json`:
|
|
40
66
|
|
|
41
67
|
```json
|
|
42
68
|
{
|
|
@@ -45,16 +71,16 @@ Add to your Cursor settings (`~/.cursor/mcp.json`):
|
|
|
45
71
|
"command": "npx",
|
|
46
72
|
"args": ["-y", "drain-mcp"],
|
|
47
73
|
"env": {
|
|
48
|
-
"DRAIN_PRIVATE_KEY": "
|
|
74
|
+
"DRAIN_PRIVATE_KEY": "0x_YOUR_PRIVATE_KEY_HERE"
|
|
49
75
|
}
|
|
50
76
|
}
|
|
51
77
|
}
|
|
52
78
|
}
|
|
53
79
|
```
|
|
54
80
|
|
|
55
|
-
|
|
81
|
+
### For Claude Desktop
|
|
56
82
|
|
|
57
|
-
Add to
|
|
83
|
+
Add to `~/Library/Application Support/Claude/claude_desktop_config.json` (Mac) or `%APPDATA%\Claude\claude_desktop_config.json` (Windows):
|
|
58
84
|
|
|
59
85
|
```json
|
|
60
86
|
{
|
|
@@ -63,114 +89,157 @@ Add to your Claude config (`~/Library/Application Support/Claude/claude_desktop_
|
|
|
63
89
|
"command": "npx",
|
|
64
90
|
"args": ["-y", "drain-mcp"],
|
|
65
91
|
"env": {
|
|
66
|
-
"DRAIN_PRIVATE_KEY": "
|
|
92
|
+
"DRAIN_PRIVATE_KEY": "0x_YOUR_PRIVATE_KEY_HERE"
|
|
67
93
|
}
|
|
68
94
|
}
|
|
69
95
|
}
|
|
70
96
|
}
|
|
71
97
|
```
|
|
72
98
|
|
|
99
|
+
### Environment Variables
|
|
100
|
+
|
|
101
|
+
| Variable | Required | Default | Description |
|
|
102
|
+
|----------|----------|---------|-------------|
|
|
103
|
+
| `DRAIN_PRIVATE_KEY` | ✅ Yes | - | Your wallet's private key |
|
|
104
|
+
| `DRAIN_CHAIN_ID` | No | `137` | Polygon Mainnet |
|
|
105
|
+
| `DRAIN_RPC_URL` | No | `https://polygon-rpc.com` | RPC endpoint |
|
|
106
|
+
| `DRAIN_DIRECTORY_URL` | No | Production URL | Provider directory |
|
|
107
|
+
|
|
108
|
+
---
|
|
109
|
+
|
|
73
110
|
## Available Tools
|
|
74
111
|
|
|
75
|
-
### Discovery
|
|
112
|
+
### 🔍 Discovery
|
|
76
113
|
|
|
77
|
-
| Tool | Description |
|
|
78
|
-
|
|
79
|
-
| `drain_providers` | List available AI providers
|
|
80
|
-
| `drain_provider_info` | Get details
|
|
114
|
+
| Tool | Parameters | Description |
|
|
115
|
+
|------|------------|-------------|
|
|
116
|
+
| `drain_providers` | `model?`, `onlineOnly?` | List available AI providers |
|
|
117
|
+
| `drain_provider_info` | `providerId` | Get provider details and pricing |
|
|
81
118
|
|
|
82
|
-
### Wallet
|
|
119
|
+
### 💰 Wallet
|
|
83
120
|
|
|
84
|
-
| Tool | Description |
|
|
85
|
-
|
|
86
|
-
| `drain_balance` | Check USDC
|
|
87
|
-
| `drain_approve` | Approve USDC
|
|
121
|
+
| Tool | Parameters | Description |
|
|
122
|
+
|------|------------|-------------|
|
|
123
|
+
| `drain_balance` | - | Check USDC and POL balance |
|
|
124
|
+
| `drain_approve` | `amount?` | Approve USDC for DRAIN contract |
|
|
88
125
|
|
|
89
|
-
### Channels
|
|
126
|
+
### 📡 Channels
|
|
90
127
|
|
|
91
|
-
| Tool | Description |
|
|
92
|
-
|
|
93
|
-
| `drain_open_channel` |
|
|
94
|
-
| `drain_close_channel` | Close
|
|
95
|
-
| `drain_channel_status` | Check channel balance and expiry |
|
|
128
|
+
| Tool | Parameters | Description |
|
|
129
|
+
|------|------------|-------------|
|
|
130
|
+
| `drain_open_channel` | `providerId`, `amount`, `duration` | Open payment channel |
|
|
131
|
+
| `drain_close_channel` | `channelId` | Close expired channel, get refund |
|
|
132
|
+
| `drain_channel_status` | `channelId` | Check channel balance and expiry |
|
|
96
133
|
|
|
97
|
-
### Inference
|
|
134
|
+
### 🤖 Inference
|
|
98
135
|
|
|
99
|
-
| Tool | Description |
|
|
100
|
-
|
|
101
|
-
| `drain_chat` |
|
|
136
|
+
| Tool | Parameters | Description |
|
|
137
|
+
|------|------------|-------------|
|
|
138
|
+
| `drain_chat` | `channelId`, `model`, `messages`, `maxTokens?`, `temperature?` | Chat completion with auto-payment |
|
|
102
139
|
|
|
103
|
-
|
|
140
|
+
---
|
|
141
|
+
|
|
142
|
+
## Example: Complete Session
|
|
104
143
|
|
|
105
144
|
```
|
|
106
|
-
Agent
|
|
145
|
+
AI Agent wants to analyze code using GPT-4o
|
|
107
146
|
|
|
108
|
-
1
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
147
|
+
Step 1: Find a provider
|
|
148
|
+
> drain_providers(model: "gpt-4o")
|
|
149
|
+
→ Found: "DRAIN Reference Provider" - $0.0075/1k input, $0.0225/1k output
|
|
150
|
+
|
|
151
|
+
Step 2: Check funds
|
|
152
|
+
> drain_balance()
|
|
153
|
+
→ USDC: $50.00, POL: 2.5
|
|
154
|
+
|
|
155
|
+
Step 3: Open channel with $5 for 24 hours
|
|
156
|
+
> drain_open_channel(providerId: "prov_initial_drain", amount: "5.00", duration: "24h")
|
|
157
|
+
→ Channel opened: 0x7f8a...3b2c
|
|
158
|
+
|
|
159
|
+
Step 4: Use the AI
|
|
160
|
+
> drain_chat(channelId: "0x7f8a...3b2c", model: "gpt-4o", messages: [...])
|
|
161
|
+
→ Response received, paid $0.02
|
|
162
|
+
|
|
163
|
+
Step 5: Continue using...
|
|
164
|
+
> drain_chat(...)
|
|
165
|
+
→ Response received, paid $0.03
|
|
166
|
+
|
|
167
|
+
Step 6: After 24h, close and get refund
|
|
168
|
+
> drain_close_channel(channelId: "0x7f8a...3b2c")
|
|
169
|
+
→ Refunded: $4.95 USDC
|
|
125
170
|
```
|
|
126
171
|
|
|
127
|
-
|
|
172
|
+
---
|
|
173
|
+
|
|
174
|
+
## Pricing
|
|
175
|
+
|
|
176
|
+
Pricing is set by each provider. Typical rates:
|
|
177
|
+
|
|
178
|
+
| Model | Input/1k tokens | Output/1k tokens |
|
|
179
|
+
|-------|-----------------|------------------|
|
|
180
|
+
| gpt-4o | $0.0075 | $0.0225 |
|
|
181
|
+
| gpt-4o-mini | $0.00015 | $0.0006 |
|
|
128
182
|
|
|
129
|
-
|
|
183
|
+
Use `drain_providers()` to see current pricing.
|
|
130
184
|
|
|
131
|
-
|
|
132
|
-
|-----|-------------|
|
|
133
|
-
| `drain://wallet` | Current wallet status |
|
|
134
|
-
| `drain://providers` | List of available providers |
|
|
185
|
+
---
|
|
135
186
|
|
|
136
|
-
## Funding Your
|
|
187
|
+
## Funding Your Wallet
|
|
137
188
|
|
|
138
|
-
|
|
189
|
+
Your agent needs USDC and POL on Polygon:
|
|
139
190
|
|
|
140
|
-
|
|
141
|
-
|
|
191
|
+
### Get a Wallet
|
|
192
|
+
1. Generate a new private key for your agent
|
|
193
|
+
2. Save it securely - this wallet will hold funds
|
|
142
194
|
|
|
143
|
-
|
|
195
|
+
### Get USDC
|
|
196
|
+
- **Bridge from Ethereum:** [Polygon Bridge](https://wallet.polygon.technology/bridge)
|
|
197
|
+
- **Buy directly:** Coinbase, Binance support Polygon USDC
|
|
198
|
+
- **Circle:** [Circle Mint](https://www.circle.com/en/usdc)
|
|
144
199
|
|
|
145
|
-
###
|
|
200
|
+
### Get POL (for gas)
|
|
201
|
+
- Most exchanges support Polygon
|
|
202
|
+
- Minimal amount needed (~$0.10 worth)
|
|
146
203
|
|
|
147
|
-
|
|
148
|
-
- Buy directly: Various exchanges support Polygon USDC
|
|
149
|
-
- Testnet: Use Amoy faucet for testing
|
|
204
|
+
---
|
|
150
205
|
|
|
151
206
|
## Security
|
|
152
207
|
|
|
153
|
-
|
|
154
|
-
- Use a dedicated wallet for your agent
|
|
155
|
-
-
|
|
156
|
-
-
|
|
208
|
+
⚠️ **Important:**
|
|
209
|
+
- Use a **dedicated wallet** for your agent
|
|
210
|
+
- Never share the private key
|
|
211
|
+
- Start with small amounts
|
|
212
|
+
- Monitor spending via `drain_balance()`
|
|
157
213
|
|
|
158
|
-
|
|
214
|
+
---
|
|
159
215
|
|
|
160
|
-
|
|
161
|
-
# Clone the repo
|
|
162
|
-
git clone https://github.com/kimbo128/DRAIN.git
|
|
163
|
-
cd DRAIN/mcp
|
|
216
|
+
## Troubleshooting
|
|
164
217
|
|
|
165
|
-
|
|
166
|
-
|
|
218
|
+
### "Insufficient USDC balance"
|
|
219
|
+
→ Send USDC to your wallet on Polygon network
|
|
167
220
|
|
|
168
|
-
|
|
169
|
-
|
|
221
|
+
### "Insufficient gas"
|
|
222
|
+
→ Send POL to your wallet for transaction fees
|
|
170
223
|
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
224
|
+
### "Channel not found"
|
|
225
|
+
→ The channelId might be wrong, use `drain_channel_status()` to verify
|
|
226
|
+
|
|
227
|
+
### "Channel not expired"
|
|
228
|
+
→ You can only close channels after the duration ends
|
|
229
|
+
|
|
230
|
+
### "No providers found"
|
|
231
|
+
→ Check your internet connection, try `drain_providers(onlineOnly: false)`
|
|
232
|
+
|
|
233
|
+
---
|
|
234
|
+
|
|
235
|
+
## Links
|
|
236
|
+
|
|
237
|
+
- **NPM:** https://www.npmjs.com/package/drain-mcp
|
|
238
|
+
- **GitHub:** https://github.com/kimbo128/DRAIN
|
|
239
|
+
- **Marketplace:** https://believable-inspiration-production-b1c6.up.railway.app
|
|
240
|
+
- **Contract:** `0x1C1918C99b6DcE977392E4131C91654d8aB71e64` (Polygon)
|
|
241
|
+
|
|
242
|
+
---
|
|
174
243
|
|
|
175
244
|
## License
|
|
176
245
|
|