Drain Mcp

io.github.kimbo128由 GitHub 帳號 kimbo128 發布v0.1.3更新於 Oct 24, 2026

Pay for AI inference with USDC micropayments on Polygon. No API keys needed.

概覽

AI 產生的概覽

一個本機 MCP 伺服器,讓助理探索 AI 服務市場中的提供者,並以 Polygon 上的 USDC 小額付款呼叫其服務,不需 API 金鑰。

可以做什麼
探索服務提供者並閱讀其使用文件,可依模型、類別或線上狀態篩選,涵蓋 LLM、影像、音訊、程式碼、擷取和 VPN 等服務。查詢錢包的 USDC 與 gas 餘額,並為付款合約授權 USDC 額度。開啟、列出和檢視付款通道,包括押金、已花費金額和到期時間。透過通道向任何類型的提供者送出付費請求,或對 MPP 提供者按次付費進行對話和 REST 呼叫。合作關閉通道以取得即時退款,或在到期後關閉通道取回資金,並回報提供者的成功或失敗。
適用情境
當助理需要呼叫 LLM 推論、搜尋、擷取或影像生成等外部服務,但不想持有 API 金鑰,且可接受以 USDC 按次付費時適用。若你已有目標服務的 API 金鑰,或工作不需要外部服務,則不需使用。
執行需求
以本機 npm 套件(drain-mcp)透過 stdio 執行,僅限桌面端。需要 Polygon 錢包私鑰,透過環境變數 DRAIN_PRIVATE_KEY 提供,並在 Polygon 主網持有 USDC;選用變數可設定鏈 ID、RPC 位址和 MPP 單次最大押金。需要連線 handshake58.com、各提供者端點以及 Polygon RPC 的網路存取。
安裝前請注意
伺服器在 DRAIN_PRIVATE_KEY 中持有錢包私鑰,並用它簽署付款和鏈上交易,因此應使用專用的低餘額錢包,切勿使用主錢包。請求會花費真實 USDC:通道押金、MPP 按次付款、gas 以及提供者結算時 2% 的協議費。通道中未花費的資金不會自動退回,必須關閉通道才能取回。請求訊息會送往第三方提供者,遙測、回饋和錢包位址會送往該市場。

安裝

在 SourceWeft 中

  1. 開啟 儀表板中的 Drain Mcp,將其新增到工作區。
  2. 為需要使用其工具的對話啟用該服務。

Desktop only,透過 STDIO。 STDIO 服務會啟動本機處理程序,因此需要 SourceWeft 桌面主機。

其他 MCP 客戶端

參照 儲存庫 中的啟動說明。

README

DRAIN MCP Server

Payments for AI Agents — No API keys, no credit cards, no subscriptions.

MCP server for the Handshake58 AI Marketplace. Agents discover service providers, pay automatically, and call any service — LLM inference, web scraping, image generation, search, and more.

Supports two payment protocols:

  • DRAIN — Payment channels on Polygon. Open once, send many requests, close when done.
  • MPP — Per-request payments via Tempo. Each request is paid individually. No channel needed.
DRAINMPP
SetupOpen channel ($0.02 gas)None
Per request$0.0001–$0.01Varies by provider
Best forHigh-volume sessionsSingle requests, REST APIs
PaymentUSDC on PolygonUSDC on Tempo chain

When to Use

Use drain-mcp when you need to:

  • Call any service (LLM, search, scraping, image gen, etc.) without API keys
  • Pay per-request with USDC — no subscriptions, no credit cards
  • Access 30+ providers through one unified interface

Do NOT use drain-mcp when:

  • You already have API keys for the service you need
  • The task doesn't require external services

TL;DR - Minimum Viable Workflow

MPP Providers (per-request, no channel)

1. drain_providers(protocol: "mpp")  → Find MPP providers2. drain_provider_info(id)           → Read docs (essential for REST APIs)3. mpp_chat(provider, messages)      → LLM providers (auto-pay via Tempo)   — OR —   mpp_request(url, body)            → REST API providers (auto-pay via Tempo)4. drain_feedback(providerId, outcome) → Optional: report success/failure

