Package Exports
- defi-trading-mcp
- defi-trading-mcp/src/index.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (defi-trading-mcp) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
DeFi Trading Agent MCP Server
Transform your AI assistant into an autonomous crypto trading agent with real-time market analysis, portfolio management, and seamless trade execution across 17+ blockchains.
🤖 Trading Agent Capabilities
Autonomous Portfolio Management
- Multi-chain Portfolio Analysis: Track balances, prices, and performance across Ethereum, Base, Polygon, Arbitrum, and 14+ other chains
- Real-time Portfolio Monitoring: Get instant updates on your holdings with metadata and price data
- Transaction History Tracking: Complete transaction analysis across all supported networks
Intelligent Market Analysis
- Market Data Intelligence: Access real-time token prices, trending pools, and DeFi market conditions
- Liquidity Analysis: Identify the best trading opportunities across multiple DEXes
- Token Research: Get detailed token information, social links, and market metrics
Advanced Trade Execution
- Smart Price Discovery: Uses advanced aggregation to find the best prices across all major DEXes
- Gasless Trading: Execute trades without holding ETH for gas fees using meta-transactions
- Multi-chain Swaps: Trade seamlessly across 17+ supported blockchains
- Slippage Protection: Built-in protection against unfavorable price movements
Risk Management & Security
- Balance Verification: Automatic balance checks before trade execution
- Transaction Simulation: Preview trades before execution
- Secure Key Management: Private keys never leave your local environment
🚀 Quick Start
Instant Setup
npx defi-trading-mcp
Global Installation
npm install -g defi-trading-mcp
defi-trading-mcp
Get Configuration
npx defi-trading-mcp --setup
⚙️ Configuration
Required API Keys
USER_PRIVATE_KEY
: Your Ethereum private key (stays local, never transmitted)USER_ADDRESS
: Your Ethereum wallet addressCOINGECKO_API_KEY
: CoinGecko API key for market dataALCHEMY_API_KEY
: Alchemy API key for portfolio tracking and premium RPCs
Optional Configuration
AGGREGATOR_SERVER_URL
: Custom aggregator server URL
🔧 Premium RPC Integration
Your ALCHEMY_API_KEY
automatically enables premium RPCs for:
- 9 Major Chains: Ethereum, Base, Polygon, Arbitrum, Optimism, BSC, Avalanche, Worldchain, Blast
- Enhanced Performance: Higher rate limits, lower latency, better uptime
- Automatic Fallback: Public RPCs for other chains
🔒 Security
- Private keys remain on your device
- No sensitive data transmitted to external servers
- Secure transaction signing locally
🎯 Trading Agent Examples
Portfolio Rebalancing Agent
"Check my portfolio across all chains and rebalance if ETH allocation exceeds 60%"
Agent Actions:
- Analyzes multi-chain portfolio
- Calculates current allocations
- Executes rebalancing swaps if needed
- Reports final allocation
Memecoin Opportunity Scanner
"Scan for newly launched memecoins on Base with >$100K liquidity and analyze the best entry opportunities"
Advanced Analysis Process:
- Discovery Phase: Uses
get_new_pools
to find tokens launched in last 24h - Volume Filtering: Identifies pools with >$100K liquidity and high trading activity
- Technical Analysis: Pulls OHLCV data to analyze price patterns and momentum
- Risk Assessment: Evaluates liquidity depth, holder concentration, and volatility
- Entry Strategy: Determines optimal entry price, position size, and risk management
- Execution: Places gasless swap with calculated slippage and stop-loss levels
Example AI Analysis:
"Found 3 promising new tokens:
🚀 $ROCKET (0x123...): 2M volume, bullish OHLCV pattern, 85% liquidity locked
📈 Entry: $0.0001 (current support level)
💰 Size: 2% portfolio allocation
🛡️ Stop: $0.000085 (-15%)
🎯 Target: $0.00015 (+50%)
Executing gasless swap now..."
Risk Management Agent
"Monitor my portfolio and alert me if any position drops more than 15%"
Agent Actions:
- Continuously monitors portfolio values
- Calculates position changes
- Provides alerts and recommendations
- Can execute protective trades
🔧 MCP Client Setup
Kiro IDE
Add to ~/.kiro/settings/mcp.json
:
{
"mcpServers": {
"0x-api": {
"command": "npx",
"args": ["defi-trading-mcp"],
"env": {
"USER_PRIVATE_KEY": "your_private_key_here",
"USER_ADDRESS": "0xYourWalletAddress",
"COINGECKO_API_KEY": "CG-your_coingecko_api_key",
"ALCHEMY_API_KEY": "your_alchemy_api_key",
"AGGREGATOR_SERVER_URL": "http://localhost:3000"
}
}
}
}
Claude Desktop
Add to your Claude Desktop configuration:
{
"mcpServers": {
"0x-api": {
"command": "npx",
"args": ["defi-trading-mcp"],
"env": {
"USER_PRIVATE_KEY": "your_private_key_here",
"USER_ADDRESS": "0xYourWalletAddress",
"COINGECKO_API_KEY": "CG-your_coingecko_api_key",
"ALCHEMY_API_KEY": "your_alchemy_api_key",
"AGGREGATOR_SERVER_URL": "http://localhost:3000"
}
}
}
}
Other MCP Clients
For other MCP clients, use the same pattern with environment variables:
{
"command": "npx",
"args": ["defi-trading-mcp"],
"env": {
"USER_PRIVATE_KEY": "your_private_key_here",
"USER_ADDRESS": "0xYourWalletAddress",
"COINGECKO_API_KEY": "CG-your_coingecko_api_key",
"ALCHEMY_API_KEY": "your_alchemy_api_key"
}
}
🛠️ Trading Agent Tools
Portfolio Management
get_portfolio_tokens
- Multi-chain portfolio analysis with prices and metadataget_portfolio_balances
- Fast balance checking across all chainsget_portfolio_transactions
- Complete transaction history analysis
Market Intelligence & Analysis
get_trending_pools
- Identify hot trading opportunities with volume metricsget_new_pools
- Discover newly launched tokens and liquidity poolsget_pool_ohlcv
- Technical analysis with OHLCV candlestick dataget_pool_trades
- Analyze recent trading activity and whale movementsget_token_price
- Real-time pricing with 24h change indicatorsget_token_data
- Deep token research with metadata and social linksget_token_info
- Comprehensive token analysis including descriptionssearch_pools
- Find specific pools by token symbol or contract address
Smart Trading
get_swap_price
- Get best prices across all DEXesget_swap_quote
- Get executable quotes with transaction dataexecute_swap
- Execute trades with optimal routingget_supported_chains
- List all 17+ supported blockchains
Gasless Trading
get_gasless_price
- Get prices for gas-free tradesget_gasless_quote
- Get gasless swap quotessubmit_gasless_swap
- Execute trades without holding ETHget_gasless_status
- Monitor gasless transaction status
Utility Tools
convert_wei_to_formatted
- Convert blockchain units to human-readableconvert_formatted_to_wei
- Convert amounts to blockchain format
Plus 25+ additional tools for comprehensive DeFi trading and analysis.
🌐 Supported Networks
17+ Blockchain Networks:
- Ethereum - The original DeFi ecosystem
- Base - Coinbase's L2 with low fees
- Polygon - Fast and cheap transactions
- Arbitrum - Leading Ethereum L2
- Optimism - Optimistic rollup scaling
- BSC - Binance Smart Chain
- Avalanche - High-performance blockchain
- Blast - Native yield for ETH and stablecoins
- Linea - ConsenSys zkEVM
- Scroll - zkRollup technology
- Mantle - Modular blockchain network
- Mode - DeFi-focused L2
- Worldchain - World ID integration
- Unichain - Uniswap's dedicated chain
- Berachain - Proof-of-liquidity consensus
- Ink - Kraken's L2 solution
- MonadTestnet - Next-gen parallel EVM
Use get_supported_chains
for the complete current list.
🔐 Security & Trust
Local Key Management
- Private keys never leave your device
- All transaction signing happens locally
- No sensitive data transmitted to servers
Secure Infrastructure
- HTTPS encryption for all API calls
- Rate limiting prevents abuse
- Secure aggregator routing for best prices
- Multi-layer validation before execution
Transparent Operations
- Open source codebase
- Auditable transaction flows
- Real-time transaction monitoring
- Complete operation logging
💡 Agent Use Cases
DeFi Portfolio Manager
"Analyze my DeFi portfolio and suggest optimizations"
- Tracks performance across all chains
- Identifies underperforming assets
- Suggests rebalancing strategies
- Executes optimization trades
Technical Analysis Expert
"Analyze the OHLCV data for trending tokens and identify the best entry points"
Advanced Technical Analysis:
- Pattern Recognition: Identifies bullish/bearish patterns in OHLCV data
- Support/Resistance: Calculates key price levels using historical data
- Volume Analysis: Analyzes trading volume for momentum confirmation
- Entry Timing: Determines optimal entry points based on technical indicators
- Risk Management: Sets stop-loss and take-profit levels automatically
- Position Sizing: Calculates optimal allocation based on volatility and risk tolerance
Example Technical Analysis:
"$TOKEN shows strong bullish momentum:
📊 OHLCV Analysis: Higher lows pattern, volume increasing 300%
📈 Support Level: $0.00085 (tested 3x, held strong)
📉 Resistance: $0.0012 (previous high, light volume)
💡 Strategy: Enter at $0.00095, Stop at $0.00082, Target $0.0015
⚖️ Risk/Reward: 1:4 ratio, recommended 1.5% portfolio allocation"
Arbitrage Hunter
"Look for arbitrage opportunities between chains"
- Compares prices across networks
- Identifies profitable spreads
- Calculates gas costs and slippage
- Executes profitable arbitrage
Risk Monitor
"Alert me if any of my positions drop more than 10%"
- Continuous portfolio monitoring
- Real-time price alerts
- Automatic stop-loss execution
- Risk assessment reports
Advanced Market Analysis Agent
"Analyze newly launched memecoins on Base with high volume and determine entry strategy"
Comprehensive Analysis:
- Trend Detection: Identifies trending pools with unusual volume spikes
- Technical Analysis: Uses OHLCV data to analyze price patterns and momentum
- Liquidity Assessment: Evaluates pool depth and trading sustainability
- Risk Scoring: Calculates risk metrics based on volatility and liquidity
- Entry Optimization: Determines optimal entry points using technical indicators
- Position Sizing: Recommends allocation based on portfolio risk management
Example Analysis Flow:
- Discovery: "Find new tokens with >1000% volume increase in last 24h"
- Research: Pulls token metadata, social links, and trading history
- Technical Analysis: Analyzes OHLCV patterns for support/resistance levels
- Risk Assessment: Evaluates liquidity, holder distribution, and volatility
- Strategy: "Enter 2% of portfolio at $0.0001 with stop-loss at $0.00008"
- Execution: Places gasless swap with optimal slippage settings
🚀 Why Choose DeFi Trading Agent MCP?
For Traders
- AI-Powered Analysis: Advanced market intelligence with OHLCV technical analysis
- Memecoin Discovery: Automated scanning for newly launched high-potential tokens
- Smart Entry Timing: AI determines optimal entry points using multiple indicators
- Risk-Managed Trading: Automated position sizing and stop-loss calculations
- Multi-chain Efficiency: Trade across 17+ networks seamlessly
- Gas Optimization: Gasless trades save on transaction costs
- Professional Grade: Built for high-volume trading
📄 License
MIT License - Build the future of autonomous trading
🤝 Contributing
Join the revolution in AI-powered DeFi trading. Contributions welcome!
Transform your AI into an autonomous crypto trading agent today.