@michaleffffff/mcp-trading-server
v3.1.2
Published
A production-ready MCP (Model Context Protocol) server for deep integration with **MYX Finance**—a decentralized perpetual exchange. It allows AI assistants to autonomously trade, manage liquidity, and analyze markets via terminal/backend using pure on-ch
Readme
MYX MCP Trading Server
A production-ready MCP (Model Context Protocol) server for deep integration with MYX Finance—a decentralized perpetual exchange. It allows AI assistants to autonomously trade, manage liquidity, and analyze markets via terminal/backend using pure on-chain logic.
Release Notes
- Current release: 3.1.0
- SDK baseline:
@myx-trade/sdk@^1.0.4compatibility completed. - Refinement: Consolidated 40+ specialized tools into ~26 high-level unified tools.
- Improved UX: Enhanced AI parameter parsing, automated unit conversion, and structured error reporting.
- Safety refresh: Docs and prompt guidance now reflect explicit-price execution for
open_position_simple, exact-approval defaults, notional-based fee checks, TP/SL semantic validation, and LP preview fail-close behavior. - Regression status: Current trade/account compatibility was verified against the
1.0.4baseline, including testnet live checks forget_trade_flow,get_base_detail,account_deposit,account_withdraw,cancel_orders,manage_tp_sl, andclose_position. - Breaking changes: Many low-level tools (e.g.,
get_market_price,get_oracle_price,get_open_orders) have been merged into unified counterparts.
Features
- Unified Toolset: High-level semantic tools for simpler AI steering.
- AI-First Design: Automated Pool ID resolution and flexible unit handling (
human:vsraw:). - Deep Liquidity Support: Tools for both traders and liquidity providers.
- Production Ready: Robust error handling with actionable hints for LLMs.
- Precision-Aware Reads: Pool and LP read tools expose human-readable formatted values alongside raw on-chain integers.
- Compliant: Full Model Context Protocol (MCP) support.
Configuration
Copy .env.example to .env and configure your trading wallet:
PRIVATE_KEY=0x...
RPC_URL=https://your-testnet-or-mainnet-rpc
CHAIN_ID=...
BROKER_ADDRESS=0x...
QUOTE_TOKEN_ADDRESS=0x...
QUOTE_TOKEN_DECIMALS=...Testnet MYXBroker Reference
- Arbitrum test:
0x895C4ae2A22bB26851011d733A9355f663a1F939 - Linea test:
0x634EfDC9dC76D7AbF6E49279875a31B02E9891e2
Use the broker that matches your active RPC and chain configuration.
Core Tools Reference
📈 Market Analysis
find_pool: Discover active markets by keyword/symbol (e.g., "BTC", "ETH").list_pools: List all tradable assets on the current chain.search_tools: Discover the right MCP tool by keyword, legacy tool name, or intent phrase.get_price: Fetch real-time prices (Impact Market Price or Oracle Price).get_pool_metadata: Comprehensive metrics (Fees, Open Interest, Liquidity Depth via fresh Oracle price).get_kline: Fetch candlestick data for technical analysis.
⚔️ Trading Operations
open_position_simple: The recommended entry point for new trades. Handles size/price/fee computation. Supports Stop-Loss/Take-Profit.execute_trade: Low-level trade execution (Increase orders).close_position: Strategy-based closing of specific positions.close_all_positions: Emergency exit for all positions in a specific pool.cancel_orders: Unified cancellation (Single ID, Pool-wide, or Account-wide).manage_tp_sl: Adjust protection orders for active positions or pending orders. Deletion is supported viatpPrice=0+slPrice=0.adjust_margin: Add or remove collateral to manage liquidation risk.
📁 Account & Portfolio
get_account_snapshot: Unified overview of balances, trading metrics, and VIP tier.get_orders: Historical and active order ledger.get_positions_all: Currently open and recently closed positions.get_trade_flow: Granular transaction history.check_account_ready: Pre-trade balance validator aligned with SDKavailableMarginBalancesemantics.
Quick Start Flow
- Find Target:
find_pool(keyword="BTC") - Check State:
get_account_snapshot(poolId="...") - Execute:
open_position_simple(poolId="...", direction="LONG", leverage=5, collateralAmount="100", price="2500") - Monitor:
get_positions_all(status="OPEN")
Safety Defaults
- Explicit execution price:
open_position_simpleno longer auto-fills a fresh Oracle price forMARKETorders; providepriceexplicitly when opening a position. - SDK-delegated funding delta: MCP no longer performs its own increase-order margin/deposit reconciliation. New increase orders delegate collateral shortfall handling to SDK
createIncreaseOrder. - Exact approvals by default: local fallback flows now prefer exact approvals instead of implicit unlimited approval.
- Size semantics:
sizealways means base-asset quantity, not USD notional. - Pre-check semantics:
check_account_readynow uses SDKgetAvailableMarginBalance. When that read fails, the response markssummary.degraded=trueand includes diagnostics instead of silently trusting stalefreeMargin. - Direction validation: when a tool operates on an existing
positionId, the supplieddirectionmust match the live position. - TP/SL semantics: LONG requires
tpPrice > entryPriceandslPrice < entryPrice; SHORT uses the inverse. - LP safety: LP preview failures are fail-close and no longer downgrade to
minAmountOut=0. - LP slippage input:
manage_liquidity.slippagenow matches SDK semantics and must be a ratio in(0, 1]; MCP still does not impose its old 5% business cap. - LP metadata safety:
get_pool_metadata(includeLiquidity=true)now ignores caller-suppliedmarketPriceand derives liquidity depth from a fresh Oracle price only. - LP holdings semantics:
get_my_lp_holdingsis an inventory view; returned rows are no longer ranked by mixed BASE/QUOTE LP raw balances. - LP token-source safety:
get_my_lp_holdingsnow falls back to livepoolInfo.basePool.poolToken/poolInfo.quotePool.poolTokenwhen market-detail token addresses are stale or mismatched. - LP approval fallback: when SDK LP deposit paths fail on non-standard
allowance()reads, MCP falls back to direct router approval/execution instead of stopping at the SDK error.
Tool Discovery
When a client or LLM is unsure which tool to call:
- Use
search_tools(keyword="open order")orsearch_tools(keyword="get_market_price") - Read the returned
aliases,category, andcommonArgs - Confirm market context with
find_pool - Call the recommended high-level tool instead of a removed legacy tool
Examples:
{ "name": "search_tools", "arguments": { "keyword": "get_open_orders" } }{ "name": "search_tools", "arguments": { "keyword": "add base lp" } }Parameter Format Guide
Use these conventions when generating tool arguments:
poolId: Prefer a real hex pool id fromfind_poolorlist_poolskeyword: Use a market symbol like"BTC","ETH","ARB"direction:LONG/SHORTare canonical; lowercase and aliases likebuy/sellare toleratedstatus:OPEN/HISTORY/ALLare canonical; lowercase is toleratedpoolType:BASE/QUOTEare canonical; lowercase is toleratedorderType:MARKET/LIMIT/STOP/CONDITIONAL- Trading MCP tools now fix
timeInForceinternally toIOC (0); do not pass this field size: base token quantity, not USD notional; expected order value is usuallycollateralAmount * leverageopen_position_simple: ifsize + price + leverageare provided, MCP can auto-computecollateralAmount; ifcollateralAmountis also provided, MCP validates it against the requested notionalexecutionFeeToken: must be a real token address; zero address is rejected. Use the poolquoteTokenslippagePct: trading tools use 4-decimal raw units where100 = 1.00%and50 = 0.50%- Human units:
"100"means 100 USDC or 100 token units depending on field - Raw units:
"raw:1000000"means exact on-chain integer units
Examples:
{
"name": "get_orders",
"arguments": { "status": "OPEN", "limit": 20 }
}{
"name": "manage_liquidity",
"arguments": {
"poolId": "0x...",
"poolType": "BASE",
"action": "deposit",
"amount": 1000,
"slippage": 0.01
}
}For get_pool_metadata(includeLiquidity=true), do not rely on a custom marketPrice override. MCP now ignores that field and uses a fresh Oracle price automatically.
{
"name": "open_position_simple",
"arguments": {
"keyword": "ARB",
"direction": "LONG",
"collateralAmount": "100",
"leverage": 5,
"orderType": "MARKET",
"price": "2.5"
}
}Legacy Mapping
Common old-to-new tool mappings:
get_market_price/get_oracle_price->get_priceget_market_detail/get_pool_info/get_liquidity_info/get_pool_level_config->get_pool_metadataget_pool_list/get_pool_symbol_all->list_poolssearch_market/get_pool_by_symbol->find_poolget_open_orders/get_order_history->get_ordersget_positions/get_position_history->get_positions_allcancel_order/cancel_all_orders->cancel_ordersset_tp_sl/update_order_tp_sl->manage_tp_slget_account/get_account_info/get_balances/get_margin_balance->get_account_snapshot
Documentation
For detailed implementation examples and parameter guides, see:
- TOOL_EXAMPLES.md: Payload examples for every tool.
- CHANGELOG.md: Version history and migration paths.
- mcp_config_guide.md: Client setup instructions.
