@michaleffffff/mcp-trading-server 2.9.9 → 3.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +32 -0
- package/README.md +107 -8
- package/TOOL_EXAMPLES.md +593 -0
- package/dist/prompts/tradingGuide.js +10 -4
- package/dist/server.js +206 -15
- package/dist/services/marketService.js +101 -21
- package/dist/services/poolService.js +76 -2
- package/dist/services/tradeService.js +116 -11
- package/dist/tools/accountInfo.js +119 -49
- package/dist/tools/adjustMargin.js +1 -1
- package/dist/tools/cancelAllOrders.js +35 -3
- package/dist/tools/index.js +1 -2
- package/dist/tools/manageLiquidity.js +6 -2
- package/dist/tools/marketInfo.js +5 -4
- package/dist/tools/searchMarket.js +3 -3
- package/dist/tools/updateOrderTpSl.js +11 -9
- package/dist/utils/errorMessage.js +69 -0
- package/package.json +5 -2
- package/dist/tools/getBalances.js +0 -17
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 3.0.1 - 2026-03-17
|
|
4
|
+
|
|
5
|
+
### Added
|
|
6
|
+
- `extractErrorMessage` utility for cleaner error reporting across all tools.
|
|
7
|
+
|
|
8
|
+
### Changed
|
|
9
|
+
- `manage_liquidity` now performs strict SDK code validation before finalizing transactions.
|
|
10
|
+
- `cancel_all_orders` improved to handle comma-separated and JSON-array strings for `orderIds`.
|
|
11
|
+
- Integrated meaningful error extraction into `marketInfo`, `manageLiquidity`, and `updateOrderTpSl`.
|
|
12
|
+
|
|
13
|
+
## 3.0.0 - 2026-03-17
|
|
14
|
+
|
|
15
|
+
### Breaking Changes
|
|
16
|
+
- Removed legacy account balance tools:
|
|
17
|
+
- `get_account_info`
|
|
18
|
+
- `get_balances`
|
|
19
|
+
- `get_margin_balance`
|
|
20
|
+
- Added unified replacement:
|
|
21
|
+
- `get_account`
|
|
22
|
+
|
|
23
|
+
### Added
|
|
24
|
+
- `TOOL_EXAMPLES.md` handbook with practical examples for all exposed tools.
|
|
25
|
+
- Standardized AI-friendly error envelope with `status/error/code/hint/action`.
|
|
26
|
+
|
|
27
|
+
### Changed
|
|
28
|
+
- Updated prompts and README to use `get_account` and the new examples handbook.
|
|
29
|
+
- Improved `search_market` behavior for empty keyword usage.
|
|
30
|
+
- Read-only tool responses now surface non-zero SDK `code` as structured MCP errors.
|
|
31
|
+
- `get_account` now supports partial snapshots (`meta.partial=true`) when one section fails.
|
|
32
|
+
- Regression suite now validates `get_account` and handles optional `cancel_all_orders` mutation path safely.
|
package/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# MYX MCP Trading Server
|
|
1
|
+
# MYX MCP Trading Server
|
|
2
2
|
|
|
3
3
|
A production-ready MCP (Model Context Protocol) server that exposes tools, resources, and prompts for AI agents.
|
|
4
4
|
|
|
@@ -6,6 +6,15 @@ This server allows AI assistants (like Claude Desktop, Cursor, etc.) to securely
|
|
|
6
6
|
|
|
7
7
|
---
|
|
8
8
|
|
|
9
|
+
# Release Notes
|
|
10
|
+
|
|
11
|
+
- Current release: **3.0.0**
|
|
12
|
+
- Breaking change: `get_account_info`, `get_balances`, and `get_margin_balance` were removed.
|
|
13
|
+
- Replacement: use `get_account` for unified wallet + trading-account balance view.
|
|
14
|
+
- Detailed history: `CHANGELOG.md`
|
|
15
|
+
|
|
16
|
+
---
|
|
17
|
+
|
|
9
18
|
# Features
|
|
10
19
|
|
|
11
20
|
* MCP compliant server
|
|
@@ -115,7 +124,8 @@ The server will run using `stdio` transport and can be connected by any MCP-comp
|
|
|
115
124
|
2. **Configure env**: Copy `.env.example` to `.env` and fill in `PRIVATE_KEY`, `RPC_URL`, etc.
|
|
116
125
|
3. **Start the server**: Run `npm run build` then `npm run start` (use `npm run dev` for development).
|
|
117
126
|
4. **Configure your MCP client**: Set `command/args/env` in your MCP client (see Claude Desktop example below).
|
|
118
|
-
5. **Common flow**: Use `search_market` to get `poolId`, then optionally `get_market_price` / `get_oracle_price` to view prices, and finally use `open_position_simple` (recommended) to open a position.
|
|
127
|
+
5. **Common flow**: Use `search_market` (or `get_market_list`) to get `poolId`, then optionally `get_market_price` / `get_oracle_price` to view prices, and finally use `open_position_simple` (recommended) to open a position.
|
|
128
|
+
6. **Tool examples**: See `TOOL_EXAMPLES.md` for practical examples for every tool, common workflows, and parameter-unit guidance.
|
|
119
129
|
|
|
120
130
|
**Minimal open position example:**
|
|
121
131
|
|
|
@@ -151,6 +161,58 @@ The server will run using `stdio` transport and can be connected by any MCP-comp
|
|
|
151
161
|
- **Price**: `"price"` is human by default and will be converted to **30-decimal** format internally. Use `raw:` to pass a 30-decimal integer directly.
|
|
152
162
|
- **Slippage**: `slippagePct` uses 4-decimal raw units: `100` = `1%`, `50` = `0.5%`, `1000` = `10%`.
|
|
153
163
|
- **Note**: Some account-transfer tools (e.g. `account_deposit`, `account_withdraw`, `check_approval`) use **raw integer strings**.
|
|
164
|
+
- **`adjust_margin` units**: human amount is supported (e.g. `"1"` means 1 quote token). For exact atomic amount, use `raw:` (e.g. `"raw:1"`).
|
|
165
|
+
|
|
166
|
+
## P0 Reliability Contract (AI-friendly)
|
|
167
|
+
|
|
168
|
+
Starting with P0, tool failures are normalized to a structured JSON envelope:
|
|
169
|
+
|
|
170
|
+
```json
|
|
171
|
+
{
|
|
172
|
+
"status": "error",
|
|
173
|
+
"error": {
|
|
174
|
+
"tool": "execute_trade",
|
|
175
|
+
"code": "INVALID_PARAM",
|
|
176
|
+
"message": "Invalid arguments for tool \"execute_trade\".",
|
|
177
|
+
"hint": "Fix \"positionId\": positionId must be empty string for new position, or a bytes32 hex string.",
|
|
178
|
+
"action": "Call list_tools and resend valid arguments.",
|
|
179
|
+
"details": {
|
|
180
|
+
"issues": [
|
|
181
|
+
{
|
|
182
|
+
"field": "positionId",
|
|
183
|
+
"code": "custom",
|
|
184
|
+
"message": "positionId must be empty string for new position, or a bytes32 hex string."
|
|
185
|
+
}
|
|
186
|
+
]
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
Common error codes:
|
|
193
|
+
- `INVALID_PARAM`: input schema/field error.
|
|
194
|
+
- `INSUFFICIENT_BALANCE`: wallet or trading-account amount is not enough.
|
|
195
|
+
- `INSUFFICIENT_ALLOWANCE`: token approval/allowance is insufficient.
|
|
196
|
+
- `NOT_FOUND`: bad tool name or bad identifiers (`poolId`, `orderId`, `marketId`).
|
|
197
|
+
- `TIMEOUT`: tx confirmation/query timeout.
|
|
198
|
+
- `NETWORK_ERROR`: RPC or network issue.
|
|
199
|
+
|
|
200
|
+
Search behavior in P0:
|
|
201
|
+
- `search_market` now accepts empty `keyword` and returns active markets.
|
|
202
|
+
- When `search_market` returns empty/unstable data, server-side fallback uses SDK `api.getMarketList()` and `api.getPoolList()` to rebuild active-market results.
|
|
203
|
+
- For robust discovery, you can also call `get_market_list` directly.
|
|
204
|
+
|
|
205
|
+
Example:
|
|
206
|
+
|
|
207
|
+
```json
|
|
208
|
+
{
|
|
209
|
+
"name": "search_market",
|
|
210
|
+
"arguments": {
|
|
211
|
+
"keyword": "",
|
|
212
|
+
"limit": 20
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
```
|
|
154
216
|
|
|
155
217
|
---
|
|
156
218
|
|
|
@@ -223,7 +285,9 @@ Add to `~/Library/Application Support/Claude/claude_desktop_config.json`:
|
|
|
223
285
|
|
|
224
286
|
# Tools
|
|
225
287
|
|
|
226
|
-
The server exposes
|
|
288
|
+
The server exposes 39 tools categorized for AI:
|
|
289
|
+
|
|
290
|
+
For practical tool-by-tool examples, see: `TOOL_EXAMPLES.md`
|
|
227
291
|
|
|
228
292
|
### Trading Operations
|
|
229
293
|
* **open_position_simple**: High-level open position helper (recommended). Computes price/size/tradingFee internally.
|
|
@@ -231,8 +295,9 @@ The server exposes 38 tools categorized for AI:
|
|
|
231
295
|
* **close_position**: Close an open position.
|
|
232
296
|
* **close_all_positions**: Emergency: close ALL open positions in a pool at once.
|
|
233
297
|
* **cancel_order**: Cancel an open order by its order ID.
|
|
234
|
-
* **cancel_all_orders**: Cancel
|
|
298
|
+
* **cancel_all_orders**: Cancel open orders by IDs (supports array, JSON-array string, comma string, or single ID; use `get_open_orders` first).
|
|
235
299
|
* **set_tp_sl**: Set take profit and stop loss prices for an open position.
|
|
300
|
+
* **update_order_tp_sl**: Update TP/SL fields for an existing order. Accepts boolean-like values for `useOrderCollateral` / `isTpSlOrder`.
|
|
236
301
|
* **adjust_margin**: Adjust the margin (collateral) of an open position.
|
|
237
302
|
* **get_user_trading_fee_rate**: Query current maker/taker fee rates by asset class and risk tier.
|
|
238
303
|
* **get_network_fee**: Query estimated network fee requirements for a market.
|
|
@@ -243,17 +308,22 @@ The server exposes 38 tools categorized for AI:
|
|
|
243
308
|
* **get_oracle_price**: Get the current EVM oracle price for a specific pool.
|
|
244
309
|
* **get_kline_latest_bar**: Get only the latest bar for an interval.
|
|
245
310
|
* **get_all_tickers**: Get all ticker snapshots in one request.
|
|
246
|
-
* **get_market_list**, **get_market_list_raw**, **get_kline**, **get_pool_info**...
|
|
311
|
+
* **get_market_list**, **get_market_list_raw**, **get_kline**, **get_pool_info**... (`get_pool_info` auto-retries with oracle/ticker price on divide-by-zero reads)
|
|
247
312
|
* **get_pool_symbol_all**, **get_base_detail**, **get_pool_level_config**...
|
|
248
313
|
|
|
249
314
|
### Account & Portfolio
|
|
250
315
|
* **get_positions**: Get all open positions for the current account.
|
|
251
|
-
* **
|
|
316
|
+
* **get_account**: Unified account snapshot. Clearly separates **wallet balance** and **trading-account balance** (provide `poolId` for full trading-account metrics).
|
|
252
317
|
* **get_account_vip_info**: Query account VIP tier details.
|
|
253
|
-
* **
|
|
318
|
+
* **get_position_history**, **get_open_orders**, **get_order_history**...
|
|
319
|
+
|
|
320
|
+
`get_account` note:
|
|
321
|
+
- `poolId` omitted: wallet-focused snapshot only.
|
|
322
|
+
- `poolId` provided: wallet + trading-account + margin snapshot.
|
|
323
|
+
- If one section fails (wallet or trading-account), the tool may return a **partial** snapshot with `meta.partial=true` and section-level `error` details.
|
|
254
324
|
|
|
255
325
|
### Liquidity Provision (LP)
|
|
256
|
-
* **manage_liquidity**: Add or withdraw liquidity from a BASE or QUOTE pool.
|
|
326
|
+
* **manage_liquidity**: Add or withdraw liquidity from a BASE or QUOTE pool (aliases: `add/remove/increase/decrease` are supported).
|
|
257
327
|
* **create_perp_market**: Create a new perpetual trading pair.
|
|
258
328
|
|
|
259
329
|
---
|
|
@@ -297,6 +367,35 @@ Example MCP client usage workflow:
|
|
|
297
367
|
3. Call the `search_market` tool (e.g., `keyword: "ETH"`) to retrieve the `poolId`.
|
|
298
368
|
4. Call `open_position_simple` passing the retrieved `poolId` to open a 10x long position.
|
|
299
369
|
|
|
370
|
+
## Limit Order Lifecycle (P0)
|
|
371
|
+
|
|
372
|
+
Use this query/mutation loop for limit-order management:
|
|
373
|
+
|
|
374
|
+
1. Place order with `execute_trade` (`orderType=LIMIT`).
|
|
375
|
+
2. Query active orders with `get_open_orders`.
|
|
376
|
+
3. If still pending, you can cancel/update order-level fields; if filled into a position, prefer `set_tp_sl` for position TP/SL.
|
|
377
|
+
4. Check historical fills/cancellations with `get_order_history`.
|
|
378
|
+
5. Cancel one order via `cancel_order` or batch via `cancel_all_orders`.
|
|
379
|
+
|
|
380
|
+
Minimal query examples:
|
|
381
|
+
|
|
382
|
+
```json
|
|
383
|
+
{
|
|
384
|
+
"name": "get_open_orders",
|
|
385
|
+
"arguments": {}
|
|
386
|
+
}
|
|
387
|
+
```
|
|
388
|
+
|
|
389
|
+
```json
|
|
390
|
+
{
|
|
391
|
+
"name": "get_order_history",
|
|
392
|
+
"arguments": {
|
|
393
|
+
"poolId": "0x...",
|
|
394
|
+
"limit": 20
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
```
|
|
398
|
+
|
|
300
399
|
Example integration scripts are located in:
|
|
301
400
|
`examples/basicUsage.ts`
|
|
302
401
|
|