@michaleffffff/mcp-trading-server 3.0.5 → 3.0.10
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 +75 -0
- package/README.md +3 -2
- package/TOOL_EXAMPLES.md +13 -0
- package/dist/auth/resolveClient.js +19 -2
- package/dist/server.js +2 -2
- package/dist/services/poolService.js +474 -49
- package/dist/services/tradeService.js +18 -13
- package/dist/tools/accountInfo.js +4 -52
- package/dist/tools/accountTransfer.js +5 -10
- package/dist/tools/checkAccountReady.js +16 -10
- package/dist/tools/closePosition.js +17 -10
- package/dist/tools/createPerpMarket.js +132 -5
- package/dist/tools/getAccountSnapshot.js +10 -4
- package/dist/tools/getBaseDetail.js +43 -3
- package/dist/tools/getOrders.js +30 -2
- package/dist/tools/getPoolMetadata.js +16 -4
- package/dist/tools/getUserTradingFeeRate.js +65 -2
- package/dist/tools/manageTpSl.js +239 -31
- package/dist/tools/openPositionSimple.js +5 -3
- package/dist/utils/injectProvider.js +1 -0
- package/dist/utils/mappings.js +12 -7
- package/package.json +4 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,80 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 3.0.10 - 2026-03-18
|
|
4
|
+
|
|
5
|
+
### Fixed
|
|
6
|
+
- Hardened `manage_tp_sl` delete behavior (`tpPrice=0` + `slPrice=0`):
|
|
7
|
+
- Added a unified cancellation path helper to always map delete intent to `cancelAllOrders` (by `orderId` or by `positionId`).
|
|
8
|
+
- Added fallback recovery for SDK/contract `InvalidParameter` reverts (including selector `0x613970e0`) so zero-price delete intent will still downgrade to explicit cancellation instead of failing.
|
|
9
|
+
|
|
10
|
+
## 3.0.9 - 2026-03-18
|
|
11
|
+
|
|
12
|
+
### Fixed
|
|
13
|
+
- Fixed `create_perp_market` observability and compatibility:
|
|
14
|
+
- Added strict `marketId` (66-char hash) and `baseToken` address validation.
|
|
15
|
+
- Added structured error payloads with decoded contract selector hints (e.g. `PoolExists(PoolId)`).
|
|
16
|
+
- Added fallback for SDK v1.0.2 write-path incompatibility (`deployPool is not a function`) by directly calling `PoolManager.deployPool`.
|
|
17
|
+
- Fixed `manage_tp_sl` delete semantics:
|
|
18
|
+
- `tpPrice=0` + `slPrice=0` now maps to explicit TP/SL order cancellation (by `orderId` or by `positionId`) instead of sending invalid on-chain TP/SL orders.
|
|
19
|
+
- Fixed `get_base_detail` null-read behavior:
|
|
20
|
+
- `success + null` is now returned as a structured error (`NOT_FOUND`) with chain/base context.
|
|
21
|
+
- Fixed `get_orders` OPEN status mapping:
|
|
22
|
+
- Removed `Unknown(undefined)` and normalized missing OPEN status to `Open`.
|
|
23
|
+
- Fixed LP SDK wait incompatibility:
|
|
24
|
+
- Added submitted tx-hash recovery path when SDK returns `...wait is not a function` after broadcast (e.g., BASE withdraw).
|
|
25
|
+
- Hardened direct LP router fallback:
|
|
26
|
+
- Added token allowance auto-approval before fallback deposit.
|
|
27
|
+
|
|
28
|
+
### Verified (Real Funds, Arbitrum Sepolia 421614)
|
|
29
|
+
- Deployed and minted new base token to active wallet:
|
|
30
|
+
- token: `0xDae49922Ff1699CA2A6cc4eE835B2c5a9f3Fe870`
|
|
31
|
+
- deploy tx: `0x99e69d66cac1b3a033281bae45dd421bba37794e1a80c1a12eddded99c48acce`
|
|
32
|
+
- Created new perp pool for the token (marketId: `0x2a3fee38e8beba148141bea5cab0bcbbb0cf24fd5509117346991cc438cb2fe6`):
|
|
33
|
+
- create tx: `0x97266886c673cee13531837bcf9a0524034bd85a018036f3557c4d126fef3771`
|
|
34
|
+
- derived poolId: `0x6c1a8af5123a0cf636293aff3fce2ea6addd4bce172c39c6467d4dc95ac3f83e`
|
|
35
|
+
- BASE LP add/remove validated on the new pool:
|
|
36
|
+
- add approval tx: `0xa2739346558f43f474953c7c93be05f0c66f2659f80d8b07804823f03926bdb0`
|
|
37
|
+
- add tx: `0x6a10d7dc5d2794643b10bc2b53080bfa8df1c99eedf35cd48a46edaa6d97d832`
|
|
38
|
+
- remove tx: `0x4148585452d259f6a9928404c7b8d324013e7ee13859392302ab78aa34fab2bc`
|
|
39
|
+
|
|
40
|
+
## 3.0.8 - 2026-03-18
|
|
41
|
+
|
|
42
|
+
### Fixed
|
|
43
|
+
- Fixed `manage_liquidity` QUOTE pool ABI mismatch (`Expected length params=1, values=2`) by adding a safe fallback path:
|
|
44
|
+
- Keep SDK LP call as primary path.
|
|
45
|
+
- On SDK ABI-overload mismatch, switch to explicit-signature router transaction path (`depositQuote`/`withdrawQuote`) to avoid overloaded function ambiguity.
|
|
46
|
+
- Added the same overload-mismatch fallback for BASE pool LP operations (`depositBase`/`withdrawBase`) to prevent the same class of failure.
|
|
47
|
+
- Added SDK ABI-mismatch log suppression for LP calls to avoid noisy stack traces when fallback is activated.
|
|
48
|
+
|
|
49
|
+
### Verified
|
|
50
|
+
- Executed a real QUOTE remove liquidity transaction via MCP after the fix:
|
|
51
|
+
- txHash: `0x69e089b805cccd3b14d0c511309a0ce2aecf988344ec23ae27df929ad99af390`
|
|
52
|
+
- status: success (confirmed on-chain)
|
|
53
|
+
|
|
54
|
+
## 3.0.7 - 2026-03-18
|
|
55
|
+
|
|
56
|
+
### Changed
|
|
57
|
+
- Updated server runtime version banner and MCP server version to `3.0.7`.
|
|
58
|
+
- Hardened `get_pool_metadata` warning output by compacting long low-level errors into concise warnings.
|
|
59
|
+
- Optimized `get_pool_info` read path:
|
|
60
|
+
- Prefer resolving a positive oracle/ticker market price and use it directly for pool info reads.
|
|
61
|
+
- Return clearer domain error for empty-liquidity / unresolved-price scenarios.
|
|
62
|
+
- Refined `get_user_trading_fee_rate` error handling:
|
|
63
|
+
- Return structured MCP error envelope (`INVALID_PARAM` / `SDK_READ_ERROR`) instead of raw error strings.
|
|
64
|
+
- Include normalized concise error messages and request context details.
|
|
65
|
+
- Enhanced `account_deposit` usability by making `tokenAddress` optional (defaults to `QUOTE_TOKEN_ADDRESS`).
|
|
66
|
+
|
|
67
|
+
## 3.0.6 - 2026-03-18
|
|
68
|
+
|
|
69
|
+
### Changed
|
|
70
|
+
- Upgraded SDK dependency to `@myx-trade/sdk@^1.0.2`.
|
|
71
|
+
- Updated client bootstrap to provide a viem-compatible `walletClient` shim (`json-rpc` account + `getAddresses/request/signMessage`) for SDK v1.0.2.
|
|
72
|
+
- Moved `get_trade_flow` to SDK v1.0.2 native path (`client.api.getTradeFlow`).
|
|
73
|
+
- Moved `account_withdraw` to SDK v1.0.2 native path (`account.updateAndWithdraw`).
|
|
74
|
+
- Normalized `baseToken` address before `pool.createPool` to satisfy stricter typed input.
|
|
75
|
+
- Updated account balance parsing to SDK v1.0.2 `getAccountInfo` fields (`freeMargin`, `walletBalance`).
|
|
76
|
+
- Hardened type guards for account snapshot and fee-rate parsing under SDK union return types.
|
|
77
|
+
|
|
3
78
|
## 3.0.5 - 2026-03-18
|
|
4
79
|
|
|
5
80
|
### Changed
|
package/README.md
CHANGED
|
@@ -6,7 +6,8 @@ A production-ready MCP (Model Context Protocol) server for deep integration with
|
|
|
6
6
|
|
|
7
7
|
# Release Notes
|
|
8
8
|
|
|
9
|
-
- **Current release: 3.0.
|
|
9
|
+
- **Current release: 3.0.10**
|
|
10
|
+
- **SDK baseline**: `@myx-trade/sdk@^1.0.2` compatibility completed.
|
|
10
11
|
- **Refinement**: Consolidated 40+ specialized tools into ~26 high-level unified tools.
|
|
11
12
|
- **Improved UX**: Enhanced AI parameter parsing, automated unit conversion, and structured error reporting.
|
|
12
13
|
- **Breaking changes**: Many low-level tools (e.g., `get_market_price`, `get_oracle_price`, `get_open_orders`) have been merged into unified counterparts.
|
|
@@ -53,7 +54,7 @@ QUOTE_TOKEN_DECIMALS=18
|
|
|
53
54
|
* **`close_position`**: Strategy-based closing of specific positions.
|
|
54
55
|
* **`close_all_positions`**: Emergency exit for all positions in a specific pool.
|
|
55
56
|
* **`cancel_orders`**: Unified cancellation (Single ID, Pool-wide, or Account-wide).
|
|
56
|
-
* **`manage_tp_sl`**: Adjust protection orders for active positions or pending orders.
|
|
57
|
+
* **`manage_tp_sl`**: Adjust protection orders for active positions or pending orders. Deletion is supported via `tpPrice=0` + `slPrice=0`.
|
|
57
58
|
* **`adjust_margin`**: Add or remove collateral to manage liquidation risk.
|
|
58
59
|
|
|
59
60
|
### 📁 Account & Portfolio
|
package/TOOL_EXAMPLES.md
CHANGED
|
@@ -60,6 +60,19 @@ Update existing protection orders or set new ones for a position.
|
|
|
60
60
|
}
|
|
61
61
|
```
|
|
62
62
|
|
|
63
|
+
Delete both TP/SL for a position:
|
|
64
|
+
```json
|
|
65
|
+
{
|
|
66
|
+
"name": "manage_tp_sl",
|
|
67
|
+
"arguments": {
|
|
68
|
+
"poolId": "BTC",
|
|
69
|
+
"positionId": "0xABC...",
|
|
70
|
+
"tpPrice": "0",
|
|
71
|
+
"slPrice": "0"
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
```
|
|
75
|
+
|
|
63
76
|
---
|
|
64
77
|
|
|
65
78
|
## 🔵 Market Data
|
|
@@ -24,6 +24,8 @@ export async function resolveClient() {
|
|
|
24
24
|
const rpcUrl = process.env.RPC_URL || "https://rpc.sepolia.linea.build";
|
|
25
25
|
const privateKey = process.env.PRIVATE_KEY;
|
|
26
26
|
const chainId = Number(process.env.CHAIN_ID) || 59141;
|
|
27
|
+
const isTestnet = process.env.IS_TESTNET !== "false";
|
|
28
|
+
const isBetaMode = String(process.env.IS_BETA_MODE ?? "").trim().toLowerCase() === "true";
|
|
27
29
|
const brokerAddressRaw = process.env.BROKER_ADDRESS || getDefaultBrokerByChainId(chainId);
|
|
28
30
|
const quoteTokenRaw = process.env.QUOTE_TOKEN_ADDRESS || getDefaultQuoteTokenByChainId(chainId);
|
|
29
31
|
const quoteDecimals = Number(process.env.QUOTE_TOKEN_DECIMALS) || 6;
|
|
@@ -42,12 +44,27 @@ export async function resolveClient() {
|
|
|
42
44
|
// Inject the EIP-1193 mock so SDK can sign transactions seamlessly
|
|
43
45
|
const { injectBrowserProviderMock } = await import("../utils/injectProvider.js");
|
|
44
46
|
injectBrowserProviderMock(chainId, provider, signer);
|
|
47
|
+
const ethereumProvider = globalThis.window.ethereum;
|
|
48
|
+
const walletClient = {
|
|
49
|
+
transport: ethereumProvider,
|
|
50
|
+
chain: { id: chainId },
|
|
51
|
+
account: { address: signer.address, type: "json-rpc" },
|
|
52
|
+
getAddresses: async () => [signer.address],
|
|
53
|
+
request: async (args) => ethereumProvider.request(args),
|
|
54
|
+
signMessage: async ({ message }) => {
|
|
55
|
+
const payload = typeof message === "string"
|
|
56
|
+
? message
|
|
57
|
+
: (message?.raw ?? message?.message ?? "");
|
|
58
|
+
return signer.signMessage(payload);
|
|
59
|
+
},
|
|
60
|
+
};
|
|
45
61
|
const client = new MyxClient({
|
|
46
62
|
chainId,
|
|
47
63
|
signer: signer,
|
|
48
64
|
brokerAddress,
|
|
49
|
-
isTestnet
|
|
50
|
-
|
|
65
|
+
isTestnet,
|
|
66
|
+
isBetaMode,
|
|
67
|
+
walletClient: walletClient
|
|
51
68
|
});
|
|
52
69
|
cached = { client, address: signer.address, signer, chainId, quoteToken, quoteDecimals };
|
|
53
70
|
return cached;
|
package/dist/server.js
CHANGED
|
@@ -370,7 +370,7 @@ function zodSchemaToJsonSchema(zodSchema) {
|
|
|
370
370
|
};
|
|
371
371
|
}
|
|
372
372
|
// ─── MCP Server ───
|
|
373
|
-
const server = new Server({ name: "myx-mcp-trading-server", version: "3.0.
|
|
373
|
+
const server = new Server({ name: "myx-mcp-trading-server", version: "3.0.10" }, { capabilities: { tools: {}, resources: {}, prompts: {} } });
|
|
374
374
|
// List tools
|
|
375
375
|
server.setRequestHandler(ListToolsRequestSchema, async () => {
|
|
376
376
|
return {
|
|
@@ -491,7 +491,7 @@ server.setRequestHandler(GetPromptRequestSchema, async (request) => {
|
|
|
491
491
|
async function main() {
|
|
492
492
|
const transport = new StdioServerTransport();
|
|
493
493
|
await server.connect(transport);
|
|
494
|
-
logger.info("🚀 MYX Trading MCP Server v3.0.
|
|
494
|
+
logger.info("🚀 MYX Trading MCP Server v3.0.10 running (stdio, pure on-chain, prod ready)");
|
|
495
495
|
}
|
|
496
496
|
main().catch((err) => {
|
|
497
497
|
logger.error("Fatal Server Startup Error", err);
|