AI Agent Integration (MCP)

Use the Lavarage API with AI assistants via Model Context Protocol.

Build Trading Agents with Lavarage

The Lavarage API is designed for programmatic access — which makes it a natural fit for AI agents. Any agent that can make HTTP calls can open, monitor, and close leveraged positions on Solana through Lavarage.

This documentation site supports Model Context Protocol (MCP), so AI assistants can read our API docs directly and generate accurate integration code.

What AI Agents Can Do

With a Lavarage API key, an agent can:

  • Trade any Solana token — open leveraged longs and shorts on 2800+ tokens
  • Monitor positions — track PnL, check health, detect liquidation risk
  • Manage risk — set take-profit/stop-loss orders, partial sell, add collateral
  • Execute strategies — momentum trading, mean reversion, portfolio rebalancing with leverage
  • Query markets — scan offers, compare rates, find the best liquidity pools

All operations return unsigned transactions. The agent (or user) signs and submits — Lavarage never holds private keys.

Connect Your AI Assistant

Claude (via MCP)

Add to your Claude MCP configuration (claude_desktop_config.json or .claude/settings.json):

{
  "mcpServers": {
    "lavarage-docs": {
      "command": "npx",
      "args": ["-y", "@anthropic-ai/mcp-server-fetch"],
      "env": {
        "ALLOWED_URLS": "https://lavarage-api.readme.io/*,https://api.lavarage.xyz/*"
      }
    }
  }
}

Then ask Claude: "Read the Lavarage API docs at https://lavarage-api.readme.io and help me open a 3x long SOL position."

Cursor

In Cursor settings → MCP, add the documentation source:

https://lavarage-api.readme.io

Cursor will automatically discover the API reference and guide pages.

Any MCP-Compatible Client

Point any MCP client at https://lavarage-api.readme.io. The assistant will discover all endpoints and guides automatically. See modelcontextprotocol.io for the full ecosystem of compatible tools.

Example: Agent Trading Flow

Here's what a typical AI agent trading session looks like:

Agent: "Open a 3x leveraged long on SOL with 1 SOL collateral"

1. Agent calls POST /api/v1/positions/quote-by-token
   → Gets price preview: entry at $152.40, 0.12% price impact

2. Agent calls POST /api/v1/positions/open-by-token
   → Gets unsigned transaction + position address

3. User signs the transaction in their wallet

4. Agent calls GET /api/v1/positions?status=OPEN
   → Monitors the position: current PnL, LTV, liquidation distance

5. Agent calls POST /api/v1/orders (with wallet signature)
   → Sets take-profit at $160 and stop-loss at $145

6. When ready to exit: POST /api/v1/positions/close
   → Builds close transaction, user signs, position closed

Quick Start for Agents

1. Get an API key:

curl -X POST https://api.lavarage.xyz/api/v1/partners/apply \
  -H "Content-Type: application/json" \
  -d '{
    "orgName": "My Trading Agent",
    "contactTelegram": "@myhandle"
  }'

2. Open a position:

curl -X POST https://api.lavarage.xyz/api/v1/positions/open-by-token \
  -H "x-api-key: YOUR_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "baseTokenMint": "So11111111111111111111111111111111111111112",
    "userPublicKey": "WALLET_ADDRESS",
    "collateralAmount": "1000000000",
    "leverage": 3,
    "side": "LONG",
    "slippageBps": 50
  }'

3. Sign and submit the returned transaction field (base58-encoded VersionedTransaction).

Key Endpoints for Agents

WhatEndpointAuth
Check if a token is tradeablePOST /positions/quote-by-tokenAPI key
Open a positionPOST /positions/open-by-tokenAPI key
List open positionsGET /positions?status=OPENAPI key
Close a positionPOST /positions/closeAPI key
Set TP/SL orderPOST /ordersAPI key + wallet signature
Get live pricesGET /sse (SSE stream)Optional API key
Browse marketsGET /offers?includeTokens=trueNone

Rate Limits

Agents should respect rate limits: 600 tx calls/min, 1800 read calls/min. Implement exponential backoff on 429 responses.

Learn More