@zebpay_rajesh/zebpay-mcp-server 0.1.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.

Potentially problematic release.


This version of @zebpay_rajesh/zebpay-mcp-server might be problematic. Click here for more details.

Files changed (120) hide show
  1. package/.env.example +14 -0
  2. package/README.md +223 -0
  3. package/dist/__tests__/errors.test.d.ts +5 -0
  4. package/dist/__tests__/errors.test.js +147 -0
  5. package/dist/__tests__/errors.test.js.map +1 -0
  6. package/dist/__tests__/prompts.test.d.ts +1 -0
  7. package/dist/__tests__/prompts.test.js +73 -0
  8. package/dist/__tests__/prompts.test.js.map +1 -0
  9. package/dist/__tests__/resources.test.d.ts +1 -0
  10. package/dist/__tests__/resources.test.js +79 -0
  11. package/dist/__tests__/resources.test.js.map +1 -0
  12. package/dist/__tests__/validation.test.d.ts +15 -0
  13. package/dist/__tests__/validation.test.js +64 -0
  14. package/dist/__tests__/validation.test.js.map +1 -0
  15. package/dist/config.d.ts +19 -0
  16. package/dist/config.js +81 -0
  17. package/dist/config.js.map +1 -0
  18. package/dist/http/httpClient.d.ts +40 -0
  19. package/dist/http/httpClient.js +341 -0
  20. package/dist/http/httpClient.js.map +1 -0
  21. package/dist/index.d.ts +1 -0
  22. package/dist/index.js +60 -0
  23. package/dist/index.js.map +1 -0
  24. package/dist/mcp/errors.d.ts +21 -0
  25. package/dist/mcp/errors.js +214 -0
  26. package/dist/mcp/errors.js.map +1 -0
  27. package/dist/mcp/logging.d.ts +21 -0
  28. package/dist/mcp/logging.js +241 -0
  29. package/dist/mcp/logging.js.map +1 -0
  30. package/dist/mcp/prompts.d.ts +9 -0
  31. package/dist/mcp/prompts.js +165 -0
  32. package/dist/mcp/prompts.js.map +1 -0
  33. package/dist/mcp/resources.d.ts +9 -0
  34. package/dist/mcp/resources.js +125 -0
  35. package/dist/mcp/resources.js.map +1 -0
  36. package/dist/mcp/tools_futures.d.ts +5 -0
  37. package/dist/mcp/tools_futures.js +694 -0
  38. package/dist/mcp/tools_futures.js.map +1 -0
  39. package/dist/mcp/tools_spot.d.ts +11 -0
  40. package/dist/mcp/tools_spot.js +2225 -0
  41. package/dist/mcp/tools_spot.js.map +1 -0
  42. package/dist/private/FuturesClient.d.ts +57 -0
  43. package/dist/private/FuturesClient.js +181 -0
  44. package/dist/private/FuturesClient.js.map +1 -0
  45. package/dist/private/SpotClient.d.ts +44 -0
  46. package/dist/private/SpotClient.js +201 -0
  47. package/dist/private/SpotClient.js.map +1 -0
  48. package/dist/private/ZebpayAPI.d.ts +19 -0
  49. package/dist/private/ZebpayAPI.js +172 -0
  50. package/dist/private/ZebpayAPI.js.map +1 -0
  51. package/dist/public/PublicClient.d.ts +79 -0
  52. package/dist/public/PublicClient.js +283 -0
  53. package/dist/public/PublicClient.js.map +1 -0
  54. package/dist/public/PublicFuturesClient.d.ts +27 -0
  55. package/dist/public/PublicFuturesClient.js +187 -0
  56. package/dist/public/PublicFuturesClient.js.map +1 -0
  57. package/dist/security/credentials.d.ts +42 -0
  58. package/dist/security/credentials.js +80 -0
  59. package/dist/security/credentials.js.map +1 -0
  60. package/dist/security/signing.d.ts +33 -0
  61. package/dist/security/signing.js +56 -0
  62. package/dist/security/signing.js.map +1 -0
  63. package/dist/types/responses.d.ts +130 -0
  64. package/dist/types/responses.js +6 -0
  65. package/dist/types/responses.js.map +1 -0
  66. package/dist/utils/cache.d.ts +29 -0
  67. package/dist/utils/cache.js +72 -0
  68. package/dist/utils/cache.js.map +1 -0
  69. package/dist/utils/fileLogger.d.ts +10 -0
  70. package/dist/utils/fileLogger.js +81 -0
  71. package/dist/utils/fileLogger.js.map +1 -0
  72. package/dist/utils/metrics.d.ts +35 -0
  73. package/dist/utils/metrics.js +94 -0
  74. package/dist/utils/metrics.js.map +1 -0
  75. package/dist/utils/responseFormatter.d.ts +93 -0
  76. package/dist/utils/responseFormatter.js +268 -0
  77. package/dist/utils/responseFormatter.js.map +1 -0
  78. package/dist/validation/schemas.d.ts +70 -0
  79. package/dist/validation/schemas.js +48 -0
  80. package/dist/validation/schemas.js.map +1 -0
  81. package/dist/validation/validators.d.ts +28 -0
  82. package/dist/validation/validators.js +129 -0
  83. package/dist/validation/validators.js.map +1 -0
  84. package/docs/LOGGING.md +371 -0
  85. package/docs/zebpay-ai-trading-beginner.png +0 -0
  86. package/mcp-config.json.example +20 -0
  87. package/package.json +54 -0
  88. package/scripts/README.md +103 -0
  89. package/scripts/clear-logs.js +52 -0
  90. package/scripts/log-stats.js +264 -0
  91. package/scripts/log-viewer.js +288 -0
  92. package/server.json +31 -0
  93. package/src/__tests__/errors.test.ts +180 -0
  94. package/src/__tests__/prompts.test.ts +89 -0
  95. package/src/__tests__/resources.test.ts +95 -0
  96. package/src/__tests__/validation.test.ts +88 -0
  97. package/src/config.ts +108 -0
  98. package/src/http/httpClient.ts +398 -0
  99. package/src/index.ts +71 -0
  100. package/src/mcp/errors.ts +262 -0
  101. package/src/mcp/logging.ts +284 -0
  102. package/src/mcp/prompts.ts +206 -0
  103. package/src/mcp/resources.ts +163 -0
  104. package/src/mcp/tools_futures.ts +874 -0
  105. package/src/mcp/tools_spot.ts +2702 -0
  106. package/src/private/FuturesClient.ts +189 -0
  107. package/src/private/SpotClient.ts +250 -0
  108. package/src/private/ZebpayAPI.ts +205 -0
  109. package/src/public/PublicClient.ts +381 -0
  110. package/src/public/PublicFuturesClient.ts +228 -0
  111. package/src/security/credentials.ts +114 -0
  112. package/src/security/signing.ts +98 -0
  113. package/src/types/responses.ts +146 -0
  114. package/src/utils/cache.ts +90 -0
  115. package/src/utils/fileLogger.ts +88 -0
  116. package/src/utils/metrics.ts +135 -0
  117. package/src/utils/responseFormatter.ts +361 -0
  118. package/src/validation/schemas.ts +66 -0
  119. package/src/validation/validators.ts +189 -0
  120. package/tsconfig.json +21 -0