DRAIN Providers (payment channels)

1. drain_providers(protocol: "drain") → Find DRAIN providers2. drain_provider_info(id)            → Get provider details + usage docs3. drain_balance()                    → Check USDC + POL4. drain_approve()                    → Approve USDC spending (once)5. drain_open_channel(...)            → Deposit USDC, get channelId6. drain_chat(...)                    → Send requests (repeat as needed)7. drain_cooperative_close(...)       → Close early, instant refund (when done)   — OR after expiry —8. drain_close_channel(...)           → Reclaim funds (after expiry)

When to Close a Channel

  • Done with your task? → Use drain_cooperative_close(channelId). Instant refund of unspent deposit. Always do this when finished.

  • Planning more requests soon? → Keep the channel open. No need to close and reopen — saves $0.04 in gas fees.

  • Channel expired? → Use drain_close_channel(channelId). Reclaims unspent USDC after the expiry timestamp. Funds do NOT return automatically.

Rule of thumb: Close when the task is done. Keep open while working.


Already Hit a 402?

MPP providers: drain-mcp handles 402 automatically via mppx/Tempo. Just use mpp_chat or mpp_request — payment is resolved transparently.

DRAIN providers return 402 Payment Required with headers when no payment voucher is sent:

HeaderValue
X-Payment-Protocoldrain-v2
X-Payment-ProviderProvider wallet address (open channel to this)
X-Payment-ContractDRAIN contract address
X-Payment-Chain137 (Polygon Mainnet)
X-Payment-SigningURL for EIP-712 signing parameters
X-Payment-DocsProvider docs endpoint

DRAIN Flow:

  1. Call a provider endpoint (no voucher) → get 402 with headers
  2. Install drain-mcp or use the signing API at the X-Payment-Signing URL
  3. Open a channel to the X-Payment-Provider address
  4. Retry the request with an X-DRAIN-Voucher header

Everything you need is in the 402 response. No prior registration required.


Tools Reference

Discovery

drain_providers

Find service providers. Filter by model name, category, or online status.

json
{  "model": "gpt-4o",  "category": "scraping",  "onlineOnly": true}

Categories: llm, image, audio, code, scraping, vpn, multi-modal, other

drain_provider_info

Get details about a provider including usage instructions (docs). The docs explain how to format requests for that provider.

json
{ "provider": "hs58-openai" }

Wallet

drain_balance

Check wallet USDC balance, POL for gas, and DRAIN contract allowance.

drain_approve

Approve USDC spending for the DRAIN contract. Required once before opening channels.

json
{ "amount": "100" }

Channels

drain_open_channel

Open a payment channel. Locks USDC for the specified duration.

json
{  "provider": "hs58-openai",  "amount": "5.00",  "duration": "24h"}

Returns channelId, expiry time, and provider usage docs.

drain_channel_status

Check a channel's deposit, spending, remaining balance, and expiry.

drain_channels

List all known channels with status (active/expired/closed). Find expired channels that need closing.

Usage (DRAIN)

drain_chat

Send a paid request through a DRAIN channel. Works for ALL DRAIN provider types:

  • LLM providers: Standard chat messages
  • Non-LLM providers: JSON payload in the user message content (check provider docs)
json
{  "channelId": "0x...",  "model": "gpt-4o",  "messages": [{"role": "user", "content": "Hello"}]}

Usage (MPP)

mpp_chat

Send a chat request to an MPP LLM provider. Payment is automatic via Tempo — no channel, no setup.

json
{  "provider": "provider-id-or-url",  "messages": [{"role": "user", "content": "Hello"}],  "model": "optional-model-id"}
mpp_request

Send a request to an MPP REST API service (Tavily, Brave, Wolfram, etc.). Payment is automatic via Tempo.

json
{  "url": "https://tavily.mpp.paywithlocus.com/tavily/search",  "body": {"query": "AI agents", "max_results": 5}}

Read the provider's docs first (drain_provider_info) to find the correct endpoint paths and request format.

Quality Feedback

drain_feedback

Report success or failure after using any provider (DRAIN or MPP). Feeds the marketplace quality scoring system.

