dh-mcp

v0.5.25
@gvnrdao/dh-mcp Checked 2 days ago Published 1 month ago

MCP server for the Diamond Hands protocol

MCP (Model Context Protocol) server for the Diamond Hands protocol. It lets an AI agent — through any MCP host (Claude, IDEs, agent runtimes) — operate Bitcoin-collateralized UCD lending on a user's behalf, with a human approving every fund-moving step. Two paths, and neither downloads a file: To rehearse on the test network, say so — network_switch takes you to sepolia in one sentence, or set DH_NETWORK=sepolia. Everything is overridable by environment variable:

Summary extracted from the README.

@gvnrdao/dh-mcp

MCP (Model Context Protocol) server for the Diamond Hands protocol. It lets an AI agent — through any MCP host (Claude, IDEs, agent runtimes) — operate Bitcoin-collateralized UCD lending on a user's behalf, with a human approving every fund-moving step.

Install

Two paths, and neither downloads a file:

You want How
The hosted connector — nothing to install, no Node Paste https://mcp.diamondhands.credit/mcp into any host that accepts a remote MCP server URL: claude.ai and Claude Desktop (Settings → Connectors → Add custom connector), Cursor, VS Code, Codex, Gemini CLI, OpenCode, Grok. Sign in with your wallet — OAuth 2.1 + Sign-In-with-Ethereum, dynamic client registration, so there is no client ID or secret to configure. External-wallet signing only: that build has no keystore mode. Serves mainnet.
Run it yourself — requires Node ≥ 18 on PATH Claude Code: claude mcp add diamond-hands -- npx -y @gvnrdao/dh-mcp · any host JSON: { "mcpServers": { "diamond-hands": { "command": "npx", "args": ["-y", "@gvnrdao/dh-mcp"] } } }. Defaults to mainnet, read-only until you configure a signer; keystore signing is available here, and network_switch (or DH_NETWORK=sepolia) moves you to the test network.

Per-client setup instructions: https://app.diamondhands.credit/connect

There are no downloadable builds. The self-contained binaries, the Claude Desktop .mcpb bundle, install.sh and SHA256SUMS under assets.gvnr.xyz/dh-mcp were withdrawn on 2026-09-18 and every path there now returns 404. The hosted connector replaces them for machines without Node — including Claude Desktop, which takes a remote server URL directly — and npx replaces them everywhere else. Treat any surviving link to that host, anywhere, as stale.