@@ -0,0 +1,206 @@
1
+ /*
2
+ MCP prompt registrations for common Zebpay trading workflows.
3
+ */
4
+
5
+ import { z } from "zod";
6
+ import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
7
+ import { SpotClient } from "../private/SpotClient.js";
8
+ import { PublicClient } from "../public/PublicClient.js";
9
+ import { AppConfig } from "../config.js";
10
+
11
+ /**
12
+ * Registers MCP prompts for common Zebpay trading workflows.
13
+ * Prompts help LLMs understand common use cases and provide structured guidance.
14
+ */
15
+ export function registerPrompts(
16
+ server: McpServer,
17
+ spot: SpotClient | null,
18
+ publicClient: PublicClient,
19
+ config: AppConfig
20
+ ): void {
21
+ // Prompt: Check Balance Before Trading
22
+ if (spot) {
23
+ try {
24
+ server.prompt(
25
+ "check-balance-before-trade",
26
+ "Check account balance before placing a trade to ensure sufficient funds are available. This prompt guides you through verifying balance and understanding trading requirements.",
27
+ {
28
+ symbol: z.string().describe(
29
+ "Trading pair symbol in format BASE-QUOTE (e.g., 'BTC-INR', 'ETH-INR'). The symbol determines which currencies to check."
30
+ ),
31
+ side: z.enum(["BUY", "SELL"]).describe(
32
+ "Order side: 'BUY' checks quote currency balance (e.g., INR for BTC-INR), 'SELL' checks base currency balance (e.g., BTC for BTC-INR)."
33
+ ),
34
+ },
35
+ async ({ symbol, side }) => {
36
+ const normalizedSymbol = symbol.trim().toUpperCase();
37
+ const [baseCurrency, quoteCurrency] = normalizedSymbol.split("-");
38
+ const currencyToCheck = side === "BUY" ? quoteCurrency : baseCurrency;
39
+
40
+ return {
41
+ description: `Check balance for ${currencyToCheck} before ${side === "BUY" ? "buying" : "selling"} ${baseCurrency}`,
42
+ messages: [
43
+ {
44
+ role: "user",
45
+ content: {
46
+ type: "text",
47
+ text: `I want to ${side === "BUY" ? "buy" : "sell"} ${normalizedSymbol}.
48
+
49
+ Please:
50
+ 1. Check my ${currencyToCheck} balance using zebpay_spot_getBalance with currencies="${currencyToCheck}"
51
+ 2. Get the current price of ${normalizedSymbol} using zebpay_public_getTicker with symbol="${normalizedSymbol}"
52
+ 3. Calculate if I have sufficient funds for the trade
53
+ 4. If sufficient, place the order using zebpay_spot_placeMarketOrder
54
+ 5. If insufficient, inform me of the shortfall
55
+
56
+ For ${side === "BUY" ? "buy" : "sell"} orders, I need ${side === "BUY" ? quoteCurrency : baseCurrency} balance.`,
57
+ },
58
+ },
59
+ ],
60
+ };
61
+ }
62
+ );
63
+ console.error("Registered prompt: check-balance-before-trade");
64
+ } catch (error) {
65
+ console.error("Error registering check-balance-before-trade prompt:", error);
66
+ }
67
+ }
68
+
69
+ // Prompt: Market Analysis
70
+ try {
71
+ server.prompt(
72
+ "analyze-market",
73
+ "Perform comprehensive market analysis for a trading pair, including current price, order book depth, recent trades, and price history.",
74
+ {
75
+ symbol: z.string().describe(
76
+ "Trading pair symbol in format BASE-QUOTE (e.g., 'BTC-INR', 'ETH-INR') to analyze."
77
+ ),
78
+ },
79
+ async ({ symbol }) => {
80
+ const normalizedSymbol = symbol.trim().toUpperCase();
81
+
82
+ return {
83
+ description: `Analyze market conditions for ${normalizedSymbol}`,
84
+ messages: [
85
+ {
86
+ role: "user",
87
+ content: {
88
+ type: "text",
89
+ text: `Please provide a comprehensive market analysis for ${normalizedSymbol}:
90
+
91
+ 1. Current Price: Use zebpay_public_getTicker with symbol="${normalizedSymbol}" to get current price and 24h statistics
92
+ 2. Order Book: Use zebpay_public_getOrderBook with symbol="${normalizedSymbol}" to analyze market depth and liquidity
93
+ 3. Recent Trades: Use zebpay_public_getTrades with symbol="${normalizedSymbol}" to see recent trading activity
94
+ 4. Price History: Use zebpay_public_getKlines with symbol="${normalizedSymbol}" to get historical price data (you'll need to specify interval, startTime, and endTime)
95
+
96
+ Please summarize:
97
+ - Current price and 24h change
98
+ - Market depth (spread, liquidity)
99
+ - Recent trading activity
100
+ - Price trends (if historical data is available)`,
101
+ },
102
+ },
103
+ ],
104
+ };
105
+ }
106
+ );
107
+ console.error("Registered prompt: analyze-market");
108
+ } catch (error) {
109
+ console.error("Error registering analyze-market prompt:", error);
110
+ }
111
+
112
+ // Prompt: Compare Multiple Trading Pairs
113
+ try {
114
+ server.prompt(
115
+ "compare-trading-pairs",
116
+ "Compare multiple trading pairs side-by-side to help make trading decisions. Shows prices, volumes, and price changes for multiple symbols.",
117
+ {
118
+ symbols: z.string().describe(
119
+ "Comma-separated list of trading pair symbols (e.g., 'BTC-INR,ETH-INR,USDT-INR') to compare."
120
+ ),
121
+ },
122
+ async ({ symbols }) => {
123
+ const symbolList = symbols
124
+ .split(",")
125
+ .map((s) => s.trim().toUpperCase())
126
+ .filter(Boolean);
127
+
128
+ return {
129
+ description: `Compare trading pairs: ${symbolList.join(", ")}`,
130
+ messages: [
131
+ {
132
+ role: "user",
133
+ content: {
134
+ type: "text",
135
+ text: `Please compare the following trading pairs: ${symbolList.join(", ")}
136
+
137
+ For each symbol, use zebpay_public_getTicker to get:
138
+ - Current price
139
+ - 24h price change (absolute and percentage)
140
+ - 24h trading volume
141
+ - 24h high and low prices
142
+
143
+ Present the comparison in a clear table format showing:
144
+ 1. Symbol
145
+ 2. Current Price
146
+ 3. 24h Change (%)
147
+ 4. 24h Volume
148
+ 5. 24h High/Low
149
+
150
+ This will help me understand which pairs are most active and have the best trading opportunities.`,
151
+ },
152
+ },
153
+ ],
154
+ };
155
+ }
156
+ );
157
+ console.error("Registered prompt: compare-trading-pairs");
158
+ } catch (error) {
159
+ console.error("Error registering compare-trading-pairs prompt:", error);
160
+ }
161
+
162
+ // Prompt: Get Exchange Information
163
+ try {
164
+ server.prompt(
165
+ "get-exchange-info",
166
+ "Retrieve comprehensive exchange information including available trading pairs, trading rules, order limits, and supported currencies.",
167
+ {},
168
+ async () => {
169
+ return {
170
+ description: "Get Zebpay exchange information and trading rules",
171
+ messages: [
172
+ {
173
+ role: "user",
174
+ content: {
175
+ type: "text",
176
+ text: `Please provide comprehensive information about the Zebpay exchange:
177
+
178
+ 1. Exchange Information: Use zebpay_public_getExchangeInfo to get:
179
+ - Available trading pairs
180
+ - Trading rules and limits
181
+ - Order types supported
182
+ - Exchange-wide settings
183
+
184
+ 2. Supported Currencies: Use zebpay_public_getCurrencies to get:
185
+ - List of all supported currencies
186
+ - Currency details (precision, type, etc.)
187
+ - Withdrawal/deposit settings
188
+ - Supported blockchain chains
189
+
190
+ Please summarize:
191
+ - Total number of trading pairs
192
+ - Major trading pairs available
193
+ - Supported currencies
194
+ - Key trading rules and limits`,
195
+ },
196
+ },
197
+ ],
198
+ };
199
+ }
200
+ );
201
+ console.error("Registered prompt: get-exchange-info");
202
+ } catch (error) {
203
+ console.error("Error registering get-exchange-info prompt:", error);
204
+ }
205
+ }
206
+
@@ -0,0 +1,163 @@
1
+ /*
2
+ MCP resource registrations for Zebpay exchange data.
3
+ */
4
+
5
+ import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
6
+ import { PublicClient } from "../public/PublicClient.js";
7
+ import { SpotClient } from "../private/SpotClient.js";
8
+ import { AppConfig } from "../config.js";
9
+ import { createInternalError } from "./errors.js";
10
+
11
+ /**
12
+ * Registers MCP resources for Zebpay exchange data.
13
+ * Resources provide read-only access to exchange information that can be referenced by LLMs.
14
+ */
15
+ export function registerResources(
16
+ server: McpServer,
17
+ publicClient: PublicClient,
18
+ spot: SpotClient | null,
19
+ config: AppConfig
20
+ ): void {
21
+ // Resource: Exchange Information
22
+ try {
23
+ server.resource(
24
+ "exchange-info",
25
+ "zebpay://exchange/info",
26
+ {
27
+ title: "Exchange Information",
28
+ description: "Current exchange information including available trading pairs, trading rules, order limits, and other exchange metadata. This resource is updated periodically.",
29
+ mimeType: "application/json",
30
+ },
31
+ async () => {
32
+ try {
33
+ const data = await publicClient.getExchangeInfo();
34
+ return {
35
+ contents: [
36
+ {
37
+ uri: "zebpay://exchange/info",
38
+ mimeType: "application/json",
39
+ text: JSON.stringify(data, null, 2),
40
+ },
41
+ ],
42
+ };
43
+ } catch (error) {
44
+ throw createInternalError(
45
+ `Failed to fetch exchange information: ${error instanceof Error ? error.message : String(error)}`,
46
+ {}
47
+ );
48
+ }
49
+ }
50
+ );
51
+ console.error("Registered resource: zebpay://exchange/info");
52
+ } catch (error) {
53
+ console.error("Error registering exchange-info resource:", error);
54
+ }
55
+
56
+ // Resource: Supported Currencies
57
+ try {
58
+ server.resource(
59
+ "currencies",
60
+ "zebpay://currencies",
61
+ {
62
+ title: "Supported Currencies",
63
+ description: "List of all supported currencies and tokens on Zebpay exchange, including precision, type (crypto/fiat), withdrawal/deposit settings, supported blockchain chains, fees, and limits.",
64
+ mimeType: "application/json",
65
+ },
66
+ async () => {
67
+ try {
68
+ const data = await publicClient.getCurrencies();
69
+ return {
70
+ contents: [
71
+ {
72
+ uri: "zebpay://currencies",
73
+ mimeType: "application/json",
74
+ text: JSON.stringify(data, null, 2),
75
+ },
76
+ ],
77
+ };
78
+ } catch (error) {
79
+ throw createInternalError(
80
+ `Failed to fetch currencies: ${error instanceof Error ? error.message : String(error)}`,
81
+ {}
82
+ );
83
+ }
84
+ }
85
+ );
86
+ console.error("Registered resource: zebpay://currencies");
87
+ } catch (error) {
88
+ console.error("Error registering currencies resource:", error);
89
+ }
90
+
91
+ // Resource: All Tickers (Market Prices)
92
+ try {
93
+ server.resource(
94
+ "all-tickers",
95
+ "zebpay://market/tickers",
96
+ {
97
+ title: "All Market Tickers",
98
+ description: "Current ticker/price information for all trading pairs on Zebpay exchange, including last price, bid/ask, 24h high/low, volume, and price changes.",
99
+ mimeType: "application/json",
100
+ },
101
+ async () => {
102
+ try {
103
+ const data = await publicClient.getAllTickers();
104
+ return {
105
+ contents: [
106
+ {
107
+ uri: "zebpay://market/tickers",
108
+ mimeType: "application/json",
109
+ text: JSON.stringify(data, null, 2),
110
+ },
111
+ ],
112
+ };
113
+ } catch (error) {
114
+ throw createInternalError(
115
+ `Failed to fetch all tickers: ${error instanceof Error ? error.message : String(error)}`,
116
+ {}
117
+ );
118
+ }
119
+ }
120
+ );
121
+ console.error("Registered resource: zebpay://market/tickers");
122
+ } catch (error) {
123
+ console.error("Error registering all-tickers resource:", error);
124
+ }
125
+
126
+ // Resource: User Balance (only if authenticated)
127
+ if (spot) {
128
+ try {
129
+ server.resource(
130
+ "balance",
131
+ "zebpay://account/balance",
132
+ {
133
+ title: "Account Balance",
134
+ description: "Current balance of cryptocurrencies and fiat currencies in the user's spot trading account. Shows both available and locked balances.",
135
+ mimeType: "application/json",
136
+ },
137
+ async () => {
138
+ try {
139
+ const data = await spot.getBalance();
140
+ return {
141
+ contents: [
142
+ {
143
+ uri: "zebpay://account/balance",
144
+ mimeType: "application/json",
145
+ text: JSON.stringify(data, null, 2),
146
+ },
147
+ ],
148
+ };
149
+ } catch (error) {
150
+ throw createInternalError(
151
+ `Failed to fetch balance: ${error instanceof Error ? error.message : String(error)}`,
152
+ {}
153
+ );
154
+ }
155
+ }
156
+ );
157
+ console.error("Registered resource: zebpay://account/balance");
158
+ } catch (error) {
159
+ console.error("Error registering balance resource:", error);
160
+ }
161
+ }
162
+ }
163
+