@michaleffffff/mcp-trading-server 2.7.0 → 2.8.2

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.
@@ -1 +1,2 @@
1
1
  export { tradeAnalysisPrompt } from "./tradeAnalysisPrompt.js";
2
+ export { tradingGuidePrompt } from "./tradingGuide.js";
@@ -20,7 +20,17 @@ export const tradeAnalysisPrompt = {
20
20
  role: "user",
21
21
  content: {
22
22
  type: "text",
23
- text: `Please analyze my current trading positions:\n\nPositions: ${JSON.stringify(positions, (_, v) => typeof v === 'bigint' ? v.toString() : v, 2)}\n\nMarket Context: ${args?.marketContext || "None provided"}\n\nWhat are the major risks and opportunities?`
23
+ text: `Analyze this user's trading portfolio with professional rigor:
24
+
25
+ Positions: ${JSON.stringify(positions, (_, v) => typeof v === 'bigint' ? v.toString() : v, 2)}
26
+
27
+ Market Context: ${args?.marketContext || "None provided"}
28
+
29
+ ## Analysis Requirements:
30
+ 1. **Risk Level**: Calculate current margin health and distance to liquidation price.
31
+ 2. **PnL Review**: Evaluate performance and identify if SL/TP are appropriately placed.
32
+ 3. **Actionable Suggestions**: Suggest specific size adjustments or TP/SL updates based on context.
33
+ 4. **Funding Outlook**: Brief comment on funding fee impacts if observable.`
24
34
  }
25
35
  }
26
36
  ]
@@ -0,0 +1,43 @@
1
+ import { resolveClient } from "../auth/resolveClient.js";
2
+ export const tradingGuidePrompt = {
3
+ name: "trading_best_practices",
4
+ description: "Get the gold standard workflow and parameter advice for using this MCP trading server.",
5
+ arguments: [],
6
+ run: async () => {
7
+ const { address, chainId } = await resolveClient();
8
+ return {
9
+ messages: [
10
+ {
11
+ role: "assistant",
12
+ content: {
13
+ type: "text",
14
+ text: `
15
+ # MYX Trading MCP Best Practices (v2.8.0)
16
+
17
+ You are an expert crypto trader using the MYX Protocol. To ensure successful execution and safe handling of user funds, follow these patterns:
18
+
19
+ ## 1. The Standard Workflow
20
+ 1. **Discovery**: Use \`search_market\` with a keyword (e.g., "BTC") to find the active \`poolId\`.
21
+ 2. **Context**: Use \`get_market_price\` and \`get_account_info\` to check the current market state and your available margin.
22
+ 3. **Execution**: Prefer \`open_position_simple\` for new trades. It handles unit conversions and pool resolution automatically.
23
+ 4. **Validation**: Always check the \`verification.verified\` flag in the output. If \`false\`, read the \`cancelReason\` to explain the failure to the user.
24
+
25
+ ## 2. Parameter Tips
26
+ - **Position IDs**: When opening a NEW position, \`positionId\` MUST be an empty string \`""\`.
27
+ - **Decimals**: Human-readable units (e.g., "0.1" BTC) are default for \`open_position_simple\`. SDK-native tools often require raw units; use the \`raw:\` prefix if you need forced precision.
28
+ - **Slippage**: Default is 100 (1%). For volatile meme tokens, consider 200-300 (2-3%).
29
+ - **Fees**: Use \`get_user_trading_fee_rate\` to estimate fees before large trades.
30
+
31
+ ## 3. Self-Healing
32
+ If a transaction reverts with a hex code, the server will attempt to decode it (e.g., "AccountInsufficientFreeAmount"). Inform the user specifically about what is missing rather than giving a generic error.
33
+
34
+ Current Session:
35
+ - Wallet: ${address}
36
+ - Chain ID: ${chainId}
37
+ `
38
+ }
39
+ }
40
+ ]
41
+ };
42
+ }
43
+ };
package/dist/server.js CHANGED
@@ -81,7 +81,7 @@ function zodSchemaToJsonSchema(zodSchema) {
81
81
  };
82
82
  }
83
83
  // ─── MCP Server ───
84
- const server = new Server({ name: "myx-mcp-trading-server", version: "2.6.0" }, { capabilities: { tools: {}, resources: {}, prompts: {} } });
84
+ const server = new Server({ name: "myx-mcp-trading-server", version: "2.8.2" }, { capabilities: { tools: {}, resources: {}, prompts: {} } });
85
85
  // List tools
