@michaleffffff/mcp-trading-server 2.9.2 → 3.0.0

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.
@@ -28,10 +28,9 @@ export { createPerpMarketTool } from "./createPerpMarket.js";
28
28
  export { manageLiquidityTool, getLpPriceTool } from "./manageLiquidity.js";
29
29
  // Tools — 账户 & 查询
30
30
  export { getPositionsTool } from "./getPositions.js";
31
- export { getBalancesTool } from "./getBalances.js";
32
31
  export { getOpenOrdersTool, getOrderHistoryTool } from "./orderQueries.js";
33
32
  export { getPositionHistoryTool } from "./positionHistory.js";
34
- export { getAccountInfoTool, getTradeFlowTool, getMarginBalanceTool } from "./accountInfo.js";
33
+ export { getAccountTool, getTradeFlowTool } from "./accountInfo.js";
35
34
  export { getAccountVipInfoTool } from "./getAccountVipInfo.js";
36
35
  export { accountDepositTool, accountWithdrawTool } from "./accountTransfer.js";
37
36
  export { getMarketListTool } from "./getMarketList.js";
@@ -1,23 +1,31 @@
1
1
  import { z } from "zod";
2
2
  import { quoteDeposit, quoteWithdraw, baseDeposit, baseWithdraw, getLpPrice, } from "../services/poolService.js";
3
3
  import { resolveClient } from "../auth/resolveClient.js";
4
+ import { resolvePool } from "../services/marketService.js";
4
5
  import { finalizeMutationResult } from "../utils/mutationResult.js";