json
{  "providerId": "provider-id",  "outcome": "success",  "reason": "accurate_result"}

Settlement

drain_cooperative_close

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.

json
{ "channelId": "0x..." }
drain_close_channel

Close an expired channel and reclaim unspent USDC. Use when the channel has passed its expiry timestamp.

json
{ "channelId": "0x..." }

Economics Example

Opening a GPT-4o channel:

Gas to open channel:     $0.02   (one-time)Deposit:                 $0.50   (refundable remainder)Per request:            ~$0.001755Requests possible:      ~285
Cost for 10 requests:    $0.02 gas + $0.01755 usage = $0.04Refund after close:      $0.50 - $0.01755 = $0.48Gas to close:            $0.02
  • Protocol fee: 2% on provider claims (on-chain)
  • Session fee: none
  • Live pricing: GET https://handshake58.com/api/mcp/providers

Provider Categories

Providers are not limited to LLM chat. Each provider has a category field and a docs endpoint explaining how to format requests.

CategoryDescriptionMessage Format
llmLanguage models (GPT-4o, Claude, Grok, Gemini)Standard chat messages
imageImage generationJSON in user content (see docs)
audioAudio/TTS/STTJSON in user content (see docs)
codeCode generationStandard chat or JSON (see docs)
scrapingWeb scraping, data extractionJSON in user content (see docs)
vpnVPN servicesJSON in user content (see docs)
multi-modalMulti-modal modelsStandard chat messages
otherEverything elseAlways check docs

Rule: For any category other than llm, call drain_provider_info first to read the docs.


Decision Trees

Choosing a Protocol

What provider do I want?├── MPP provider (protocol="mpp")│   ├── mppType="llm" → mpp_chat(provider, messages)│   └── mppType="rest" → mpp_request(url, body)│   └── Done. Payment was automatic.│└── DRAIN provider (protocol="drain")    └── See DRAIN flow below

Starting a DRAIN Session

Do I have an active channel?├── YES → Use drain_chat() with existing channelId└── NO →    ├── drain_balance() → Do I have USDC?    │   ├── NO → Cannot proceed. Need USDC on Polygon.    │   └── YES →    │       ├── drain_providers() → Find provider    │       │   ├── NO providers → Cannot proceed.    │       │   └── Found provider →    │       │       ├── drain_approve() → First time only    │       │       └── drain_open_channel() → Get channelId    │       │           └── drain_chat() → Send requests

Ending a DRAIN Session

Am I done with this task?├── YES → drain_cooperative_close(channelId) → Instant refund└── NO →    ├── More requests soon? → Keep channel open    └── Channel expired? → drain_close_channel(channelId) → Reclaim funds

Choosing Amount and Duration

Use CaseAmountDuration
Quick test / single query$0.50 - $11h
Short task (few queries)$2 - $54h
Extended session$5 - $2024h
Long-running agent$20 - $1007d

Handling Errors

"Insufficient balance"→ Need more USDC. Check drain_balance().
"Insufficient allowance"→ Run drain_approve().
"Channel not found"→ channelId is wrong or channel was closed. Open new channel.
"Channel expired"→ For drain_chat: Open a new channel.→ For drain_close_channel: Expected. Proceed with close.
"Insufficient channel balance"→ Channel deposit used up. Open new channel with more funds.
"Provider offline"→ Use drain_providers() to find alternative provider.

Setup

1. Install

bash
npm install -g drain-mcp

2. Create a Wallet (locally)

Generate a key on your own machine — nothing is sent over the network:

bash
node -e "const w=require('ethers').Wallet.createRandom();console.log('Address:', w.address, '\nKey:', w.privateKey)"

3. Fund the Wallet

Send $1–5 USDC on Polygon Mainnet to your wallet address. Use a dedicated low-value wallet — never your main wallet.

No POL needed — if your wallet holds $5+ USDC, free gas is provided:

bash
curl -X POST https://handshake58.com/api/gas-station \  -H "Content-Type: application/json" \  -d '{"address": "0x_your_wallet_address"}'

Returns 0.1 POL (~10K transactions). Sends only your public address.

4. Configure MCP Client