86
86
  server.setRequestHandler(ListToolsRequestSchema, async () => {
87
87
  return {
@@ -181,7 +181,7 @@ server.setRequestHandler(GetPromptRequestSchema, async (request) => {
181
181
  async function main() {
182
182
  const transport = new StdioServerTransport();
183
183
  await server.connect(transport);
184
- logger.info("🚀 MYX Trading MCP Server v2.6.0 running (stdio, pure on-chain, prod ready)");
184
+ logger.info("🚀 MYX Trading MCP Server v2.8.2 running (stdio, pure on-chain, prod ready)");
185
185
  }
186
186
  main().catch((err) => {
187
187
  logger.error("Fatal Server Startup Error", err);
@@ -19,13 +19,18 @@ export const getAccountInfoTool = {
19
19
  structuredData = {
20
20
  ...result,
21
21
  data: {
22
- marginBalance: d[0],
23
- availableMargin: d[1],
24
- unrealizedPnL: d[2],
25
- initialMargin: d[3],
26
- maintenanceMargin: d[4],
27
- positionMargin: d[5],
28
- lastUpdateTime: d[6]
22
+ freeMargin: d[0],
23
+ walletBalance: d[1],
24
+ freeBaseAmount: d[2],
25
+ baseProfit: d[3],
26
+ quoteProfit: d[4],
27
+ reservedAmount: d[5],
28
+ releaseTime: d[6],
29
+ // Business Logic:
30
+ // tradeableMargin = freeMargin + walletBalance + (quoteProfit if releaseTime == 0)
31
+ tradeableMargin: (BigInt(d[0]) + BigInt(d[1]) + (BigInt(d[6]) === 0n ? BigInt(d[4]) : 0n)).toString(),
32
+ baseProfitStatus: "base token to be unlocked",
33
+ quoteProfitStatus: BigInt(d[6]) > 0n ? "quote token to be unlocked" : "quote token unlocked/available"
29
34
  }
30
35
  };
31
36
  }
@@ -9,29 +9,29 @@ export const executeTradeTool = {
9
9
  name: "execute_trade",
10
10
  description: "Create an increase order using SDK-native parameters.",
11
11
  schema: {
12
- poolId: z.string().describe("Pool ID"),
12
+ poolId: z.string().describe("Hex Pool ID, e.g. '0x14a19...'. Get via get_pool_list."),
13
13
  positionId: z.string().refine((value) => POSITION_ID_RE.test(value), {
14
14
  message: "positionId must be empty string for new position, or a bytes32 hex string.",
15
- }).describe("Position ID: empty string for new position"),
16
- orderType: z.coerce.number().int().min(0).max(3).describe("OrderType enum value"),
17
- triggerType: z.coerce.number().int().min(0).max(2).describe("TriggerType enum value"),
15
+ }).describe("Position ID: Use empty string '' for NEW positions, or valid hex for INCREASING existing ones."),
16
+ orderType: z.coerce.number().int().min(0).max(3).describe("0=Market, 1=Limit, 2=Stop, 3=StopLimit"),
17
+ triggerType: z.coerce.number().int().min(0).max(2).describe("0=None (Market), 1=Price, 2=Trailing"),
18
18
  direction: z.coerce.number().pipe(z.union([z.literal(0), z.literal(1)])).describe("0 = LONG, 1 = SHORT"),
19
- collateralAmount: z.coerce.string().describe("Collateral amount (raw or human-readable)"),
20
- size: z.coerce.string().describe("Position size (raw or human-readable)"),
21
- price: z.coerce.string().describe("Price (raw or human-readable, 30 decimals)"),
22
- timeInForce: z.coerce.number().int().describe("TimeInForce enum value"),
23
- postOnly: z.coerce.boolean().describe("Post-only flag"),
19
+ collateralAmount: z.coerce.string().describe("Collateral. e.g. '100' or 'raw:100000000' (6 decimals for USDC)."),
20
+ size: z.coerce.string().describe("Notional size in base tokens. e.g. '0.5' BTC or 'raw:50000000'."),
21
+ price: z.coerce.string().describe("Execution or Limit price. e.g. '65000' or 'raw:65000000000000000000000000000000000' (30 decimals)."),
22
+ timeInForce: z.coerce.number().int().describe("0=GTC, 1=IOC, 2=FOK"),
23
+ postOnly: z.coerce.boolean().describe("If true, order only executes as Maker."),
24
24
  slippagePct: z.coerce.string().refine(isValidSlippagePct4dp, {
25
25
  message: "slippagePct must be an integer in [0, 10000] with 4-decimal precision (1 = 0.01%).",
26
- }).describe(SLIPPAGE_PCT_4DP_DESC),
27
- executionFeeToken: z.string().describe("Execution fee token address"),
28
- leverage: z.coerce.number().describe("Leverage"),
29
- tpSize: z.coerce.string().optional().describe("TP size (raw or human-readable)"),
30
- tpPrice: z.coerce.string().optional().describe("TP price (raw or human-readable)"),
31
- slSize: z.coerce.string().optional().describe("SL size (raw or human-readable)"),
32
- slPrice: z.coerce.string().optional().describe("SL price (raw or human-readable)"),
33
- tradingFee: z.coerce.string().describe("Trading fee (raw units)"),
34
- marketId: z.string().describe("Market ID"),
26
+ }).describe(`${SLIPPAGE_PCT_4DP_DESC}. Standard is 100 (1%).`),
27
+ executionFeeToken: z.string().describe("Address of token to pay gas/execution fees (typically USDC)."),
28
+ leverage: z.coerce.number().describe("Leverage multiplier, e.g., 10 for 10x."),
29
+ tpSize: z.coerce.string().optional().describe("Take Profit size. Use '0' to disable."),
30
+ tpPrice: z.coerce.string().optional().describe("Take Profit trigger price."),
31
+ slSize: z.coerce.string().optional().describe("Stop Loss size. Use '0' to disable."),
32
+ slPrice: z.coerce.string().optional().describe("Stop Loss trigger price."),
33
+ tradingFee: z.coerce.string().describe("Estimated fee in raw units. Fetch via get_user_trading_fee_rate."),
34
+ marketId: z.string().describe("Specific Market Config Hash. Fetch via get_market_list."),
35
35
  },
36
36
  handler: async (args) => {
37
37
  try {
@@ -37,22 +37,22 @@ export const openPositionSimpleTool = {
37
37
  name: "open_position_simple",
38
38
  description: "High-level open position helper. Computes size/price/tradingFee and submits an increase order. Human units by default; use 'raw:' prefix for raw units.",
39
39
  schema: {
40
- poolId: z.string().optional().describe("Pool ID. Provide either poolId or keyword."),
41
- keyword: z.string().optional().describe('Market keyword, e.g. "BTC". Provide either keyword or poolId.'),
42
- direction: z.any().describe("LONG (0), SHORT (1) or string BUY/SELL/LONG/SHORT"),
40
+ poolId: z.string().optional().describe("Hex Pool ID. Provide either poolId or keyword."),
41
+ keyword: z.string().optional().describe('Recommended: Market keyword, e.g. "BTC", "ETH", "XRP".'),
42
+ direction: z.any().describe("0=LONG, 1=SHORT, or strings like 'BUY'/'SELL'/'LONG'/'SHORT'."),
43
43
  collateralAmount: z.coerce
44
44
  .string()
45
- .describe("Collateral amount in quote token units (human by default; 'raw:' prefix for raw)."),
45
+ .describe("Collateral. e.g. '100' (quoted in USDC) or 'raw:100000000'."),
46
46
  leverage: z.coerce.number().int().positive().describe("Leverage (integer, e.g. 5, 10)."),
47
- orderType: z.union([z.string(), z.number()]).optional().describe("MARKET, LIMIT, STOP (default MARKET)."),
47
+ orderType: z.union([z.string(), z.number()]).optional().describe("MARKET, LIMIT, STOP (default MARKET). Strings allowed."),
48
48
  price: z.coerce
49
49
  .string()
50
50
  .optional()
51
- .describe("Price (human by default; 30-dec raw with 'raw:' prefix). Required for LIMIT/STOP."),
51
+ .describe("Price. e.g. '62000' or 'raw:...' (30 dec). Required for LIMIT/STOP."),
52
52
  size: z.coerce
53
53
  .string()
54
54
  .optional()
55
- .describe("Position size in base token units (human by default; 'raw:' prefix for raw). If omitted, computed from collateral*leverage/price."),
55
+ .describe("Position size. e.g. '0.5' BTC. If omitted, computed from collateral*leverage/price."),
56
56
  slippagePct: z.coerce
57
57
  .string()
58
58
  .optional()
@@ -64,13 +64,13 @@ export const openPositionSimpleTool = {
64
64
  tradingFee: z.coerce
65
65
  .string()
66
66
  .optional()
67
- .describe("Trading fee in quote token units (human by default; 'raw:' prefix for raw). If omitted, computed via getUserTradingFeeRate."),
68
- autoApprove: z.coerce.boolean().optional().describe("If true, auto-approve quote token spend when needed (default false)."),
69
- approveMax: z.coerce.boolean().optional().describe("If autoApprove, approve MaxUint256 (default false approves exact amount)."),
67
+ .describe("Trading fee. e.g. '0.2' USDC or 'raw:...'. Default: computed via getUserTradingFeeRate."),
68
+ autoApprove: z.coerce.boolean().optional().describe("If true, auto-approve token spend (default false)."),
69
+ approveMax: z.coerce.boolean().optional().describe("If autoApprove, approve MaxUint256 (default false)."),
70
70
  autoDeposit: z.coerce
71
71
  .boolean()
72
72
  .optional()
73
- .describe("If true, auto-deposit to margin account when marginBalance is insufficient (default false)."),
73
+ .describe("If true, auto-deposit to margin account if marginBalance < needed (default false)."),
74
74
  dryRun: z.coerce.boolean().optional().describe("If true, only compute params; do not send a transaction."),
75
75
  },
76
76
  handler: async (args) => {
@@ -8,20 +8,20 @@ export const setTpSlTool = {
8
8
  name: "set_tp_sl",
9
9
  description: "Create TP/SL order using SDK-native parameters.",
10
10
  schema: {
11
- poolId: z.string().describe("Pool ID"),
12
- positionId: z.string().describe("Position ID"),
13
- direction: z.any().describe("LONG (0), SHORT (1) or string BUY/SELL/LONG/SHORT"),
14
- leverage: z.coerce.number().describe("Leverage"),
15
- executionFeeToken: z.string().describe("Execution fee token address"),
16
- tpTriggerType: z.union([z.number(), z.string()]).optional().describe("TP trigger type (0=NONE, 1=GTE, 2=LTE)"),
17
- slTriggerType: z.union([z.number(), z.string()]).optional().describe("SL trigger type (0=NONE, 1=GTE, 2=LTE)"),
11
+ poolId: z.string().describe("Hex Pool ID, e.g. '0x14a19...'. Get via get_pool_list."),
12
+ positionId: z.string().describe("Active Position ID. Get via get_positions."),
13
+ direction: z.any().describe("0=LONG, 1=SHORT, or strings like 'BUY'/'SELL'/'LONG'/'SHORT'."),
14
+ leverage: z.coerce.number().describe("Leverage multiplier, e.g., 10."),
15
+ executionFeeToken: z.string().describe("Address of token to pay gas/execution fees."),
16
+ tpTriggerType: z.union([z.number(), z.string()]).optional().describe("0=None, 1=Price (Market), 2=Trailing."),
17
+ slTriggerType: z.union([z.number(), z.string()]).optional().describe("0=None, 1=Price (Market), 2=Trailing."),
18
18
  slippagePct: z.coerce.string().refine(isValidSlippagePct4dp, {
19
19
  message: "slippagePct must be an integer in [0, 10000] with 4-decimal precision (1 = 0.01%).",
20
- }).describe(SLIPPAGE_PCT_4DP_DESC),
21
- tpPrice: z.coerce.string().optional().describe("TP price (raw or human-readable, 30 decimals)"),
22
- tpSize: z.coerce.string().optional().describe("TP size (raw or human-readable)"),
23
- slPrice: z.coerce.string().optional().describe("SL price (raw or human-readable, 30 decimals)"),
24
- slSize: z.coerce.string().optional().describe("SL size (raw or human-readable)"),
20
+ }).describe(`${SLIPPAGE_PCT_4DP_DESC}. Standard is 100 (1%).`),
21
+ tpPrice: z.coerce.string().optional().describe("Take Profit trigger price. e.g. '2.5' or 'raw:...' (30 decimals)."),
22
+ tpSize: z.coerce.string().optional().describe("TP size in base tokens. Use '0' to disable."),
23
+ slPrice: z.coerce.string().optional().describe("Stop Loss trigger price. e.g. '2.1' or 'raw:...' (30 decimals)."),
24
+ slSize: z.coerce.string().optional().describe("SL size in base tokens. Use '0' to disable."),
25
25
  },
26
26
  handler: async (args) => {
27
27
  try {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@michaleffffff/mcp-trading-server",
3
- "version": "2.7.0",
3
+ "version": "2.8.2",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "myx-mcp": "dist/server.js"