LayerHopdocs

Guides

AI agents (MCP)

Let Claude, ChatGPT, Cursor and other AI agents quote and prepare LayerHop swaps through the LayerHop MCP server. It holds no keys and never signs.

Open in ClaudeOpen in ChatGPT

@layerhop/mcp is a Model Context Protocol server. It lets an AI agent list chains and tokens, get best-price quotes with every fee spelled out, and hand the user a prefilled swap link. Agents that already have their own signer can also ask it for the unsigned transaction.

Source: github.com/layerhop/layerhop-js (packages/mcp) — source repository (opens at launch).

Important

The MCP server holds no private keys and never signs or broadcasts. It only reads quotes and prepares data. The user's own wallet signs, as on layerhop.com. See Non-custodial by design.

You can run it two ways:

Mode Use it for Endpoint
Hosted (Streamable HTTP) Remote-capable clients; nothing to install https://mcp.layerhop.com/mcp
Local (stdio) Claude Desktop, Claude Code, Cursor, any stdio client npx -y @layerhop/mcp

Setup#

Claude Code#

Terminal
# Hosted
claude mcp add --transport http layerhop https://mcp.layerhop.com/mcp

# Or run it locally (stdio)
claude mcp add layerhop -- npx -y @layerhop/mcp

# Locally, with your API key and partner id
claude mcp add layerhop -e LAYERHOP_API_KEY=lh_live_xxx -e LAYERHOP_INTEGRATOR=myapp -- npx -y @layerhop/mcp

Claude Desktop#

Edit claude_desktop_config.json (Settings → Developer → Edit Config), then restart Claude Desktop:

JSON
{
  "mcpServers": {
    "layerhop": {
      "command": "npx",
      "args": ["-y", "@layerhop/mcp"],
      "env": { "LAYERHOP_API_KEY": "" }
    }
  }
}

LAYERHOP_API_KEY is optional. You can also add the hosted URL as a custom connector instead.

Cursor#

Add the server to ~/.cursor/mcp.json (all projects) or .cursor/mcp.json (one project):

JSON
{
  "mcpServers": {
    "layerhop": { "command": "npx", "args": ["-y", "@layerhop/mcp"] }
  }
}

To use the hosted server instead, set "layerhop": { "url": "https://mcp.layerhop.com/mcp" }.

ChatGPT and other remote MCP clients#

Add a remote MCP server (also called a connector) with the URL https://mcp.layerhop.com/mcp. It needs no OAuth.

The server is stateless and allows CORS, so browser-based clients can call it directly. It also takes two optional headers:

  • x-layerhop-api-key: lh_live_… (or Authorization: Bearer lh_live_…) uses your API key (from dashboard.layerhop.com) for that request.
  • x-layerhop-integrator: myapp sets your partner id.

Configuration (stdio)#

Variable Default Meaning
LAYERHOP_API_URL https://api.layerhop.com API base URL
LAYERHOP_API_KEY none Optional API key (lh_live_…) for your own rate limit, dashboard and webhooks
LAYERHOP_INTEGRATOR none Optional partner id. It adds your partner fee and is included in swap links
LAYERHOP_APP_URL https://layerhop.com Base URL for the swap links

Quotes made through MCP use the api fee channel. Swap links open the web app, which uses its own channel.

Self-hosting the HTTP server#

Terminal
npx -y @layerhop/mcp --http --port 8090 --host 0.0.0.0
# MCP endpoint: http://localhost:8090/mcp    health: GET /healthz

Tools#

Amounts in tool inputs are human decimals. For example, "100" means 100 USDC and "0.05" means 0.05 ETH. The server converts them to base units using the token's decimals, with integer math. Amounts of 0 or less are rejected.

Addresses are checked against the chain's VM: 0x… for EVM, base58 for Solana.

Tool What it does
list_chains Supported chains: slug, id, VM and native coin.
list_tokens { chain } Built-in tokens on a chain: symbol, address or mint, decimals.
get_quote { fromChain, fromToken, amount, toChain, toToken, sender, recipient?, slippageBps? } The best quote plus alternatives. See below for what each quote contains.
get_swap_link { fromChain, fromToken, toChain, toToken, amount?, recipient?, slippageBps? } A https://layerhop.com/swap?… deep link. The user reviews the swap and signs in their own wallet. This is the default, safest way to execute.
build_transaction { quoteId } The unsigned transaction, with plain-language signing steps. See below.
simulate_transaction { quoteId } A dry run of the transaction: will it succeed, gas or compute units, is an approval still needed. Nothing is sent.
report_submitted { quoteId, txHash } Call after the user's wallet broadcasts. LayerHop then tracks the order and fires webhooks.
get_order_status { provider, txHash } Returns pending, filled, refunded, failed or unknown. See Order tracking.
list_orders { address, status?, limit?, cursor? } Orders where the address is the sender or the recipient.

Each quote from get_quote includes:

  • output and minimum after slippage, in human units
  • the LayerHop fee, as a % and in tokens
  • the partner fee, if any
  • provider and gas fees in USD
  • ETA
  • quoteId and expiresAt
  • a ready-made swapLink

build_transaction returns one of:

  • EVM: { chainId, to, data, value }, plus an ERC-20 approval to send first if one is needed.
  • Solana: a base64 serializedTx.

The server also provides:

  • Resources:
    • layerhop://chains
    • layerhop://tokens/{chain}
    • the docs index at https://docs.layerhop.com/llms.txt
  • Prompt: swap_assistant, which walks the model through a safe swap.

Safety model#

  • No keys, no signing. The server cannot move funds. The worst a bad prompt can do is produce a quote or an unsigned transaction. Only the user's wallet can sign it, and only after the user approves it there.

  • Humans sign by default. The tool descriptions and the swap_assistant prompt tell the model to:

    • show every fee, the minimum received and the ETA
    • get explicit confirmation from the user
    • prefer handing over a swap link

    On layerhop.com the user sees the live quote and signs in their own wallet.

  • Raw transactions are opt-in. build_transaction is meant for agents that already have a signer the user controls, such as a smart-account session key or a wallet SDK. Use simulate_transaction first.

  • Never share a seed phrase or private key with an AI agent. LayerHop never asks for one.

  • Inputs are validated before any API call:

    • the address format must match each chain's VM
    • amounts must be positive and not have more decimals than the token
    • unknown tokens must come with their decimals

Example conversation#

You: Swap 100 USDC on Base to SOL. My Solana address is 9WzD…AWWM.

Agent (calls get_quote): Best route is Relay. You'd receive about 0.9497 SOL, minimum 0.9450 after 0.5% slippage, in about 1 s. The LayerHop fee is 0.2% (0.2 USDC), plus about $0.12 in provider fees. Open this link to review and sign in your wallet: https://layerhop.com/swap?srcChain=base&srcToken=USDC&dstChain=solana&dstToken=SOL&amount=100&recipient=9WzD…&ref=mcp