@gala-chain/launchpad-mcp-server 1.14.0 → 1.14.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.
Files changed (75) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/README.md +1 -1
  3. package/dist/generated/version.d.ts +1 -1
  4. package/dist/generated/version.js +1 -1
  5. package/dist/schemas/common-schemas.d.ts +1 -1
  6. package/dist/schemas/common-schemas.d.ts.map +1 -1
  7. package/dist/schemas/common-schemas.js +1 -0
  8. package/dist/schemas/common-schemas.js.map +1 -1
  9. package/dist/tools/pools/fetchPriceHistory.js +2 -2
  10. package/dist/tools/pools/fetchPriceHistory.js.map +1 -1
  11. package/dist/tools/utils/explainSdkUsage.d.ts.map +1 -1
  12. package/dist/tools/utils/explainSdkUsage.js +441 -20
  13. package/dist/tools/utils/explainSdkUsage.js.map +1 -1
  14. package/dist/utils/constraints.d.ts +9 -3
  15. package/dist/utils/constraints.d.ts.map +1 -1
  16. package/dist/utils/constraints.js +9 -1
  17. package/dist/utils/constraints.js.map +1 -1
  18. package/docs/AI-AGENT-PATTERNS.md +555 -0
  19. package/docs/CONSTRAINTS-REFERENCE.md +454 -0
  20. package/docs/PROMPT-TOOL-MAPPING.md +352 -0
  21. package/docs/examples/default-values-pattern.md +240 -0
  22. package/docs/examples/tool-factory-pattern.md +217 -0
  23. package/jest.config.js +94 -0
  24. package/package.json +2 -2
  25. package/src/__tests__/integration/fetchTokenDetails.integration.test.ts +258 -0
  26. package/src/__tests__/integration/poolTools.integration.test.ts +185 -0
  27. package/src/constants/mcpToolNames.ts +141 -0
  28. package/src/index.ts +19 -0
  29. package/src/prompts/__tests__/promptStructure.test.ts +114 -0
  30. package/src/prompts/__tests__/registry.test.ts +145 -0
  31. package/src/prompts/analysis.ts +429 -0
  32. package/src/prompts/index.ts +127 -0
  33. package/src/prompts/portfolio.ts +242 -0
  34. package/src/prompts/trading.ts +191 -0
  35. package/src/prompts/utility.ts +43 -0
  36. package/src/prompts/utils/workflowTemplates.ts +344 -0
  37. package/src/schemas/common-schemas.ts +393 -0
  38. package/src/scripts/test-all-prompts.ts +184 -0
  39. package/src/server.ts +241 -0
  40. package/src/tools/balance/index.ts +174 -0
  41. package/src/tools/creation/index.ts +182 -0
  42. package/src/tools/index.ts +80 -0
  43. package/src/tools/pools/fetchAllPools.ts +47 -0
  44. package/src/tools/pools/fetchAllPriceHistory.ts +103 -0
  45. package/src/tools/pools/fetchPoolDetails.ts +27 -0
  46. package/src/tools/pools/fetchPoolDetailsForCalculation.ts +22 -0
  47. package/src/tools/pools/fetchPools.ts +47 -0
  48. package/src/tools/pools/fetchPriceHistory.ts +108 -0
  49. package/src/tools/pools/fetchTokenDetails.ts +77 -0
  50. package/src/tools/pools/index.ts +246 -0
  51. package/src/tools/social/index.ts +64 -0
  52. package/src/tools/trading/index.ts +605 -0
  53. package/src/tools/transfers/index.ts +75 -0
  54. package/src/tools/utils/clearCache.ts +36 -0
  55. package/src/tools/utils/createWallet.ts +19 -0
  56. package/src/tools/utils/explainSdkUsage.ts +1277 -0
  57. package/src/tools/utils/getAddress.ts +12 -0
  58. package/src/tools/utils/getCacheInfo.ts +14 -0
  59. package/src/tools/utils/getConfig.ts +11 -0
  60. package/src/tools/utils/getEthereumAddress.ts +12 -0
  61. package/src/tools/utils/getUrlByTokenName.ts +12 -0
  62. package/src/tools/utils/getVersion.ts +25 -0
  63. package/src/tools/utils/index.ts +27 -0
  64. package/src/tools/utils/isTokenGraduated.ts +16 -0
  65. package/src/types/mcp.ts +72 -0
  66. package/src/utils/__tests__/validation.test.ts +147 -0
  67. package/src/utils/constraints.ts +155 -0
  68. package/src/utils/default-values.ts +208 -0
  69. package/src/utils/error-handler.ts +69 -0
  70. package/src/utils/error-templates.ts +273 -0
  71. package/src/utils/response-formatter.ts +51 -0
  72. package/src/utils/tool-factory.ts +257 -0
  73. package/src/utils/tool-registry.ts +296 -0
  74. package/src/utils/validation.ts +336 -0
  75. package/tsconfig.json +23 -0
