# AI agents (MCP)

> Connect Claude, ChatGPT, Cursor and other AI agents to the hosted LayerHop MCP server at mcp.layerhop.com/mcp to list chains, quote swaps and prepare unsigned transactions. It holds no keys and never signs.

Source: https://docs.layerhop.com/guides/ai-agents

LayerHop runs a hosted [Model Context Protocol](https://modelcontextprotocol.io) server at `https://mcp.layerhop.com/mcp` that 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. The server holds no private keys and never signs or broadcasts: the user's own wallet signs every swap.

## What is the LayerHop MCP server?

`@layerhop/mcp` is an MCP server with fifteen tools over the [LayerHop API](/api-reference). An agent can answer "what's the cheapest way to move 100 USDC from Base to SOL on Solana?" with live quotes, then either give the user a [swap link](/guides/deep-links) to review and sign on layerhop.com, or, for agents that already have a user-controlled signer, return the unsigned transaction.

> [!IMPORTANT]
> The MCP server **holds no private keys and never signs or broadcasts**. It only reads quotes and prepares data. See [Non-custodial by design](/concepts/non-custodial).

| Mode | Use it for | Endpoint |
|---|---|---|
| Hosted (Streamable HTTP) | Any remote-capable MCP client; nothing to install | `https://mcp.layerhop.com/mcp` |
| Local (stdio) | Clients that launch a local process | the `layerhop-mcp` command from `@layerhop/mcp` |

Building your own agent instead of connecting an MCP client? The same tools ship as packages for the Vercel AI SDK, LangChain, OpenAI, ElizaOS, Coinbase AgentKit and GOAT: see [Agent frameworks](/guides/agent-frameworks).

## 1. Connect your client

### Claude Code

```bash
# Hosted server
claude mcp add --transport http layerhop https://mcp.layerhop.com/mcp

# Local stdio server 
claude mcp add layerhop -e LAYERHOP_API_KEY=lh_live_xxx -e LAYERHOP_INTEGRATOR=myapp -- npx -y @layerhop/mcp
```

### Claude Desktop

Add the hosted URL as a custom connector, or run the stdio server from `claude_desktop_config.json` (Settings → Developer → Edit Config), then restart the app:

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

### Cursor and other JSON-configured clients

Most clients take the same shape. In Cursor, use `~/.cursor/mcp.json` (all projects) or `.cursor/mcp.json` (one project):

```json
{
  "mcpServers": {
    "layerhop": { "url": "https://mcp.layerhop.com/mcp" }
  }
}
```

For a local stdio server, replace the entry with `{ "command": "npx", "args": ["-y", "@layerhop/mcp"] }`.

### ChatGPT and other remote clients

Add a remote MCP server (often called a connector) with the URL `https://mcp.layerhop.com/mcp`. No OAuth is needed.

## 2. Add your API key and partner id (optional)

Without a key the server works anonymously under the per-IP [rate limit](/guides/dashboard-and-api-keys). With an API key from [dashboard.layerhop.com](https://dashboard.layerhop.com) you get your key's rate limit, and your orders show up in the dashboard and trigger your [webhooks](/guides/webhooks). The [deposit address](/guides/deposit-addresses) tools always need a key: without one they answer with an error that explains how to add it.

**Hosted server**, per request headers:

| Header | Meaning |
|---|---|
| `x-layerhop-api-key: lh_live_…` (or `Authorization: Bearer lh_live_…`) | Your API key for that request. An `lh_test_…` key works too (test mode). |
| `x-layerhop-integrator: myapp` | Your [partner id](/guides/partner-fees), added to quotes and swap links. |

The hosted server is stateless and sends CORS headers, so browser-based clients can call it directly. `GET /healthz` reports health.

**Local server**, environment variables:

| Variable | Default | Meaning |
|---|---|---|
| `LAYERHOP_API_URL` | `https://api.layerhop.com` | API base URL. |
| `LAYERHOP_API_KEY` | none | API key (`lh_live_…`, or `lh_test_…` for test mode). Required for deposit addresses. |
| `LAYERHOP_INTEGRATOR` | none | Partner id. Adds your partner fee and is included in swap links. |
| `LAYERHOP_APP_URL` | `https://layerhop.com` | Base URL for swap links. |
| `LAYERHOP_DOCS_URL` | `https://docs.layerhop.com` | Docs site for the `llms.txt` resource. |

To self-host the HTTP transport, run the CLI with `--http`:

```bash
layerhop-mcp --http --port 8090 --host 0.0.0.0
# MCP endpoint: http://localhost:8090/mcp   health: GET /healthz
```

Flags: `--http`, `--port` / `-p` (default `8090`, or `PORT`), `--host` (default `127.0.0.1`, or `HOST`), `--help`, `--version`.

Quotes made through MCP use the `api` [fee channel](/concepts/fees-and-channels) (0.10%). Swap links open the web app, which quotes on the `web` channel (0.15%).

## 3. Use the tools

**Amounts in tool inputs are human decimals:** `"100"` means 100 USDC and `"0.05"` means 0.05 ETH. The server converts them to base units with the token's decimals using integer math, and rejects amounts of 0 or less. Addresses are checked against the chain's VM: `0x…` for EVM, base58 for Solana.

| Tool | Inputs | What it returns |
|---|---|---|
| `list_chains` | none | Supported chains: slug, id, name, VM, native coin and decimals. |
| `list_tokens` | `chain` | Tokens on a chain: symbol, address or mint, decimals. |
| `lookup_token` | `address`, `chain?` | One token's symbol, name, decimals, price and `verified` flag. Without `chain`, LayerHop finds the chain. |
| `get_token_risk` | `chain`, `token` | A [token risk](/api-reference#check-a-token-for-risks) report: `ok`, `caution`, `danger` or `unknown`, with reasons (honeypot, taxes, owner powers, fake majors) and what to tell the user. |
| `get_quote` | `fromChain`, `fromToken`, `amount`, `toChain`, `toToken`, `sender`, `recipient?`, `slippageBps?`, `fromTokenDecimals?`, `toTokenDecimals?`, `gasless?` | The best quote plus alternatives (see below). `recipient` is required for EVM ↔ Solana; the decimals are needed only for tokens not on a list. A `NO_ROUTE` error lists the API's [suggestions](/errors/NO_ROUTE) in human units (a `via_hub` one as two separate swaps), and `AMOUNT_TOO_SMALL` states the route's minimum. |
| `get_swap_link` | `fromChain`, `fromToken`, `toChain`, `toToken`, `amount?`, `recipient?`, `slippageBps?` | A `https://layerhop.com/swap?…` [deep link](/guides/deep-links). **The default, safest way to execute.** |
| `build_transaction` | `quoteId` | The **unsigned** transaction with plain-language signing steps. For a [gasless](/guides/gasless-swaps) quote: the EIP-712 typed data instead, with a note that the server can't sign or submit it (hand the user the swap link). Tron transactions are not supported by the agent tools. |
| `simulate_transaction` | `quoteId` | A dry run: success or the failure reason, gas or compute units, whether an approval is still needed. Nothing is sent. See [Simulation](/concepts/simulation). |
| `report_submitted` | `quoteId`, `txHash` | Tells LayerHop the user broadcast the transaction, so the order is tracked and webhooks fire. |
| `get_order_status` | `provider`, `txHash` | `pending`, `filled`, `refunded`, `failed`, `dropped` (the transaction never reached the network) or `unknown`. See [Order tracking](/concepts/order-tracking). |
| `list_orders` | `address`, `status?`, `limit?` (1–100), `cursor?` | Orders where the address is the sender or the recipient. |

### Solana limit order tools

[Limit orders](/guides/limit-and-recurring-orders) sell a token on Solana once the price is reached. The create and cancel tools return an **unsigned** transaction: only the maker's own wallet signs it, and `submit_limit_order` relays the signed transaction.

| Tool | Inputs | What it returns |
|---|---|---|
| `create_limit_order` | `wallet`, `sellToken`, `sellAmount`, `buyToken`, `minReceive`, `expiresInMinutes?` | The order (human amounts) and its unsigned transaction with signing steps. |
| `submit_limit_order` | `id`, `signedTransaction` | Relays the wallet-signed create or cancel transaction; returns its signature. |
| `list_limit_orders` | `wallet?`, `status?`, `limit?`, `cursor?` | Orders of a wallet (or of the API key's account). |
| `get_limit_order` | `id` | One order with its fills. |
| `cancel_limit_order` | `id` | The unsigned cancel transaction (an order that was never submitted is cancelled at once). |

### Deposit address tools (API key required)

[Deposit addresses](/guides/deposit-addresses) let a user swap or bridge by just sending a token to an address. These tools need an API key and act on the key's account and mode.

| Tool | Inputs | What it returns |
|---|---|---|
| `create_deposit_address` | `fromChain`, `fromToken`, `toChain`, `toToken`, `recipient`, `refundTo`, `reusable?`, `amount?`, `fromTokenDecimals?`, `label?`, `metadata?` | The address, what to send where, fees, an estimate in human units, and `tellTheUser`: the rules the agent must relay. `amount` is in human units and is required when `reusable` is `false`. |
| `list_deposit_addresses` | `status?`, `label?`, `limit?` (1–100), `cursor?` | The account's addresses, newest first. |
| `get_deposit_address` | `id` | The address with its 20 most recent deposits (amounts deposited and delivered, status, tx hashes). |
| `refresh_deposit_address` | `id` | Checks for deposits right away. Call it when the user says they sent funds. |
| `disable_deposit_address` | `id` | Stops tracking the address. The agent should confirm with the user first. |
| `simulate_deposit` | `id`, `amount` or `amountBaseUnits` | **Test keys only.** Records a fake deposit; base units ending in `4001` are refunded, `4002` fail. |

Tool descriptions and every response tell the model to relay these rules to the user: **send only `srcToken` on `srcChain`** (anything else may be lost), **at least $1 worth**, and **`refundTo` must be the user's own address, never an exchange deposit address**. With an `lh_test_` key the address is a fake sandbox address: never send real funds to it.

`slippageBps` accepts 1–5000 and defaults to 50 (0.5%). Chains can be slugs (`base`) or numeric ids (Solana is `7565164`).

Each quote from `get_quote` contains:

- the expected output and the minimum after slippage, in human units
- the LayerHop fee as a percentage and in tokens, and the partner fee if any
- provider and gas fees in USD
- the estimated time
- a `quoteId` and its `expiresAt`
- a ready-made `swapLink`

`build_transaction` returns either an **EVM** transaction `{ chainId, to, data, value }`, plus an ERC-20 `approval` to send first when needed, or a **Solana** base64 `serializedTx`.

The server also exposes:

| Kind | Name | Content |
|---|---|---|
| Resource | `layerhop://chains` | The chain list as JSON. |
| Resource template | `layerhop://tokens/{chain}` | Tokens on one chain as JSON. |
| Resource | `https://docs.layerhop.com/llms.txt` | The docs index for LLMs. |
| Prompt | `swap_assistant` | Walks the model through a safe swap. Optional `request` argument, for example "swap 100 USDC on Base to SOL". |

## How does the MCP server keep users safe?

- **No keys, no signing.** The server cannot move funds. The worst a malicious prompt can produce is a quote or an unsigned transaction, and only the user's wallet can sign it, after the user approves it there.
- **Humans confirm.** Tool descriptions and the `swap_assistant` prompt tell the model to show every fee, the minimum received and the ETA, get explicit confirmation, and prefer a swap link, where the user sees the live quote before signing.
- **Raw transactions are opt-in.** `build_transaction` is for agents that already have a signer the user controls, such as a smart-account session key. Run `simulate_transaction` first.
- **Inputs are validated** before any API call: address format per VM, positive amounts with no more decimals than the token has, and explicit decimals for unlisted tokens.
- **Never share a seed phrase or private key with an AI agent.** LayerHop never asks for one.

## Example conversation

> **You:** Swap 100 USDC on Base to SOL. My Solana address is 9WzD…AWWM.
>
> **Agent** (calls `get_quote`): The best route is via Relay. You would receive about *X* SOL, at least *Y* SOL after 0.5% slippage, in about *N* seconds. LayerHop's fee is 0.1% (0.1 USDC), plus the provider and gas fees shown. Open this link to review the live quote and sign in your wallet: `https://layerhop.com/swap?srcChain=base&srcToken=USDC&dstChain=solana&dstToken=SOL&amount=100&recipient=9WzD…&ref=mcp`

The values in italics stand for the live quote; the agent shows the real numbers.

## How can an AI read these docs?

- [`/llms.txt`](/llms.txt): an index of every page with a one-line summary, following the llms.txt convention.
- [`/llms-full.txt`](/llms-full.txt): every page concatenated as one Markdown file.
- **Per-page Markdown:** add `.md` to any page URL, for example `https://docs.layerhop.com/quickstart.md`. Each page also links it as `<link rel="alternate" type="text/markdown">`.
- **Copy page as Markdown** and **Open in Claude / ChatGPT** buttons at the top of every page.
