OKX DEX MCP Server
Enables gasless token swaps across multiple chains using OKX DEX aggregation and Biconomy MEE, allowing users to execute swaps via natural language without needing native gas tokens.
README
OKX MCP SERVER
Revolutionary gasless DEX swapping powered by OKX DEX API + Biconomy MEE - Swap without holding ETH for gas fees!
š Note: Swapping occurs only for OKX supported networks and tokens.
š¦ Package Available on NPM
Live Package: https://www.npmjs.com/package/okx-mcp-server
Quick Setup for Claude Desktop:
{
"mcpServers": {
"okx-dex": {
"command": "npx",
"args": ["-y", "okx-mcp-server"],
"env": {
"PRIVATE_KEY": "0xxxx",
"OKX_API_KEY": "xxx",
"OKX_SECRET_KEY": "xxxA1",
"OKX_PASSPHRASE": "xxx"
}
}
}
}
šÆ What Problem Are We Solving?
The DeFi Gas Problem:
- ā Need ETH on every chain for gas fees
- ā Complex multi-step approval processes
- ā Failed transactions waste gas
- ā Cross-chain operations require multiple signatures
Our Solution:
ā
Gasless Swaps: Use your source tokens to pay for ALL transaction costs
ā
One-Click Multi-Chain: Single signature for complex cross-chain flows
ā
Natural Language: "Swap 10 USDC to WETH on Base" - that's it!
ā
MEE Orchestration: Smart execution across 50+ DEX sources
š Key Features
ā
Gasless Swaps: No ETH needed for gas fees
ā
Multi-Chain: Ethereum, Base, Optimism, xLayer
ā
Best Prices: OKX DEX aggregates 50+ DEX sources
ā
Natural Language: "Swap 10 USDC to WETH on Base"
ā
Real-time Quotes: Get current market prices
ā
Portfolio Management: Check balances across chains
š Hackathon Tracks
Smart Account UX & Abstraction (TRACK)
- Revolutionary Gas Abstraction: Use ANY token to pay gas on ANY chain - no ETH required
- Biconomy MEE Integration: Superior to ERC-4337 with true composability and cross-chain orchestration
- One-Signature Multi-Chain: Execute complex flows across Ethereum, Base, Optimism with single approval
- Natural Language Interface: "Swap 10 USDC to WETH on Base" via Claude Desktop
DeFi Innovation (TRACK)
- 50+ DEX Aggregation: OKX DEX routes across Uniswap, SushiSwap, 1inch for best prices
- Gasless Trading: Eliminates the #1 barrier to DeFi adoption
- Cross-Chain Liquidity: Access unified liquidity pools across all supported networks
- Professional Tools: Real-time quotes, slippage protection, transaction tracking
Autonomous Apps(TRACK)
- MEE Orchestration: Self-executing transaction flows with conditional logic
- Intelligent Routing: MEE optimizes gas costs and execution paths automatically
Key MEE Advantages Over ERC-4337:
| Feature | ERC-4337 | Biconomy MEE | Our Implementation |
|---|---|---|---|
| Cross-Chain | ā Single chain only | ā Native multi-chain | ā 4 chains, 1 signature |
| Dynamic Execution | ā Static batching | ā Conditional logic | ā Approve ā Swap ā Transfer |
| Universal Gas | ā Chain-specific | ā Any token, any chain | ā Pay with your swap token |
| True Composability | ā Limited | ā Runtime calculations | ā Dynamic amount handling |
Impact: 95% reduction in user steps, 100% elimination of native gas requirements, zero learning curve with natural language commands.
š¼ļø Gallery of the Project
Here are some screenshots and visuals from the project in action:
<p align="center"> <img src="./img/claude-mcp-success.png" alt="Claude MCP Success" width="600" /> <br><em>Claude MCP Success</em> </p>
<p align="center"> <img src="./img/mcp-liquidity-tool.png" alt="MCP Liquidity Tool" width="600" /> <br><em>MCP Liquidity Tool</em> </p>
<p align="center"> <img src="./img/mee-success-tnx.png" alt="MEE Success Transaction" width="600" /> <br><em>MEE Success Transaction</em> </p>
<p align="center"> <img src="./img/price-okx-fetch.png" alt="Price OKX Fetch" width="600" /> <br><em>Price OKX Fetch</em> </p>
šØ Superior User Experience
Before (Traditional DEX):
1. Check ETH balance for gas ā
2. Approve token spending ā³
3. Wait for confirmation ā³
4. Execute swap transaction ā³
5. Wait for confirmation ā³
6. Pay gas in native ETH ā
After (Our MEE Implementation):
1. "Swap 10 USDC to WETH on Base" ā
2. Single signature ā
3. MEE handles everything ā
4. Gas paid from USDC ā
5. Done! š
š MEE vs ERC-4337: Why We Chose Superior Technology
1. True Composability
| Feature | ERC-4337 | Biconomy MEE | Our Implementation |
|---|---|---|---|
| Dynamic Execution | ā Static batching only | ā Runtime conditional logic | ā Approval ā Swap ā Transfer in one flow |
| Cross-Transaction Data | ā Cannot use previous results | ā Each step uses prior outputs | ā Dynamic amount calculations |
| Conditional Logic | ā All steps must execute | ā Conditional execution paths | ā Smart slippage handling |
2. Cross-Chain Orchestration
| Feature | ERC-4337 | Biconomy MEE | Our Implementation |
|---|---|---|---|
| Multi-Chain Support | ā Single chain per transaction | ā Native cross-chain flows | ā Ethereum, Base, Optimism, xLayer |
| Unified Gas Payment | ā Separate gas per chain | ā Pay from any chain | ā Use USDC on Base to swap on Optimism |
| Atomic Operations | ā Multiple signatures needed | ā Single signature for all chains | ā One signature, multi-chain execution |
3. Universal Gas Abstraction
| Feature | ERC-4337 | Biconomy MEE | Our Implementation |
|---|---|---|---|
| Gas Token Flexibility | ā ļø Limited token support | ā Any token, any chain | ā Pay gas with your swap token |
| Cross-Chain Gas | ā Chain-specific gas management | ā Universal gas abstraction | ā USDC on any chain pays for everything |
| Gas Optimization | ā ļø Basic bundling | ā Intelligent routing | ā MEE optimizes across 50+ DEX sources |
4. Advanced Automation
| Feature | ERC-4337 | Biconomy MEE | Our Implementation |
|---|---|---|---|
| Scheduled Execution | ā No native scheduling | ā Built-in automation | š Coming: Limit orders via Gelato |
| Recurring Transactions | ā Manual repetition | ā Automated patterns | š Coming: DCA strategies |
| Conditional Triggers | ā No trigger support | ā Event-based execution | š Coming: Price-based swaps |
š Available MCP Tools
Once deployed, you'll have access to these tools in Claude:
get_supported_networks_okx- List supported networksget_supported_tokens_okx- Get tokens for a networkget_account_balance_evm- Check wallet balancesget_token_swap_quote_okx- Get swap quotes/pricesswap_tokens_okx_mee- Execute gasless token swaps (using Biconomy MEE)transfer_tokens_evm- Transfer tokensget_transaction_evm- Check transaction status
š How to Deploy This MCP Server
Prerequisites
- Node.js 18+ or Bun installed
- Claude Desktop app (for mcp test)
- OKX DEX API credentials
- Private key for wallet operations
Step 1: Clone and Setup
git clone https://github.com/Nith567/okx-dex-mcp.git
cd okx-dex-mcp
bun install
Step 2: Environment Configuration
Create a .env file in the project root:
# OKX DEX API Configuration
OKX_API_KEY=your_okx_api_key_here
OKX_SECRET_KEY=your_okx_secret_key_here
OKX_PASSPHRASE=your_okx_passphrase_here
# Wallet Configuration
PRIVATE_KEY=0x_your_private_key_here
Step 3: Build the Server
bun run build
Step 4: Test the Server (Optional)
# Test a token swap(checkout serveral test scripts out there )
bun run test:swap
# Start server locally
bun run start
Step 5: Find Your Bun Path
which bun
# Example output: /opt/homebrew/bin/bun
Step 6: Configure Claude Desktop
Edit your Claude Desktop config file:
macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
Windows: %APPDATA%\Claude\claude_desktop_config.json
{
"mcpServers": {
"okx-dex": {
"command": "/opt/homebrew/bin/bun",
"args": [
"run",
"/Users/your-username/path/to/okx-mcp/build/index.js"
],
"env": {
"OKX_API_KEY": "your_okx_api_key_here",
"OKX_SECRET_KEY": "your_okx_secret_key_here",
"OKX_PASSPHRASE": "your_okx_passphrase_here",
"PRIVATE_KEY": "0x_your_private_key_here"
}
}
}
}
Important:
- Replace
/opt/homebrew/bin/bunwith your actual bun path from Step 5 - Replace
/Users/your-username/path/to/okx-mcpwith your actual project path - Replace the environment variables with your actual credentials
Step 7: Restart Claude Desktop
Close and reopen Claude Desktop for the configuration to take effect.
Step 8: Test in Claude
Try this in Claude Desktop:
Can you check what tokens are supported on Optimism network?
or
Swap 10 USDC to USDT on optimism network
š§ Architecture & Implementation
Token Swap Process Flow
Step-by-Step Execution:
- Network Validation: Resolve network name to chain ID
- Token Discovery: Get supported tokens for the network via OKX API
- Token Validation: Ensure both source and destination tokens are supported
- Amount Calculation: Convert human-readable amount to token decimals
- Wallet Setup: Create EOA from private key and get wallet address
- Approval Transaction:
- Call OKX
/api/v5/dex/aggregator/approve-transaction - Decode transaction data to get DEX contract address and amount
- Call OKX
- Swap Transaction:
- Call OKX
/api/v5/dex/aggregator/swap - Decode transaction data to get function name and arguments
- Call OKX
- MEE Integration:
- Create multichain nexus account with supported chains
- Build approval composable transaction
- Build swap composable transaction
- Create trigger with source token details
- Execution:
- Get fusion quote from MEE client
- Execute the fusion quote
- Return transaction hash and MEE scan link
- Wait for transaction receipt
Supported Networks
- Ethereum: Chain ID 1
- Base: Chain ID 8453
- Optimism: Chain ID 10
- xLayer: Chain ID 196
Key Technical Features
- OKX API Integration: HMAC-SHA256 authentication for secure API calls
- Transaction Decoding: ERC20 and DEX router ABI for transaction parsing
- Biconomy MEE: Multichain nexus account with composable transactions
- Error Handling: Comprehensive validation and error management
- Type Safety: Full TypeScript implementation
šø Referral & Fee Revenue Support
This MCP server supports referral-based revenue generation by allowing you to specify a referrer wallet address and a small percentage fee on each swap. This is similar to how Phantom and other wallets have generated significant revenue by taking a small cut of each transaction.
How it works:
- When building the swap request to OKX DEX Aggregator, you can include the following parameters:
const params = {
chainIndex: chainId,
amount,
toTokenAddress,
fromTokenAddress,
slippage: SLIPPAGE,
userWalletAddress,
fromTokenReferrerWalletAddress: "0xYourReferralAddress", // Your address to receive referral fees
feePercent: "0.25" // Example: 0.35% fee for revenue
};
- The
fromTokenReferrerWalletAddressreceives the referral fee, andfeePercentsets the percentage (e.g.,0.25for 0.25%). - This enables you to earn a small profit on every swap routed through your MCP server.
- Many wallets (like Phantom) have made millions in revenue using this approach.
- We are expanding this by providing MCP as a service, so you can also benefit from referral fees.
Example Usage
// Example: Swap 0.4 USDC to USDT on Optimism
const result = await executeTokenSwap({
network: 'optimism',
amount: '0.4',
fromTokenSymbol: 'USDC',
toTokenSymbol: 'USDT'
});
// Returns:
{
success: true,
hash: "0x...",
explorerLink: "https://..",
meeScanLink: "https://...",
receipt: {...}
}
Required Environment Variables
PRIVATE_KEY=your_private_key_here
OKX_API_KEY=your_okx_api_key
OKX_SECRET_KEY=your_okx_secret_key
OKX_PASSPHRASE=your_okx_passphrase
šÆ Why This Project Matters
Innovation Impact:
- Solves Real Problems: Eliminates the #1 barrier to DeFi adoption (gas complexity)
- Technical Excellence: Leverages cutting-edge MEE technology over legacy ERC-4337
- User-Centric Design: Natural language interface removes technical barriers
- Cross-Chain Leadership: True multi-chain operations with single signature
Recommended Servers
playwright-mcp
A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.
Magic Component Platform (MCP)
An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.
Audiense Insights MCP Server
Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.
VeyraX MCP
Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.
graphlit-mcp-server
The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.
Kagi MCP Server
An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.
E2B
Using MCP to run code via e2b.
Neon Database
MCP server for interacting with Neon Management API and databases
Exa Search
A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.
Qdrant Server
This repository is an example of how to create a MCP server for Qdrant, a vector search engine.