Trade Mutex with an AI agent. This is a local MCP server: point your agent at it and it can preview, place, modify and cancel orders, and read positions, fills and market data.
It has two modes, chosen by the key you give it. A mtx_bot_…key drives one isolated bot sub-account and can never move money in or out; the bot's balance is the whole downside. A mtx_agent_… key acts as you on your main account and can withdraw, but only to wallets you linked. Start with bot mode. Reach for user mode only for an agent you already trust with your account.
| Key | Mode | The agent can | The agent cannot |
|---|---|---|---|
| mtx_bot_… | Bot mode | Trade ONE isolated bot sub-account: preview, place, modify, cancel; read positions, fills and market data. | Deposit, withdraw, swap, transfer, or touch anything outside that sub-account. |
| mtx_agent_… | User mode | Act as you: trade your main perp account, read balances, positions, orders and history, show your deposit address, and withdraw to your own linked wallets, signed by a key that lives only on your machine. | Withdraw anywhere else (the api and the signer both refuse), or add, remove or replace a linked wallet (no tool exists and the api refuses agent sessions). |
The server logs which mode it started in on stderr. Public market data (get_markets, get_candles) works in both.
In the web app, create a bot with the API template (no strategy params - the agent drives it), then fund it from the bot's detail page.
Start small. Mutex has no testnet, so every fill is real. An isolated bot with a small balance is the sanctioned safe way to try an agent: real slippage, bounded real downside. Fund only what you would accept losing to a bad prompt.
On the bot detail page, generate the trading key. It is shown once - copy it (mtx_bot_…). Full walk-through on the Trading API page.
The server runs via npx, so there is no install step. Add it to your agent's MCP config with the key in the environment.
Claude Desktop / Claude Code (claude_desktop_config.json or .mcp.json):
{
"mcpServers": {
"mutex": {
"command": "npx",
"args": ["-y", "@trade-mutex/mcp"],
"env": { "MUTEX_API_KEY": "mtx_bot_your_key_here" }
}
}
}| Env var | Purpose |
|---|---|
| MUTEX_API_KEY | Your mtx_bot_… (bot mode) or mtx_agent_… (user mode) key. Required for everything except public market data. |
| MUTEX_API_BASE | Override the base URL. Bot mode defaults to https://trade.mutex.exchange, user mode to https://api.mutex.exchange. The app prints the right line next to a new agent key. |
| MUTEX_SIGNER_KEY_FILE | User mode only: where the local signing key lives. Default ~/.config/mutex/agent-signer.json, created with mode 0600 on first run. |
Paste this into your agent's system prompt (or a MUTEX.md it reads). It teaches the agent to preview before ordering, size in coin units, respect the balance, and poll on a cadence. That is the difference between an AI-friendly tool and a plain REST wrapper. The same prompt covers user mode: the agent tells the modes apart by the tools it has.
You work on Mutex through the `mutex` MCP tools. The server runs in one of two
modes and you can tell which from the tools you have:
- **Bot mode** (you have `place_order`, `get_account`): you are driving **one
isolated bot sub-account**. You cannot deposit, withdraw, swap, or transfer.
The only money at stake is this bot's balance, and that balance is your hard
ceiling. Everything below applies.
- **User mode** (you have `mutex_withdraw`, `mutex_signer_address`,
`get_balances`): you act **as the user** on their own account. You trade
their **main perp account** with the same `preview_order` / `place_order` /
`modify_order` / `cancel_order` / `set_leverage` tools as bot mode, plus
`place_oco` and `cancel_all`; you can read balances, positions, orders and
trade history, show their deposit address, and withdraw **only to a wallet
they have already linked**. You can never add, remove or replace a linked
wallet. Everything below applies, with these differences: the bankroll is
the perp collateral `get_positions` reports (`available`), not a bot
balance; there is no `client_order_id`, so if an order call times out read
`get_orders` before retrying (it lists every status; `resting_only: true`
keeps the live ones); `mutex_withdraw` needs a `client_ref` that is unique per
withdrawal; the api treats a repeated one as a replay of the same withdrawal
(never a second payout), so if that call times out, retry with the SAME
`client_ref`, or read `get_withdrawals` and look for it; brackets are `{ trigger_price, price? }`
objects (a bare trigger price also works); errors come back as the api's
refusal copy under an `http_<status>` code rather than a stable code, so
read the message. Trading and withdrawing move the user's real money: state
what you are about to do and get the user's explicit yes before
`place_order`, `place_oco` or `mutex_withdraw`, unless they have told you
to act on your own. If the api or the signer refuses, repeat its message to
the user word for word; do not retry with another destination. If
`mutex_withdraw` says the signer is not authorized, give the user the
address from `mutex_signer_address` to paste into Settings > Agents.
**Before you trade**
- **Preview first.** Call `preview_order` before `place_order` unless you have a
specific reason not to. It returns the estimated fill, fee, and margin. Trading
without previewing is trading blind.
- **Sizes are in COIN units, never dollars.** `size: "0.01"` on BTC means 0.01
BTC. To spend a dollar budget, divide by price yourself (get it from
`get_markets` or a candle).
- **Respect the balance.** Call `get_account` (user mode: `get_positions`)
and size positions against `available`. Do not assume funds that are not there. The worst case is losing
this bot's balance, so treat it as the whole bankroll.
- **Respect the market's limits.** `get_markets` gives `min_size`,
`min_notional`, `size_decimals`, and `max_leverage`. Round to the decimals and
clear the minimums, or the venue rejects the order.
**When you place**
- `place_order` already echoes a fill/fee/cost **estimate** and the **resulting
position and open-order state**. Read that response. Do **not** call
`get_positions` or `get_orders` again just to confirm what you just did.
- Set a fresh `client_order_id` on each order (unique per bot). It is your
idempotency handle: if you are unsure whether a call landed, reuse the same id
and a duplicate is safely rejected rather than doubled.
- Attach `take_profit` and `stop_loss` trigger prices to an **entry** order to
fan out reduce-only exits automatically. On a not-yet-filled limit entry, place
the exits standalone after the fill instead.
**Cadence: do not burst**
- Poll market data on a cadence tied to the bar (once per candle `resolution`),
not between every thought. Reads are capped at 300/min and orders at 60/min per
key; sustained flooding auto-suspends the key.
- You almost never need to re-read right after acting, because the mutators hand
you the new state. Re-poll only when you are waiting on the market to move, not
to re-check your own action.
**When something is wrong**
- Errors carry a stable `code` and a plain-language recovery hint. Match on the
code, not the prose.
- `bot_not_trading` means the bot is not in a trading state, and NOT always
"paused": the message names the state and the control that clears it (a
`ready` bot has never been armed and needs Execute; only a `paused` one
resumes). Placement is blocked but cancels still work, so you can always
unwind. To fully stop the agent, the human pauses the bot in the Mutex web
app.
- On `rate_limited`, wait the `Retry-After` seconds. Do not tight-loop.
- On `order_rejected`, the message names the reason (size, notional, leverage).
Fix it and re-preview before retrying.User mode lets the agent act as you: it trades your own main perp account and has real access to your funding balance. Approval is "paste a key"; there is no device flow. What can and cannot happen is on the Agent access page.
{
"mcpServers": {
"mutex": {
"command": "npx",
"args": ["-y", "@trade-mutex/mcp"],
"env": {
"MUTEX_API_KEY": "mtx_agent_your_key_here",
"MUTEX_API_BASE": "https://api.mutex.exchange"
}
}
}
}What holds it in check, server-side, not by prompt:
The signing key is a file on the machine that runs the server. Treat it like an SSH key: back it up to keep the authorization across machines, delete it (and revoke the address) if the machine is lost.
With the server wired up and the system prompt in place, prompt your agent:
Check the BTC market and my account balance. If I have room, preview a small long of 0.001 BTC market, then place it with a stop-loss 3% below and a take-profit 5% above.
The agent calls get_markets and get_account (user mode: get_positions), then preview_order to quote the fill and fee, then place_order with inline stop_loss and take_profit. The place response echoes the estimate plus the resulting position and open orders, so it reports back without a single extra poll.
To stop it at any time, pause the botin the web app. A paused bot is reads-and-cancels-only, so the agent can still unwind but cannot open anything new. In user mode there is no bot to pause: revoke the agent key in Settings > Agents, and cancel_all keeps working while trading is halted platform-wide.
Bot mode (mtx_bot_…):
| Tool | Does |
|---|---|
| get_markets | List markets (or one) with fees and limits. |
| get_candles | OHLCV history. |
| get_account | Bot balance: equity, available, margin, uPnL. |
| get_positions | Open positions. |
| get_orders | List orders (or fetch one by id). |
| get_fills | Fill history. |
| preview_order | Pre-trade fill/fee/margin quote, no side effects. |
| place_order | Place an order; echoes estimate and resulting state. |
| modify_order | Reprice or resize a resting order; echoes state. |
| cancel_order | Cancel one or all; echoes state. |
| set_leverage | Set per-symbol leverage. |
User mode (mtx_agent_…). The trading tools take the same inputs as their bot-mode twins: symbol, coin-unit size, brackets as trigger prices. There is no client_order_id; if an order call times out, read get_orders before retrying. mutex_withdraw needs a client_ref unique per withdrawal; the api treats a repeated one as a replay, never a second payout, so on a timeout retry with the same one.
| Tool | Does |
|---|---|
| mutex_signer_address | The local signing key's address, to paste into Settings > Agents. Never the private key. |
| get_balances | Your ledger accounts; the perp row is a live venue read. |
| get_positions | Main perp account: collateral, available, positions. |
| get_orders | Orders, newest first, every status; resting_only keeps the live ones. |
| get_fills | Trade history, one row per closed position. |
| mutex_deposit_address | Your deposit address on Ethereum or Solana. |
| get_withdrawals | Withdrawal history with state and client_ref; the agent reads it before retrying a timed-out withdraw. |
| mutex_withdraw | Withdraw USDC (or swap to an asset) to one of your linked wallets, signed locally. |
| preview_order | Fees, margin and worst-case fill. Pure read. |
| place_order | Market, limit, stop or take-profit order on your main account, with inline brackets. |
| place_oco | Linked take-profit + stop-loss exit pair on a position. |
| modify_order | Reprice or resize a resting order. |
| cancel_order | Cancel one order. |
| cancel_all | Cancel every resting order, or one market's. |
| set_leverage | Per-market leverage, capped by the venue maximum. |
In user mode the bounds are different, and you should know them before you start: a hijacked agent trades your main perp account and can withdraw your funding balance, but only to a wallet youlinked, and it can never change which wallets those are. Revoke the agent key in Settings > Agents to stop it.