@@ -0,0 +1,336 @@
1
+ /**
2
+ * Validation Utilities for MCP Prompts
3
+ *
4
+ * Input validation functions for slash command arguments.
5
+ * Prevents malformed inputs and provides clear error messages.
6
+ */
7
+
8
+ /**
9
+ * Validation error class for better error handling
10
+ */
11
+ export class ValidationError extends Error {
12
+ constructor(
13
+ public field: string,
14
+ message: string
15
+ ) {
16
+ super(`Validation error for '${field}': ${message}`);
17
+ this.name = 'ValidationError';
18
+ }
19
+ }
20
+
21
+ /**
22
+ * Validate token name format
23
+ *
24
+ * Token names must be 2-20 characters, alphanumeric with hyphens and underscores.
25
+ *
26
+ * @param name - Token name to validate
27
+ * @param fieldName - Field name for error messages (default: 'tokenName')
28
+ * @throws {ValidationError} If token name is invalid
29
+ *
30
+ * @example
31
+ * ```typescript
32
+ * validateTokenName('anime'); // ✅ Valid
33
+ * validateTokenName('test-123'); // ✅ Valid
34
+ * validateTokenName('my_token'); // ✅ Valid
35
+ * validateTokenName('a'); // ❌ Throws: too short
36
+ * validateTokenName('token@#$'); // ❌ Throws: invalid characters
37
+ * ```
38
+ */
39
+ export function validateTokenName(name: string, fieldName = 'tokenName'): void {
40
+ if (!name || typeof name !== 'string') {
41
+ throw new ValidationError(fieldName, 'Token name is required');
42
+ }
43
+
44
+ if (name.length < 2 || name.length > 20) {
45
+ throw new ValidationError(
46
+ fieldName,
47
+ `Token name must be 2-20 characters (got ${name.length})`
48
+ );
49
+ }
50
+
51
+ const tokenNameRegex = /^[a-zA-Z0-9-_]+$/;
52
+ if (!tokenNameRegex.test(name)) {
53
+ throw new ValidationError(
54
+ fieldName,
55
+ 'Token name can only contain letters, numbers, hyphens, and underscores'
56
+ );
57
+ }
58
+ }
59
+
60
+ /**
61
+ * Validate numeric amount
62
+ *
63
+ * Amounts must be positive numbers (integers or decimals).
64
+ *
65
+ * @param amount - Amount to validate (string or number)
66
+ * @param fieldName - Field name for error messages
67
+ * @throws {ValidationError} If amount is invalid
68
+ *
69
+ * @example
70
+ * ```typescript
71
+ * validateNumericAmount('100', 'galaAmount'); // ✅ Valid
72
+ * validateNumericAmount('99.5', 'tokenAmount'); // ✅ Valid
73
+ * validateNumericAmount('-5', 'amount'); // ❌ Throws: negative
74
+ * validateNumericAmount('abc', 'amount'); // ❌ Throws: not a number
75
+ * ```
76
+ */
77
+ export function validateNumericAmount(
78
+ amount: string | number,
79
+ fieldName: string
80
+ ): void {
81
+ if (amount === null || amount === undefined || amount === '') {
82
+ throw new ValidationError(fieldName, 'Amount is required');
83
+ }
84
+
85
+ const numAmount = typeof amount === 'string' ? parseFloat(amount) : amount;
86
+
87
+ if (isNaN(numAmount)) {
88
+ throw new ValidationError(fieldName, `Amount must be a valid number (got: ${amount})`);
89
+ }
90
+
91
+ if (numAmount <= 0) {
92
+ throw new ValidationError(
93
+ fieldName,
94
+ `Amount must be positive (got: ${numAmount})`
95
+ );
96
+ }
97
+
98
+ if (!isFinite(numAmount)) {
99
+ throw new ValidationError(fieldName, 'Amount must be a finite number');
100
+ }
101
+ }
102
+
103
+ /**
104
+ * Validate slippage tolerance percentage
105
+ *
106
+ * Slippage must be between 0.01% and 100%.
107
+ *
108
+ * @param slippage - Slippage percentage to validate
109
+ * @param fieldName - Field name for error messages (default: 'slippage')
110
+ * @throws {ValidationError} If slippage is invalid
111
+ *
112
+ * @example
113
+ * ```typescript
114
+ * validateSlippage('1'); // ✅ Valid (1%)
115
+ * validateSlippage('0.5'); // ✅ Valid (0.5%)
116
+ * validateSlippage('50'); // ✅ Valid (50%)
117
+ * validateSlippage('0'); // ❌ Throws: too low
118
+ * validateSlippage('150'); // ❌ Throws: too high
119
+ * ```
120
+ */
121
+ export function validateSlippage(
122
+ slippage: string | number,
123
+ fieldName = 'slippage'
124
+ ): void {
125
+ if (slippage === null || slippage === undefined || slippage === '') {
126
+ throw new ValidationError(fieldName, 'Slippage is required');
127
+ }
128
+
129
+ const numSlippage = typeof slippage === 'string' ? parseFloat(slippage) : slippage;
130
+
131
+ if (isNaN(numSlippage)) {
132
+ throw new ValidationError(
133
+ fieldName,
134
+ `Slippage must be a valid number (got: ${slippage})`
135
+ );
136
+ }
137
+
138
+ if (numSlippage < 0.01 || numSlippage > 100) {
139
+ throw new ValidationError(
140
+ fieldName,
141
+ `Slippage must be between 0.01% and 100% (got: ${numSlippage}%)`
142
+ );
143
+ }
144
+ }
145
+
146
+ /**
147
+ * Validate wallet address format
148
+ *
149
+ * Supports both GalaChain format (eth|0x...) and standard Ethereum format (0x...).
150
+ *
151
+ * @param address - Wallet address to validate
152
+ * @param fieldName - Field name for error messages (default: 'address')
153
+ * @throws {ValidationError} If address is invalid
154
+ *
155
+ * @example
156
+ * ```typescript
157
+ * validateAddress('eth|0x1234567890abcdef1234567890abcdef12345678'); // ✅ Valid
158
+ * validateAddress('0x1234567890abcdef1234567890abcdef12345678'); // ✅ Valid
159
+ * validateAddress('invalid'); // ❌ Throws: invalid format
160
+ * ```
161
+ */
162
+ export function validateAddress(address: string, fieldName = 'address'): void {
163
+ if (!address || typeof address !== 'string') {
164
+ throw new ValidationError(fieldName, 'Address is required');
165
+ }
166
+
167
+ // GalaChain format: eth|0x{40 hex chars}
168
+ const galachainRegex = /^eth\|0x[a-fA-F0-9]{40}$/;
169
+ // Standard Ethereum format: 0x{40 hex chars}
170
+ const ethereumRegex = /^0x[a-fA-F0-9]{40}$/;
171
+
172
+ if (!galachainRegex.test(address) && !ethereumRegex.test(address)) {
173
+ throw new ValidationError(
174
+ fieldName,
175
+ 'Address must be in GalaChain format (eth|0x...) or Ethereum format (0x...)'
176
+ );
177
+ }
178
+ }
179
+
180
+ /**
181
+ * Validate token symbol format
182
+ *
183
+ * Symbols must be 1-8 uppercase letters.
184
+ *
185
+ * @param symbol - Token symbol to validate
186
+ * @param fieldName - Field name for error messages (default: 'symbol')
187
+ * @throws {ValidationError} If symbol is invalid
188
+ *
189
+ * @example
190
+ * ```typescript
191
+ * validateTokenSymbol('GALA'); // ✅ Valid
192
+ * validateTokenSymbol('TEST'); // ✅ Valid
193
+ * validateTokenSymbol('test'); // ❌ Throws: must be uppercase
194
+ * validateTokenSymbol('TOOLONG123'); // ❌ Throws: too long
195
+ * ```
196
+ */
197
+ export function validateTokenSymbol(symbol: string, fieldName = 'symbol'): void {
198
+ if (!symbol || typeof symbol !== 'string') {
199
+ throw new ValidationError(fieldName, 'Symbol is required');
200
+ }
201
+
202
+ if (symbol.length < 1 || symbol.length > 8) {
203
+ throw new ValidationError(
204
+ fieldName,
205
+ `Symbol must be 1-8 characters (got ${symbol.length})`
206
+ );
207
+ }
208
+
209
+ const symbolRegex = /^[A-Z]+$/;
210
+ if (!symbolRegex.test(symbol)) {
211
+ throw new ValidationError(
212
+ fieldName,
213
+ 'Symbol must be uppercase letters only (A-Z)'
214
+ );
215
+ }
216
+ }
217
+
218
+ /**
219
+ * Validate pagination limit
220
+ *
221
+ * Limits must be positive integers within reasonable range (1-100).
222
+ *
223
+ * @param limit - Pagination limit to validate
224
+ * @param max - Maximum allowed limit (default: 100)
225
+ * @param fieldName - Field name for error messages (default: 'limit')
226
+ * @throws {ValidationError} If limit is invalid
227
+ *
228
+ * @example
229
+ * ```typescript
230
+ * validatePaginationLimit('20'); // ✅ Valid
231
+ * validatePaginationLimit('1'); // ✅ Valid
232
+ * validatePaginationLimit('0'); // ❌ Throws: too low
233
+ * validatePaginationLimit('150'); // ❌ Throws: too high
234
+ * ```
235
+ */
236
+ export function validatePaginationLimit(
237
+ limit: string | number,
238
+ max = 100,
239
+ fieldName = 'limit'
240
+ ): void {
241
+ if (limit === null || limit === undefined || limit === '') {
242
+ throw new ValidationError(fieldName, 'Limit is required');
243
+ }
244
+
245
+ const numLimit = typeof limit === 'string' ? parseInt(limit, 10) : limit;
246
+
247
+ if (isNaN(numLimit) || !Number.isInteger(numLimit)) {
248
+ throw new ValidationError(
249
+ fieldName,
250
+ `Limit must be a valid integer (got: ${limit})`
251
+ );
252
+ }
253
+
254
+ if (numLimit < 1 || numLimit > max) {
255
+ throw new ValidationError(
256
+ fieldName,
257
+ `Limit must be between 1 and ${max} (got: ${numLimit})`
258
+ );
259
+ }
260
+ }
261
+
262
+ /**
263
+ * Validate comma-separated token list
264
+ *
265
+ * For batch operations that accept multiple token names.
266
+ *
267
+ * @param tokens - Comma-separated token names
268
+ * @param fieldName - Field name for error messages (default: 'tokens')
269
+ * @throws {ValidationError} If token list is invalid
270
+ *
271
+ * @example
272
+ * ```typescript
273
+ * validateTokenList('anime,test,dragon'); // ✅ Valid
274
+ * validateTokenList('token1'); // ✅ Valid (single token)
275
+ * validateTokenList(''); // ❌ Throws: empty list
276
+ * validateTokenList('token1,invalid@#$'); // ❌ Throws: invalid token name
277
+ * ```
278
+ */
279
+ export function validateTokenList(tokens: string, fieldName = 'tokens'): string[] {
280
+ if (!tokens || typeof tokens !== 'string') {
281
+ throw new ValidationError(fieldName, 'Token list is required');
282
+ }
283
+
284
+ const tokenArray = tokens.split(',').map((t) => t.trim());
285
+
286
+ if (tokenArray.length === 0 || tokenArray.some((t) => !t)) {
287
+ throw new ValidationError(fieldName, 'Token list cannot be empty');
288
+ }
289
+
290
+ // Validate each token name
291
+ tokenArray.forEach((token, index) => {
292
+ try {
293
+ validateTokenName(token, `${fieldName}[${index}]`);
294
+ } catch (error) {
295
+ if (error instanceof ValidationError) {
296
+ throw new ValidationError(
297
+ fieldName,
298
+ `Invalid token at position ${index + 1}: ${token}`
299
+ );
300
+ }
301
+ throw error;
302
+ }
303
+ });
304
+
305
+ return tokenArray;
306
+ }
307
+
308
+ /**
309
+ * Safe validation wrapper that doesn't throw
310
+ *
311
+ * Useful for non-critical validation where you want to continue with a warning.
312
+ *
313
+ * @param validationFn - Validation function to execute
314
+ * @returns Object with success flag and optional error
315
+ *
316
+ * @example
317
+ * ```typescript
318
+ * const result = safeValidate(() => validateTokenName('anime'));
319
+ * if (!result.success) {
320
+ * console.warn('Validation warning:', result.error);
321
+ * }
322
+ * ```
323
+ */
324
+ export function safeValidate(
325
+ validationFn: () => void
326
+ ): { success: boolean; error?: string } {
327
+ try {
328
+ validationFn();
329
+ return { success: true };
330
+ } catch (error) {
331
+ if (error instanceof ValidationError) {
332
+ return { success: false, error: error.message };
333
+ }
334
+ return { success: false, error: String(error) };
335
+ }
336
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,23 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2022",
4
+ "module": "CommonJS",
5
+ "moduleResolution": "node",
6
+ "lib": ["ES2022"],
7
+ "outDir": "./dist",
8
+ "rootDir": "./src",
9
+ "declaration": true,
10
+ "declarationMap": true,
11
+ "sourceMap": true,
12
+ "strict": true,
13
+ "esModuleInterop": true,
14
+ "skipLibCheck": true,
15
+ "noEmit": false,
16
+ "forceConsistentCasingInFileNames": true,
17
+ "resolveJsonModule": true,
18
+ "allowSyntheticDefaultImports": true,
19
+ "types": ["node", "jest"]
20
+ },
21
+ "include": ["src/**/*"],
22
+ "exclude": ["node_modules", "dist", "tests", "src/scripts", "src/**/__tests__"]
23
+ }