Troubleshooting spawn npx ENOENT: your MCP host searched the system PATH and found no npx — the machine has no Node.js (or the host, e.g. an Electron app, cannot see your shell's version manager). That is the npx path's stated precondition, not a bug in the server. Use the hosted connector instead: it needs no local runtime at all.

Zero configuration boots the real protocol on ETHEREUM MAINNET with public endpoints — the same network the hosted connector serves, so a local install and a hosted one agree about where your money is. It starts read-only: with no signer configured every write answers with a setup invitation instead of acting, and moving value always needs a signer, an explicit confirmation, and a fresh signature from your own wallet.

To rehearse on the test network, say so — network_switch takes you to sepolia in one sentence, or set DH_NETWORK=sepolia. Everything is overridable by environment variable:

Variable Default Meaning
DH_ADAPTER real real protocol, or mock (offline practice sandbox; needs DH_MOCK_DB + DH_MOCK_LATENCY)
DH_NETWORK mainnet mainnet (REAL money — reads and writes both work out of the box) or sepolia (practice)
ETH_RPC_URL our RPC proxy per network (api.gvnr.xyz/v1/proxy/rpc/<chainId> — dRPC upstream, keys held server-side, no credential needed here) your own RPC if preferred. URLs are cut to their host in every error this server renders
DRPC_API_KEY unset a dRPC key: the server uses dRPC directly for the active network, sending the key in the Drpc-Key header, never in the URL. Set this or ETH_RPC_URL, not both
DH_SERVICE_ENDPOINT per network Diamond Hands ops service
DH_KEYSTORE_PATH + DH_KEYSTORE_PASSWORD unset optional: encrypted keystore for automatic signing (both or neither)

Signing is chosen by conversation (signer_setup — available on the real adapter): your own wallet (recommended — MetaMask browser popup, or WalletConnect for mobile — scannable QR or paste-code) or a local encrypted keystore (legacy, opt-in). See Where signing keys live. Safe smart-account and delegation modes are mock-only for now (table below).

What works where

Network Reads (public) Reads (authenticated) Writes
sepolia (default — the real protocol, practice money) always, no setup after a login: keystore env pair, or "connect my wallet" (signer_setup) signer modes keystore and external (your own wallet). External-mode BTC withdrawal signs the SDK's bare auth hashes blind — same as the web app; the approval page says so loudly
mainnet (real money) always (indexer gaps are reported honestly) after a login (the broker throttles logins per address) signer modes keystore and external, same as sepolia — every operation moves REAL funds behind your confirmation + signature. PSM swaps included: you must NAME the stablecoin (verified on-chain before signing), and the PSM contract's own caps, pause switches and reserves bound every swap
mock (DH_ADAPTER=mock — offline practice sandbox) always always all modes, including the simulated Safe and delegation planes

Signer modes safe and safe-module (Safe smart-account borrower, delegation) are mock-only pending their own deliveries — on the real adapter they refuse with that true reason. Reads never trigger wallet popups: an authenticated read without a login refuses legibly, and the user says "connect my wallet" (signer_setup action connect).

Security posture (what this package will never do)

  • No secrets ship, ever. The package contains code only; every credential enters on YOUR machine via env vars, a secure local unlock page, or your own wallet. Passwords pasted into chat are refused by design.
  • The approval bridge listens on loopback only (127.0.0.1, token-gated).
  • Every fund-moving call requires your explicit confirmation AND a real signature; the card you sign is decoded from the exact transaction — never re-formatted.
  • Mainnet operations move real funds — they run only behind your explicit confirmation plus a real signature you approve. PSM swaps are no exception: they execute on mainnet and move real USDC and UCD, with the named-and-on-chain-verified stablecoin plus the PSM contract's own caps, pause switches and reserves as the bounds.

Where signing keys live

In your wallet — not in this server, and not in your MCP host's config file. Crypto keys cannot be rotated the way an API key can, so the recommended signing mode (and the only mode the hosted connector has) never gives the MCP a private key at all.

Mode Where the key is What the MCP holds Status
external — your own wallet your wallet (MetaMask, or a mobile wallet over WalletConnect) your public address — nothing secret recommended; the only mode in the hosted connector
keystore — automatic signing an encrypted (scrypt, ethers V3) keystore file on your machine the decrypted key, in memory, for as long as the server runs legacy, opt-in, local builds only
raw DH_PRIVATE_KEY env var plaintext in the host config the key removed — no longer in the code

Wallet signing (external mode)

The same model as other wallet-first crypto MCPs: the server prepares the transaction or the EIP-712 typed data, and your wallet signs it.

  1. The MCP builds the transaction and decodes its calldata against a whitelist of protocol functions — calldata that does not decode is refused before it ever reaches your wallet.
  2. That decode becomes the approval card, shown on a token-gated approval page that hands the request to MetaMask, or as a WalletConnect QR / pairing code for a mobile wallet:
    • Local (stdio / loopback connector): http://127.0.0.1:<port>/ (token-gated).
    • Hosted connector: {publicOrigin}/approval/<mountId>/ (token-gated) — the connector's own public origin, never loopback.
  3. You review and sign in your wallet; the wallet broadcasts.
  4. The MCP receives only the transaction hash, then verifies the landed transaction matches the approved to / data / value / chainId and was sent by your address. A mismatch is reported loudly, never silently retried.
  5. Login is an audience-bound EIP-712 signature through the same wallet.

What rests on your machine in this mode: the MCP host config (~/.claude.json, claude_desktop_config.json) holds the launch command and, optionally, the network and RPC URL — no key, no seed, no password. ~/.dh-mcp holds the chosen signer mode and your public address. Login session tokens live in process memory only.

One stated gap: the BTC-withdrawal EXECUTE step asks the wallet to personal_sign a bare 32-byte hash built inside the SDK — identical to how diamondhands.credit signs it. The approval card says plainly that this hash cannot be decoded, and gives its real expiry deadline. Every other request is decoded before you sign.

Keystore mode (legacy, opt-in)

The first signing model, kept for headless local use. The key is encrypted at rest, but the running process holds it decrypted, and anyone who can read both the keystore file and its password has the key. Where the password lives is therefore the whole risk:

  • Claude Desktop .mcpb — held by the OS credential store (the field is marked sensitive), not written to a config file.
  • The unlock page (signer_setup → "unlock my keystore") — typed into the local loopback page, never written anywhere.
  • DH_KEYSTORE_PASSWORD in an env block or claude mcp add -e … — stored in plaintext in the host config, next to the keystore path. That is exactly the pattern this section exists to avoid: do not use it for real funds — use wallet signing.

Passwords pasted into chat are refused by design. The hosted connector cannot run keystore mode at all: the keystore runtime is not part of that build, and it refuses to boot if keystore variables are present.

What it solves

Diamond Hands is otherwise operated by hand. This server adds a conversational access channel: "open me a 12-month position", "mint 500 UCD", "how is my loan doing?" — while keeping every irreversible action behind explicit human confirmation.

For an agent to act safely on a live lending protocol, it must never act on guessed configuration, stale state, or errors it cannot interpret. The server is therefore built around a strict trust boundary (see below) whose contract is: never guess, never misrepresent upstream state, always answer with legible, typed results.

What it supports

Borrowing lifecycle (write tools — human-gated, signer required):

Tool Meaning
loan_create Open a position: BTC custody vault + PKP, returns the vault deposit address
loan_mint Mint UCD against BTC collateral
loan_pay Repay UCD debt (partial or full)
loan_extend Renew the position term (pro-rata fee)
loan_withdraw Withdraw BTC from the vault (unrecoverable — strictest gate)
loan_recover_stale_spend Clear a stale BTC withdrawal reservation (permissionless)
loan_allowlist_destination Register a BTC withdrawal destination in the registry (delay-gated on live networks)
psm_swap Swap USDC ↔ UCD through the PSM (quotes via the psm_quote read; mainnet PSM writes always refuse)
loan_delegation_setup / loan_delegation_grant Safe delegation plane — practice (mock) only today; real refuses with that true reason

Authorization by conversation: signer_setup — the user picks external wallet (MetaMask popup / WalletConnect QR), local encrypted keystore, or the Safe modes by TALKING; secrets never travel through chat. guide serves the walkthroughs (first-setup, connect-wallet, safe, delegation, troubleshooting, …).

Observability (read tools + resources, no signer needed): position status, listings, event history, pending withdrawals (position_*, position://{id}), protocol health and terms (protocol_*, protocol://config, protocol://terms), BTC balance and oracle price (btc_*), and boundary://info — which world the server is talking to (adapter, sources, signer identity; never secrets), including its capabilities block: network, chain id, practice-vs-real money, whether reads need a login, whether writes are enabled (and the true reason when not), and which signer modes this build offers.

Architecture: the protocol boundary

All protocol traffic passes through one module — the ProtocolBoundary port (anticorruption layer). Tools and resources never touch protocol surfaces directly.

  • Every call returns a result envelope: data + data-source identity + explicit discrepancy warnings, or a typed error from a small closed taxonomy. Raw upstream text never reaches the agent.
  • Configuration has zero silent defaults: anything missing or invalid is a loud, actionable CONFIG_MISSING error.
  • If upstream sources disagree or lag, the boundary reports the divergence explicitly instead of presenting one side as truth.
  • A single switch (DH_ADAPTER=mock|real) selects the adapter behind the port.

The real adapter (the zero-config default) speaks to the live protocol: the Diamond Hands SDK, the lit-ops service, and an Ethereum RPC. Public reads need no setup; authenticated reads need a login; writes run on sepolia through the keystore or the user's own wallet (capability table above). The mock adapter is a full protocol simulator: complete position lifecycle (deposit → active → repaid → closed), LTV-checked mints, fee math, event history — held in memory, persisted to a local file DB (survives restarts), with deterministic operation delays and injectable fault scenarios. It enables end-to-end agent development and testing with zero funds at risk, offline.

In one paragraph: tools and resources talk only to the ProtocolBoundary port; behind it sit the two adapters, a signer layer (signer_setup) with a loopback-only approval bridge for external wallets, and a result-envelope contract carrying data provenance and typed errors — never raw upstream text. The full design docs (use cases, sequence diagrams, data contracts, scenario catalog) live in the repository: https://github.com/gvnrdao/diamond-hands.

Reliability status

  • Behavior is pinned by scenario tests that run through the genuine MCP request path (in-memory client/server pair), covering happy paths and failure classes alike (missing config, uncollateralized operations, source divergence, upstream outages).
  • Current stage: real adapter (sepolia AND mainnet, reads and writes) + mock simulator, all behind the same boundary contract and the same scenario suites. External-wallet signing runs on the real adapter, including BTC withdrawal (blind hash signatures, site-parity — the approval card states the contents are not decodable; keystore withdrawal signs locally).
  • Reads are unrestricted, with indexer gaps reported honestly.

Security model

These tools move real funds and create on-chain state. Treat them accordingly.

Write tools require explicit human confirmation (audit H-5)

The irreversible, fund-moving tools — loan_create, loan_mint, loan_pay, loan_extend, loan_withdraw — are gated by a confirmed: true parameter. They refuse to run until it is set, and it is meant to be set by a human, not by the model:

  • The model should surface the exact operation (amounts, destination address, position) to the user and obtain explicit approval before re-invoking with confirmed: true.
  • These tools are annotated destructiveHint: true; compliant MCP hosts present an approval prompt.
  • In a fully headless context with no human in the loop, leave confirmed unset — the tool will refuse rather than move funds silently.

loan_withdraw sends BTC to an external address and is unrecoverable. The destination address is validated against the configured BTC network — a mismatched-network address is rejected before signing — but address correctness is still the human's responsibility.

Signer required for writes

All write tools require a configured signer; without one they return a typed SIGNER_UNAVAILABLE error. On the real adapter the two remedies are the keystore env pair (DH_KEYSTORE_PATH + DH_KEYSTORE_PASSWORD) or connecting the user's own wallet (signer_setup, mode external). In mock mode the signed identity is DH_MOCK_BORROWER.

Supply chain (audit H-6)

Dependencies are pinned to exact versions so nothing drifts silently between installs. Bump deliberately, in lockstep with sibling packages, and run npm ci in CI.

Mainnet moves real funds

Mainnet reads and writes both work out of the box. Every fund-moving operation still requires the explicit human confirmed: true plus a real signature (wallet approval card or keystore), and the network switch ceremony states the money reality loudly. Review your host's approval flow and key management before using mainnet. Mainnet PSM swaps are enabled too: name the stablecoin (it is verified against the PSM's supported set on-chain before anything is signed), and the contract's per-operation and per-block caps, paused / redeemEnabled and live reserves still bound every swap.

For AI assistants

  • Read boundary://info FIRST. Its capabilities block is the truth about the session: network, chain id, practice-vs-real money, whether reads need a login, whether writes are enabled (and the true reason when not), which signer modes exist, and whether signer_setup is registered. Never promise a capability it does not list.
  • Use the guide:// topics (also served by the guide tool) — guide://index lists them; getting-started, first-setup, and connect-wallet carry the onboarding path. Narrate them in the user's language.
  • Never invent flows. Every refusal names its true reason and next step — relay that, don't improvise around it.
  • Claude Code users may copy the guide://index content into a project skill for persistent context across sessions.