A [Model Context Protocol (MCP)] server for interacting with Hyperliquid DEX.
- Order Management: Place, modify, and cancel orders with support for both limit and market orders
- USD-Based Sizing: Specify order sizes in USD amounts for easier position sizing
- Leverage Control: Set and modify leverage for perpetual positions
- Account Analytics: Comprehensive P&L tracking, position monitoring, and balance queries
- Market Data: Access perpetual and spot market metadata
- Flexible Authentication: Separate accounts for trading operations and data queries
pip install -r requirements.txtgit clone https://github.com/PlayAINetwork/hyperliquid
cd hyperliquid_mcp
pip install -e .If you prefer to run the server directly:
{
"mcpServers": {
"hyperliquid": {
"command": "uvx",
"args": ["hyperliquid_server"],
"env": {
"HYPERLIQUID_MAIN_ACCOUNT_ADDRESS": "",
"HYPERLIQUID_API_ACCOUNT_ADDRESS": "",
"HYPERLIQUID_API_ACCOUNT_PRIVATE_KEY": ""
}
}
}
}placeOrder: Place limit or market orders with USD-based sizing supportmodifyOrder: Modify existing orderscancelOrder: Cancel orders by ID or client order ID
getAccountState: Get comprehensive account information including P&L, positions, and balancesgetUserTradeHistory: Retrieve trade history and fill datagetUserSpotBalances: Query spot token balances
getPerpetualsMeta: Get metadata for all perpetual marketsgetSpotMeta: Get metadata for all spot markets and tokens
# Buy $100 worth of ETH at market price
await placeOrder(
coin="ETH",
is_buy=True,
usd_amount=100.0,
order_type="market"
)# Place a limit buy order with 10x leverage
await placeOrder(
coin="BTC",
is_buy=True,
size=0.1,
price=45000.0,
order_type="limit",
leverage=10,
is_cross=False
)# Get comprehensive account information
account_info = await getAccountState()
print(f"Total PnL: ${account_info['pnl_overview']['total_pnl']}")
print(f"Account Value: ${account_info['pnl_overview']['account_value']}")This MCP server uses a dual-account architecture for enhanced security:
- Main Account: Your primary trading account that holds funds. Used only for read-only operations.
- API Account: A separate account used exclusively for signing transactions. Should have minimal or no funds.
This separation means:
- Your main trading funds are never directly exposed
- The API account can be easily rotated if compromised
- You can grant specific permissions to the API account via Hyperliquid's interface
| Variable | Description | Required |
|---|---|---|
HYPERLIQUID_MAIN_ACCOUNT_ADDRESS |
Your main trading account address | Yes |
HYPERLIQUID_API_ACCOUNT_ADDRESS |
API account address for signing | Yes |
HYPERLIQUID_API_ACCOUNT_PRIVATE_KEY |
Private key for API account | Yes |
HYPERLIQUID_BASE_URL |
Hyperliquid API endpoint | No (defaults to mainnet) |
git clone https://github.com/yourusername/hyperliquid-mcp
cd hyperliquid-mcp
pip install -e ".[dev]"- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
- Issues: GitHub Issues
- Documentation: README