@michaleffffff/mcp-trading-server 2.9.2 → 2.9.9

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/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.9.2" }, { capabilities: { tools: {}, resources: {}, prompts: {} } });
84
+ const server = new Server({ name: "myx-mcp-trading-server", version: "2.9.9" }, { 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.9.2 running (stdio, pure on-chain, prod ready)");
184
+ logger.info("🚀 MYX Trading MCP Server v2.9.9 running (stdio, pure on-chain, prod ready)");
185
185
  }
186
186
  main().catch((err) => {
187
187
  logger.error("Fatal Server Startup Error", err);
@@ -128,7 +128,13 @@ export async function resolvePool(client, poolId, keyword) {
128
128
  const base = String(row?.baseSymbol ?? "").toUpperCase();
129
129
  const pair = String(row?.baseQuoteSymbol ?? "").toUpperCase();
130
130
  const id = String(row?.poolId ?? row?.pool_id ?? "").toUpperCase();
131
- return base === searchKey || pair.includes(searchKey) || id === searchKey;
131
+ const baseToken = String(row?.baseToken ?? row?.base_token ?? "").toUpperCase();
132
+ const quoteToken = String(row?.quoteToken ?? row?.quote_token ?? "").toUpperCase();
133
+ return base === searchKey ||
134
+ pair.includes(searchKey) ||
135
+ id === searchKey ||
136
+ baseToken === searchKey ||
137
+ quoteToken === searchKey;
132
138
  });
133
139
  if (match) {
134
140
  return String(match.poolId ?? match.pool_id);
@@ -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) {
@@ -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,6 +1,6 @@
1
1
  {
2
2
  "name": "@michaleffffff/mcp-trading-server",
3
- "version": "2.9.2",
3
+ "version": "2.9.9",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "myx-mcp": "dist/server.js"