lifi-mcp

jayeshchowdary/lifi-mcp

3.2

If you are the rightful owner of lifi-mcp and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to henry@mcphub.com.

A Model Context Protocol (MCP) server for interacting with Li.FI cross-chain bridge and swap aggregator.

Tools
17
Resources
0
Prompts
0

LiFi MCP Server (Python)

A Model Context Protocol (MCP) server for interacting with Li.FI cross-chain bridge and swap aggregator.

Built with FastMCP framework for robust MCP protocol implementation.


๐Ÿ“‹ Table of Contents


๐Ÿš€ Quick Start

Prerequisites

  • Python 3.10 or higher
  • uv package manager (install with: curl -LsSf https://astral.sh/uv/install.sh | sh)

Installation

# 1. Navigate to project directory
cd lifi-mcp-python

# 2. Install dependencies
uv sync

# 3. Start Inspector (easiest way to test)
./run-inspector-fast.sh

Browser opens automatically with working MCP server! โœ…


๐Ÿ› ๏ธ Tool Categories

โœ… Read-Only Tools (NO Credentials Needed)

These 12 tools work immediately without any wallet or credentials:

ToolWhat It DoesPaginationExample Use Case
get_chainsLists all supported blockchainsโœ… Yes"Which chains does Li.FI support?"
get_tokensLists all available tokensโœ… Yes"What tokens can I swap?"
get_tokenGet specific token infoโŒ No"Tell me about USDC on Ethereum"
get_quoteGet swap/bridge quoteโŒ No"How much ETH will I get for 100 USDC?"
get_statusCheck transaction statusโŒ No"Is my bridge transaction complete?"
get_connectionsList chain connectionsโœ… Yes"Can I bridge from Ethereum to Polygon?"
get_tools_listList bridges and DEXsโœ… Yes"Which bridges are available?"
get_chain_by_idGet chain by IDโŒ No"What is chain ID 1?"
get_chain_by_nameGet chain by nameโŒ No"Tell me about Polygon"
get_native_token_balanceCheck ETH/MATIC/etc balanceโŒ No"What's Vitalik's ETH balance?"
get_token_balanceCheck ERC20 token balanceโŒ No"What's my USDC balance?"
get_allowanceCheck token spending approvalโŒ No"How much USDC can this contract spend?"

โœจ You can test all of these immediately!

๐Ÿ“„ Pagination Support: Tools marked with โœ… support pagination to handle large result sets efficiently.

๐Ÿ” Wallet Tools (Credentials REQUIRED)

These 5 tools require an Ethereum wallet keystore:

ToolWhat It DoesRisk Level
get_wallet_addressShows your wallet address๐ŸŸข Safe
execute_quoteExecutes a swap/bridge๐Ÿ”ด Spends funds
approve_tokenApprove token spending๐ŸŸก Moderate
transfer_tokenTransfer ERC20 tokens๐Ÿ”ด Spends funds
transfer_nativeTransfer ETH/MATIC/etc๐Ÿ”ด Spends funds

โš ๏ธ Warning: Wallet tools can spend your cryptocurrency. Always test on testnets first!


๐Ÿ“„ Using Pagination

Some tools return large amounts of data. These tools support pagination to make results more manageable:

Paginated Tools

  • get_chains - Lists 50+ blockchain chains
  • get_tokens - Can list thousands of tokens
  • get_connections - Can return hundreds of chain connections
  • get_tools_list - Lists all bridges and DEXs

Pagination Parameters

ParameterTypeDefaultRangeDescription
pageinteger11-โˆžPage number to retrieve
page_sizeinteger501-500Items per page

Example: Paginated get_chains

{
  "page": 1,
  "page_size": 10
}

Response:

{
  "chains": [
    { "id": 1, "name": "Ethereum", ... },
    { "id": 10, "name": "Optimism", ... },
    ...10 items total...
  ],
  "pagination": {
    "page": 1,
    "page_size": 10,
    "total_items": 57,
    "total_pages": 6,
    "has_next": true,
    "has_prev": false
  }
}

Example: Get Next Page

{
  "page": 2,
  "page_size": 10
}

Example: Larger Page Size

{
  "page": 1,
  "page_size": 100
}

Pagination Response Fields

FieldDescription
pageCurrent page number
page_sizeItems per page
total_itemsTotal number of items across all pages
total_pagesTotal number of pages available
has_nextBoolean indicating if more pages exist
has_prevBoolean indicating if previous pages exist

๐Ÿงช Testing Without Credentials (Read-Only Mode)

Step 1: Start Inspector

cd lifi-mcp-python
./run-inspector-fast.sh

What happens:

  • Terminal shows: โœ… Setup verified!
  • Browser opens automatically
  • Inspector shows: "Server: Connected"
  • Tools dropdown shows 12+ tools

Step 2: Test Your First Tool

In the browser Inspector:

  1. Select tool: get_chains
  2. Arguments: {}
  3. Click: "Call Tool"
  4. Result: JSON with 57+ blockchain chains โœ…

Step 3: More Test Examples

Example 1: Get Ethereum Chain Info
Tool: get_chain_by_name
Arguments: {
  "name": "ethereum"
}

Result:

{
  "id": 1,
  "name": "Ethereum",
  "key": "eth",
  "chainType": "EVM",
  "nativeToken": {
    "symbol": "ETH",
    "decimals": 18,
    "address": "0x0000000000000000000000000000000000000000"
  }
}
Example 2: Check Vitalik's ETH Balance
Tool: get_native_token_balance
Arguments: {
  "rpcUrl": "https://eth.llamarpc.com",
  "address": "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045"
}

Result:

{
  "address": "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045",
  "balance": "1234.56",
  "symbol": "ETH",
  "decimals": 18
}
Example 3: Get USDC Token Info
Tool: get_token
Arguments: {
  "chain": "1",
  "token": "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"
}

Result:

{
  "address": "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
  "symbol": "USDC",
  "decimals": 6,
  "name": "USD Coin",
  "chainId": 1,
  "logoURI": "https://..."
}
Example 4: Get Swap Quote (No Execution)
Tool: get_quote
Arguments: {
  "fromChain": "1",
  "toChain": "137",
  "fromToken": "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
  "toToken": "0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174",
  "fromAddress": "0xYourAddress",
  "fromAmount": "1000000"
}

Result: Complete quote with estimated output, fees, and transaction data (but doesn't execute)


๐Ÿ” Setting Up Wallet Tools (Requires Credentials)

What You Need

To use wallet tools, you need an Ethereum keystore file. This is an encrypted JSON file containing your private key.

Option 1: Create a Test Wallet (RECOMMENDED for Testing)

Step 1: Create Keystore with MetaMask
  1. Install MetaMask: https://metamask.io/
  2. Create new wallet or use existing
  3. Export private key:
    • MetaMask โ†’ Account Details โ†’ Export Private Key
    • Enter password
    • Copy private key (starts with 0x...)
Step 2: Convert to Keystore Format

Use Python to create encrypted keystore:

from eth_account import Account
import json
import getpass

# Your private key from MetaMask
private_key = "0x..." # Paste here

# Create account
account = Account.from_key(private_key)

# Get password for encryption
password = getpass.getpass("Enter password for keystore: ")

# Create keystore
keystore = account.encrypt(password)

# Save to file
keystore_path = f"~/.lifi-mcp/keystore/{account.address}.json"
import os
os.makedirs(os.path.dirname(os.path.expanduser(keystore_path)), exist_ok=True)

with open(os.path.expanduser(keystore_path), 'w') as f:
    json.dump(keystore, f)

print(f"โœ… Keystore saved to: {keystore_path}")
print(f"๐Ÿ“ Address: {account.address}")
Step 3: Fund Your Test Wallet

For Testing (Use Testnet!):

  1. Get Testnet ETH:

  2. Get Testnet Tokens:

    • Bridge testnet ETH to other chains
    • Use testnet DEXs to get tokens

โš ๏ธ NEVER USE MAINNET FOR TESTING! Always start with testnets.

Option 2: Use Existing Keystore

If you already have a keystore file (e.g., from Geth, MyEtherWallet):

  1. Copy keystore to standard location:

    mkdir -p ~/.lifi-mcp/keystore
    cp your-keystore.json ~/.lifi-mcp/keystore/
    
  2. Note the filename (e.g., UTC--2024-...--0xabcd1234)

Option 3: Hardware Wallet (Advanced)

Hardware wallets (Ledger, Trezor) are more secure but require additional setup. See for instructions.


๐Ÿ”‘ Using Wallet Tools

Method 1: Start Inspector with Keystore

cd lifi-mcp-python

# Replace with your keystore filename and password
npx @modelcontextprotocol/inspector \
  "$(pwd)/.venv/bin/python" \
  -m lifi_mcp_python.main_fastmcp \
  --keystore "UTC--2024-...--0xabcd1234.json" \
  --password "YourPassword"

What happens:

  • Server loads your wallet
  • All 17 tools are now available (12 read-only + 5 wallet)
  • Your address is loaded and ready

Method 2: Run Server Directly

cd lifi-mcp-python

# Start server with wallet
.venv/bin/python -m lifi_mcp_python.main_fastmcp \
  --keystore "UTC--2024-...--0xabcd1234.json" \
  --password "YourPassword"

Keystore Location

The server looks for keystores in:

~/.lifi-mcp/keystore/

Or you can provide the full path:

--keystore "/full/path/to/keystore.json"

๐Ÿงช Complete Testing Guide

Phase 1: Read-Only Testing (5 minutes)

No credentials needed!

# 1. Start Inspector
./run-inspector-fast.sh

# 2. Test these tools in order:
  1. get_chains โ†’ {}
  2. get_chain_by_name โ†’ {"name": "ethereum"}
  3. get_tokens โ†’ {"chains": "1"}
  4. get_native_token_balance โ†’ {"rpcUrl": "https://eth.llamarpc.com", "address": "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045"}

Phase 2: Quote Testing (10 minutes)

Still no credentials needed!

# Get a quote for swapping USDC on Ethereum to USDC on Polygon
Tool: get_quote
Arguments: {
  "fromChain": "1",
  "toChain": "137",
  "fromToken": "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
  "toToken": "0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174",
  "fromAddress": "0xYourAddress",
  "fromAmount": "1000000"
}

What you get:

  • Estimated output amount
  • Gas fees
  • Route (which bridges/DEXs used)
  • Transaction data (for execution)

Phase 3: Wallet Testing (WITH Credentials)

โš ๏ธ Use Testnet Only!

# 1. Create test wallet (see above)
# 2. Fund with testnet ETH
# 3. Start Inspector with keystore

npx @modelcontextprotocol/inspector \
  "$(pwd)/.venv/bin/python" \
  -m lifi_mcp_python.main_fastmcp \
  --keystore "your-keystore.json" \
  --password "YourPassword"

Test wallet tools:

  1. get_wallet_address โ†’ {}

    • Should show your address
  2. get_native_token_balance โ†’ {"rpcUrl": "https://rpc.sepolia.org", "address": "YOUR_ADDRESS"}

    • Check your testnet balance
  3. approve_token (if needed) โ†’ See examples below

  4. transfer_token โ†’ See examples below

Phase 4: Execute Swap (ADVANCED - Testnet Only)

# Step 1: Get quote
Tool: get_quote
Arguments: {...} # See Phase 2

# Step 2: From quote response, copy the "transactionRequest" object

# Step 3: Execute
Tool: execute_quote
Arguments: {
  "rpcUrl": "https://rpc.sepolia.org",
  "transactionRequest": {...} # Paste from quote
}

๐Ÿ“– Usage Examples

Example 1: Check Token Balance

No credentials needed!

Tool: get_token_balance
Arguments: {
  "rpcUrl": "https://eth.llamarpc.com",
  "tokenAddress": "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
  "walletAddress": "0xYourAddress"
}

Example 2: Check Token Allowance

No credentials needed!

Tool: get_allowance
Arguments: {
  "rpcUrl": "https://eth.llamarpc.com",
  "tokenAddress": "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
  "ownerAddress": "0xYourAddress",
  "spenderAddress": "0x1231DEB6f5749EF6cE6943a275A1D3E7486F4EaE"
}

Example 3: Approve Token (Requires Keystore)

Tool: approve_token
Arguments: {
  "rpcUrl": "https://rpc.sepolia.org",
  "tokenAddress": "0xTokenAddress",
  "spenderAddress": "0x1231DEB6f5749EF6cE6943a275A1D3E7486F4EaE",
  "amount": "1000000"
}

Example 4: Transfer Tokens (Requires Keystore)

Tool: transfer_token
Arguments: {
  "rpcUrl": "https://rpc.sepolia.org",
  "tokenAddress": "0xTokenAddress",
  "to": "0xRecipientAddress",
  "amount": "1000000"
}

Example 5: Transfer Native Token (Requires Keystore)

Tool: transfer_native
Arguments: {
  "rpcUrl": "https://rpc.sepolia.org",
  "to": "0xRecipientAddress",
  "amount": "1000000000000000"
}

๐Ÿ” Finding RPC URLs

Free Public RPCs

ChainRPC URL
Ethereum Mainnethttps://eth.llamarpc.com
Ethereum Sepolia (testnet)https://rpc.sepolia.org
Polygonhttps://polygon-rpc.com
Polygon Mumbai (testnet)https://rpc-mumbai.maticvigil.com
Arbitrumhttps://arb1.arbitrum.io/rpc
Optimismhttps://mainnet.optimism.io
Binance Smart Chainhttps://bsc-dataseed.binance.org

Dedicated RPC Services (Better Performance)

  1. Infura: https://infura.io/

    • Free tier: 100K requests/day
    • Sign up โ†’ Create project โ†’ Copy endpoint
  2. Alchemy: https://www.alchemy.com/

    • Free tier: 300M compute units/month
    • Sign up โ†’ Create app โ†’ Copy HTTPS endpoint
  3. Ankr: https://www.ankr.com/

    • Free tier available
    • No signup needed for public endpoints

๐Ÿงฐ Use in Claude Desktop

Configuration

Add to claude_desktop_config.json:

Read-Only Mode (No Wallet):

{
  "mcpServers": {
    "lifi": {
      "command": "/Users/jayeshkumarchowdary/Downloads/lifi-mcp-main/lifi-mcp-python/.venv/bin/python",
      "args": ["-m", "lifi_mcp_python.main_fastmcp"]
    }
  }
}

With Wallet (Testnet Only!):

{
  "mcpServers": {
    "lifi": {
      "command": "/Users/jayeshkumarchowdary/Downloads/lifi-mcp-main/lifi-mcp-python/.venv/bin/python",
      "args": [
        "-m",
        "lifi_mcp_python.main_fastmcp",
        "--keystore",
        "your-keystore.json",
        "--password",
        "YourPassword"
      ]
    }
  }
}

โš ๏ธ Security Note: Storing passwords in config files is NOT secure. Use environment variables or prompt-based authentication for production.


๐Ÿ› Troubleshooting

"Module not found"

cd lifi-mcp-python
uv sync

"No tools showing in Inspector"

  1. Refresh browser (F5)
  2. Wait 5 seconds
  3. Check terminal for errors
  4. Try: ./run-inspector-fast.sh again

"Keystore not found"

# Check keystore location
ls -la ~/.lifi-mcp/keystore/

# Or provide full path
--keystore "/full/path/to/keystore.json"

"Insufficient funds"

  • Check you have enough ETH for gas
  • Check token balance: Use get_token_balance tool
  • For testnets: Get more from faucets

"Transaction failed"

  • Check gas price (might be too low)
  • Check token allowance: Use get_allowance tool
  • Check RPC URL is correct
  • Try different RPC endpoint

๐Ÿ“š Additional Resources


๐Ÿ”’ Security Best Practices

DO โœ…

  • Test on testnets first
  • Use dedicated test wallets
  • Keep keystores secure
  • Never share private keys
  • Verify transaction details
  • Use hardware wallets for large amounts

DON'T โŒ

  • Use mainnet for testing
  • Store passwords in plaintext
  • Commit keystores to git
  • Share keystores with anyone
  • Skip transaction verification
  • Use production wallets for testing

๐Ÿ“‹ Configuration Files

This project includes two configuration files for MCP client integration:

lifi_mcp_config.json

MCP client configuration for launching and connecting to the server. Use this with MCP clients like Claude Desktop or Inspector.

{
  "mcpServers": {
    "lifi-mcp": {
      "command": "bash",
      "args": ["-c", "cd /path/to/lifi-mcp-python && .venv/bin/python -m lifi_mcp_python.main_fastmcp"],
      "type": "stdio"
    }
  }
}

lifi_mcp_metadata.json

Comprehensive metadata describing:

  • All 17 tools with detailed parameters
  • Supported blockchain networks (50+)
  • Security model and best practices
  • Installation and usage information
  • API provider details

See for detailed documentation about these configuration files.


๐Ÿ“– Additional Resources


๐Ÿ“ License

MIT License - See file for details.


๐Ÿ™‹ Getting Help

  • Quick Reference: See for a one-page guide
  • Configuration Files: See for integration details
  • Issues or Questions: Refer to the troubleshooting section above
  • Bugs or Feature Requests: Open an issue on GitHub

๐ŸŽ‰ Ready to start? Run ./run-inspector-fast.sh now!