json
{  "mcpServers": {    "drain": {      "command": "drain-mcp",      "env": { "DRAIN_PRIVATE_KEY": "0x..." }    }  }}

Environment Variables

VariableRequiredDefaultDescription
DRAIN_PRIVATE_KEYYes—Polygon wallet private key (also used for MPP/Tempo)
DRAIN_CHAIN_IDNo137137 (Polygon) or 80002 (Amoy testnet)
DRAIN_RPC_URLNoPublic RPCCustom Polygon RPC endpoint
DRAIN_MPP_MAX_DEPOSITNo1Max USDC per MPP session deposit

Security & Privacy

Key Handling

DRAIN_PRIVATE_KEY is loaded into memory by the local MCP process. It is used for:

  1. EIP-712 voucher signing for DRAIN channels (off-chain, no network call)
  2. On-chain transaction signing (signed locally, only the signature is broadcast)
  3. Tempo payment signing for MPP requests (handled by mppx, signed locally)

The key is never transmitted to any server. Providers verify signatures against on-chain state.

Spending Limits

DRAIN: Exposure is capped by the smart contract:

  • Maximum spend = channel deposit (you choose the amount)
  • Channel has a fixed duration (you choose)
  • After expiry, unspent funds are reclaimable via drain_close_channel

MPP: Each request is paid individually at the provider's advertised price. No pre-deposit required.

Both protocols: No recurring charges, no stored payment methods.

What Leaves Your Machine

  • Public API queries to handshake58.com (provider list, config, channel status)
  • Request messages to providers (sent to the provider's apiUrl, NOT to Handshake58)
  • Signed payment vouchers (contain a cryptographic signature, not the key)
  • Signed on-chain transactions (broadcast to Polygon RPC)

What Stays Local

  • Private key (never transmitted)
  • All cryptographic operations (signing happens in-process)

External Endpoints

Every network request the MCP server makes:

EndpointMethodData SentKey Transmitted?
handshake58.com/api/mcp/providersGETNothing (public catalog)No
handshake58.com/api/directory/configGETNothing (reads fee wallet)No
handshake58.com/api/channels/statusGETchannelId (public on-chain data)No
handshake58.com/api/gas-stationPOSTWallet addressNo
handshake58.com/api/telemetryPOSTProvider ID, latency, status, costNo
handshake58.com/api/feedbackPOSTProvider ID, outcomeNo
Provider apiUrl /v1/docsGETNothing (fetches usage docs)No
Provider apiUrl /v1/chat/completionsPOSTRequest messages + signed voucher (DRAIN)No
Provider apiUrl /v1/close-channelPOSTchannelId + close signatureNo
MPP provider endpointPOSTRequest body + Tempo payment (via mppx)No
Polygon RPC (on-chain tx)POSTSigned transactionsNo

Safeguards

  • Use a dedicated wallet with $1–5 USDC. Never reuse your main wallet.
  • Always generate keys locally. The key stays on your machine.
  • Open source: github.com/kimbo128/DRAIN (MIT licensed)
  • Open channels with small deposits. Close promptly when done.

Links

來源:mcp/README.md,提交 50b3a11

工具

0
SourceWeft 尚未在沙箱中啟動過該軟體包,因此其工具未知。

版本歷史

1
  1. v0.1.3最新Sep 16, 2026

評分

已滿足適用檢查項的 50%

該評分衡量此收錄條目的完整程度,依據註冊中心條目、端點與公開來源計算得出。它不是對伺服器本身的評價,也不表示伺服器安全或目前可用:可連通性是帶日期的檢查結果,評分也不包含安裝量或使用者評價。

  • 近 30 天內可連通25 分

    請保持端點能夠回應 MCP 握手;SourceWeft 每 30 天探測一次。

  • 已宣告認證方式10 分

    請在註冊中心條目中宣告憑證請求標頭,或保持端點能夠回應探測,以便判定其認證方式。

  • 已列出工具15 分

    請讓伺服器在無憑證時回應 tools/list,或發布可在沙箱中無憑證啟動的軟體包。

  • 描述必需15 分
  • 圖示10 分
  • 文件15 分
  • 授權條款10 分