5
6
  export const manageLiquidityTool = {
6
7
  name: "manage_liquidity",
7
8
  description: "Add or withdraw liquidity from a BASE or QUOTE pool.",
8
9
  schema: {
9
- action: z.enum(["deposit", "withdraw"]).describe("'deposit' or 'withdraw'"),
10
+ action: z.enum(["deposit", "withdraw", "add", "remove", "increase", "decrease"]).describe("'deposit' or 'withdraw' (aliases: add, remove, increase, decrease)"),
10
11
  poolType: z.enum(["BASE", "QUOTE"]).describe("'BASE' or 'QUOTE'"),
11
- poolId: z.string().describe("Pool ID"),
12
+ poolId: z.string().describe("Pool ID or Base Token Address"),
12
13
  amount: z.coerce.number().positive().describe("Amount in human-readable units"),
13
14
  slippage: z.coerce.number().min(0).describe("LP slippage ratio (e.g. 0.01 = 1%)"),
14
15
  chainId: z.coerce.number().int().positive().optional().describe("Optional chainId override"),
15
16
  },
16
17
  handler: async (args) => {
17
18
  try {
18
- const { signer } = await resolveClient();
19
- const { action, poolType, poolId } = args;
19
+ const { client, signer } = await resolveClient();
20
+ let { action, poolType, poolId } = args;
20
21
  const { amount, slippage } = args;
22
+ // 1. Action Alias Mapping
23
+ if (action === "add" || action === "increase")
24
+ action = "deposit";
25
+ if (action === "remove" || action === "decrease")
26
+ action = "withdraw";
27
+ // 2. Smart Pool Resolution (Handles PoolId, Token Address, or Keywords)
28
+ poolId = await resolvePool(client, poolId);
21
29
  let raw;
22
30
  if (poolType === "QUOTE") {
23
31
  raw = action === "deposit"
@@ -1,19 +1,22 @@
1
1
  import { z } from "zod";
2
2
  import { resolveClient, getChainId } from "../auth/resolveClient.js";
3
- import { getMarketDetail } from "../services/marketService.js";
3
+ import { getMarketDetail, resolvePool } from "../services/marketService.js";
4
4
  import { getPoolInfo, getLiquidityInfo } from "../services/poolService.js";
5
5
  export const getMarketDetailTool = {
6
6
  name: "get_market_detail",
7
- description: "Get detailed information for a specific trading pool (fee rates, open interest, etc.).",
7
+ description: "Get detailed information for a specific trading pool (fee rates, open interest, etc.). Supports PoolId, Token Address, or Keywords.",
8
8
  schema: {
9
- poolId: z.string().describe("Pool ID"),
9
+ poolId: z.string().describe("Pool ID, Token Address, or Keyword"),
10
10
  chainId: z.number().int().positive().optional().describe("Optional chainId override"),
11
11
  },
12
12
  handler: async (args) => {
13
13
  try {
14
14
  const { client } = await resolveClient();
15
+ const poolId = await resolvePool(client, args.poolId);
15
16
  const chainId = args.chainId ?? getChainId();
16
- const data = await getMarketDetail(client, args.poolId, chainId);
17
+ const data = await getMarketDetail(client, poolId, chainId);
18
+ if (!data)
19
+ throw new Error(`Market detail for ${poolId} not found.`);
17
20
  return { content: [{ type: "text", text: JSON.stringify({ status: "success", data }, (_, v) => typeof v === 'bigint' ? v.toString() : v, 2) }] };
18
21
  }
19
22
  catch (error) {
@@ -23,15 +26,19 @@ export const getMarketDetailTool = {
23
26
  };
24
27
  export const getPoolInfoTool = {
25
28
  name: "get_pool_info",
26
- description: "Get pool on-chain information (reserves, utilization, etc.).",
29
+ description: "Get pool on-chain information (reserves, utilization, etc.). Supports PoolId, Token Address, or Keywords.",
27
30
  schema: {
28
- poolId: z.string().describe("Pool ID"),
31
+ poolId: z.string().describe("Pool ID, Token Address, or Keyword"),
29
32
  chainId: z.number().int().positive().optional().describe("Optional chainId override"),
30
33
  },
31
34
  handler: async (args) => {
32
35
  try {
36
+ const { client } = await resolveClient();
37
+ const poolId = await resolvePool(client, args.poolId);
33
38
  const chainId = args.chainId ?? getChainId();
34
- const data = await getPoolInfo(args.poolId, chainId);
39
+ const data = await getPoolInfo(poolId, chainId);
40
+ if (!data)
41
+ throw new Error(`Pool info for ${poolId} returned undefined. The pool may not exist on chainId ${chainId}.`);
35
42
  return { content: [{ type: "text", text: JSON.stringify({ status: "success", data }, (_, v) => typeof v === 'bigint' ? v.toString() : v, 2) }] };
36
43
  }
37
44
  catch (error) {
@@ -41,17 +48,20 @@ export const getPoolInfoTool = {
41
48
  };
42
49
  export const getLiquidityInfoTool = {
43
50
  name: "get_liquidity_info",
44
- description: "Get pool liquidity utilization and depth information.",
51
+ description: "Get pool liquidity utilization and depth information. Supports PoolId, Token Address, or Keywords.",
45
52
  schema: {
46
- poolId: z.string().describe("Pool ID"),
53
+ poolId: z.string().describe("Pool ID, Token Address, or Keyword"),
47
54
  marketPrice: z.string().regex(/^\d+$/).describe("Current market price in 30-decimal raw units"),
48
55
  chainId: z.number().int().positive().optional().describe("Optional chainId override"),
49
56
  },
50
57
  handler: async (args) => {
51
58
  try {
52
59
  const { client } = await resolveClient();
60
+ const poolId = await resolvePool(client, args.poolId);
53
61
  const chainId = args.chainId ?? getChainId();
54
- const data = await getLiquidityInfo(client, args.poolId, args.marketPrice, chainId);
62
+ const data = await getLiquidityInfo(client, poolId, args.marketPrice, chainId);
63
+ if (!data)
64
+ throw new Error(`Liquidity info for ${poolId} not available.`);
55
65
  return { content: [{ type: "text", text: JSON.stringify({ status: "success", data }, (_, v) => typeof v === 'bigint' ? v.toString() : v, 2) }] };
56
66
  }
57
67
  catch (error) {
@@ -3,15 +3,15 @@ import { resolveClient } from "../auth/resolveClient.js";
3
3
  import { searchMarket } from "../services/marketService.js";
4
4
  export const searchMarketTool = {
5
5
  name: "search_market",
6
- description: "Search for an active market by keyword.",
6
+ description: "Search active markets by keyword. Leave keyword empty to list active markets.",
7
7
  schema: {
8
- keyword: z.string().describe('Search keyword, e.g. "BTC", "ETH"'),
8
+ keyword: z.string().optional().describe('Search keyword, e.g. "BTC", "ETH". Leave empty to return active markets.'),
9
9
  limit: z.number().int().positive().optional().describe("Max results (default 100)"),
10
10
  },
11
11
  handler: async (args) => {
12
12
  try {
13
13
  const { client } = await resolveClient();
14
- const activeMarkets = await searchMarket(client, args.keyword, args.limit);
14
+ const activeMarkets = await searchMarket(client, args.keyword ?? "", args.limit ?? 100);
15
15
  return { content: [{ type: "text", text: JSON.stringify({ status: "success", data: activeMarkets }, (_, v) => typeof v === 'bigint' ? v.toString() : v, 2) }] };
16
16
  }
17
17
  catch (error) {
@@ -1,6 +1,14 @@
1
1
  import { decodeErrorSelector } from "./errors.js";
2
+ import { getChainId } from "../auth/resolveClient.js";
2
3
  const TX_HASH_RE = /^0x[0-9a-fA-F]{64}$/;
3
4
  const TX_HASH_KEYS = new Set(["hash", "txHash", "transactionHash"]);
5
+ function getExplorerLink(txHash, chainId) {
6
+ if (chainId === 421614)
7
+ return `https://sepolia.arbiscan.io/tx/${txHash}`;
8
+ if (chainId === 59141)
9
+ return `https://sepolia.lineascan.build/tx/${txHash}`;
10
+ return txHash; // Fallback to just hash
11
+ }
4
12
  function isObject(value) {
5
13
  return !!value && typeof value === "object";
6
14
  }
@@ -59,26 +67,35 @@ function assertSdkCode(result, actionName) {
59
67
  export async function finalizeMutationResult(result, signer, actionName) {
60
68
  assertSdkCode(result, actionName);
61
69
  const txHash = findTxHashDeep(result);
70
+ const chainId = getChainId();
62
71
  if (!txHash) {
63
72
  return { result };
64
73
  }
65
74
  const provider = signer?.provider;
66
- if (!provider?.waitForTransaction) {
67
- return { result, confirmation: { txHash, status: "submitted" } };
68
- }
69
- const receipt = await provider.waitForTransaction(txHash, 1, 120000);
70
- if (!receipt) {
71
- throw new Error(`${actionName} failed: tx not confirmed within timeout (${txHash}).`);
72
- }
73
- if (receipt.status !== 1) {
74
- throw new Error(`${actionName} failed on-chain: tx reverted (${txHash}).`);
75
+ let status = "submitted";
76
+ let receipt = null;
77
+ if (provider?.waitForTransaction) {
78
+ receipt = await provider.waitForTransaction(txHash, 1, 120000);
79
+ if (!receipt) {
80
+ throw new Error(`${actionName} failed: tx not confirmed within timeout (${txHash}).`);
81
+ }
82
+ if (receipt.status !== 1) {
83
+ throw new Error(`${actionName} failed on-chain: tx reverted (${txHash}).`);
84
+ }
85
+ status = "success";
75
86
  }
76
87
  return {
77
- result,
78
- confirmation: {
88
+ summary: {
89
+ action: actionName,
90
+ status: status,
91
+ txHash: txHash,
92
+ explorerUrl: getExplorerLink(txHash, chainId)
93
+ },
94
+ confirmation: receipt ? {
79
95
  txHash,
80
96
  blockNumber: receipt.blockNumber,
81
97
  status: receipt.status,
82
- },
98
+ } : { txHash, status: "submitted" },
99
+ raw: result
83
100
  };
84
101
  }
package/package.json CHANGED
@@ -1,12 +1,15 @@
1
1
  {
2
2
  "name": "@michaleffffff/mcp-trading-server",
3
- "version": "2.9.2",
3
+ "version": "3.0.0",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "myx-mcp": "dist/server.js"
7
7
  },
8
8
  "files": [
9
- "dist"
9
+ "dist",
10
+ "README.md",
11
+ "TOOL_EXAMPLES.md",
12
+ "CHANGELOG.md"
10
13
  ],
11
14
  "scripts": {
12
15
  "build": "rm -rf dist && tsc",
@@ -1,17 +0,0 @@
1
- import { resolveClient } from "../auth/resolveClient.js";
2
- import { getBalances } from "../services/balanceService.js";
3
- export const getBalancesTool = {
4
- name: "get_balances",
5
- description: "Get the account balances for different tokens.",
6
- schema: {},
7
- handler: async () => {
8
- try {
9
- const { client, address } = await resolveClient();
10
- const data = await getBalances(client, address);
11
- return { content: [{ type: "text", text: JSON.stringify({ status: "success", data }, (_, v) => typeof v === 'bigint' ? v.toString() : v, 2) }] };
12
- }
13
- catch (error) {
14
- return { content: [{ type: "text", text: `Error: ${error.message}` }], isError: true };
15
- }
16
- },
17
- };