@gala-chain/launchpad-mcp-server 1.21.4 → 1.22.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.
Files changed (82) hide show
  1. package/CHANGELOG.md +84 -0
  2. package/dist/generated/version.d.ts +1 -1
  3. package/dist/generated/version.js +1 -1
  4. package/dist/tools/dex/advanced-dex.d.ts +15 -0
  5. package/dist/tools/dex/advanced-dex.d.ts.map +1 -0
  6. package/dist/tools/dex/advanced-dex.js +239 -0
  7. package/dist/tools/dex/advanced-dex.js.map +1 -0
  8. package/dist/tools/pools/index.d.ts +2 -2
  9. package/dist/tools/pools/index.d.ts.map +1 -1
  10. package/dist/tools/pools/index.js +7 -7
  11. package/dist/tools/pools/index.js.map +1 -1
  12. package/dist/tools/utils/explainSdkUsage.js +7 -7
  13. package/docs/AI-AGENT-PATTERNS.md +555 -0
  14. package/docs/CONSTRAINTS-REFERENCE.md +454 -0
  15. package/docs/PROMPT-TOOL-MAPPING.md +352 -0
  16. package/docs/examples/default-values-pattern.md +240 -0
  17. package/docs/examples/tool-factory-pattern.md +217 -0
  18. package/jest.config.js +94 -0
  19. package/package.json +2 -2
  20. package/src/__tests__/integration/fetchTokenDetails.integration.test.ts +258 -0
  21. package/src/__tests__/integration/poolTools.integration.test.ts +185 -0
  22. package/src/constants/mcpToolNames.ts +141 -0
  23. package/src/index.ts +19 -0
  24. package/src/prompts/__tests__/promptStructure.test.ts +137 -0
  25. package/src/prompts/__tests__/registry.test.ts +191 -0
  26. package/src/prompts/analysis.ts +429 -0
  27. package/src/prompts/create-token.ts +123 -0
  28. package/src/prompts/dex-trading.ts +86 -0
  29. package/src/prompts/discover-tokens.ts +86 -0
  30. package/src/prompts/index.ts +154 -0
  31. package/src/prompts/liquidity-positions.ts +270 -0
  32. package/src/prompts/portfolio.ts +242 -0
  33. package/src/prompts/trading.ts +191 -0
  34. package/src/prompts/utility.ts +43 -0
  35. package/src/prompts/utils/workflowTemplates.ts +511 -0
  36. package/src/schemas/common-schemas.ts +393 -0
  37. package/src/scripts/test-all-prompts.ts +184 -0
  38. package/src/server.ts +277 -0
  39. package/src/tools/__tests__/dex-tools.test.ts +562 -0
  40. package/src/tools/__tests__/liquidity-positions.test.ts +673 -0
  41. package/src/tools/balance/index.ts +174 -0
  42. package/src/tools/creation/index.ts +182 -0
  43. package/src/tools/dex/index.ts +226 -0
  44. package/src/tools/dex/liquidity-positions.ts +547 -0
  45. package/src/tools/index.ts +86 -0
  46. package/src/tools/pools/fetchAllPools.ts +47 -0
  47. package/src/tools/pools/fetchAllPriceHistory.ts +119 -0
  48. package/src/tools/pools/fetchPoolDetails.ts +27 -0
  49. package/src/tools/pools/fetchPoolDetailsForCalculation.ts +22 -0
  50. package/src/tools/pools/fetchPools.ts +47 -0
  51. package/src/tools/pools/fetchPriceHistory.ts +124 -0
  52. package/src/tools/pools/fetchTokenDetails.ts +77 -0
  53. package/src/tools/pools/index.ts +284 -0
  54. package/src/tools/social/index.ts +64 -0
  55. package/src/tools/trading/index.ts +605 -0
  56. package/src/tools/transfers/index.ts +75 -0
  57. package/src/tools/utils/clearCache.ts +36 -0
  58. package/src/tools/utils/createWallet.ts +19 -0
  59. package/src/tools/utils/explainSdkUsage.ts +1446 -0
  60. package/src/tools/utils/getAddress.ts +12 -0
  61. package/src/tools/utils/getCacheInfo.ts +14 -0
  62. package/src/tools/utils/getConfig.ts +11 -0
  63. package/src/tools/utils/getEthereumAddress.ts +12 -0
  64. package/src/tools/utils/getUrlByTokenName.ts +12 -0
  65. package/src/tools/utils/getVersion.ts +25 -0
  66. package/src/tools/utils/getWallet.ts +25 -0
  67. package/src/tools/utils/hasWallet.ts +15 -0
  68. package/src/tools/utils/index.ts +33 -0
  69. package/src/tools/utils/isTokenGraduated.ts +16 -0
  70. package/src/tools/utils/setWallet.ts +41 -0
  71. package/src/types/mcp.ts +72 -0
  72. package/src/utils/__tests__/validation.test.ts +147 -0
  73. package/src/utils/constraints.ts +155 -0
  74. package/src/utils/default-values.ts +208 -0
  75. package/src/utils/error-handler.ts +69 -0
  76. package/src/utils/error-templates.ts +273 -0
  77. package/src/utils/response-formatter.ts +51 -0
  78. package/src/utils/tool-factory.ts +257 -0
  79. package/src/utils/tool-registry.ts +296 -0
  80. package/src/utils/validation.ts +371 -0
  81. package/tests/wallet-management-integration.test.ts +284 -0
  82. package/tsconfig.json +23 -0
package/src/server.ts ADDED
@@ -0,0 +1,277 @@
1
+ /**
2
+ * Gala Launchpad MCP Server
3
+ *
4
+ * Provides MCP tools for AI agents to interact with Gala Launchpad
5
+ */
6
+
7
+ import { Server } from '@modelcontextprotocol/sdk/server/index.js';
8
+ import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
9
+ import {
10
+ ListToolsRequestSchema,
11
+ CallToolRequestSchema,
12
+ ListPromptsRequestSchema,
13
+ GetPromptRequestSchema,
14
+ } from '@modelcontextprotocol/sdk/types.js';
15
+ import { AgentConfig, type LaunchpadSDK } from '@gala-chain/launchpad-sdk';
16
+ import { tools } from './tools/index.js';
17
+ import { prompts, getPrompt } from './prompts/index.js';
18
+
19
+ export class LaunchpadMCPServer {
20
+ private server: Server;
21
+ private sdk: LaunchpadSDK | null = null;
22
+ private debug: boolean;
23
+
24
+ constructor() {
25
+ this.debug = process.env.DEBUG === 'true';
26
+
27
+ this.server = new Server(
28
+ {
29
+ name: '@gala-chain/launchpad-mcp-server',
30
+ version: '1.5.0',
31
+ },
32
+ {
33
+ capabilities: {
34
+ tools: {},
35
+ prompts: {
36
+ listChanged: true,
37
+ },
38
+ },
39
+ }
40
+ );
41
+
42
+ this.setupToolHandlers();
43
+ this.setupPromptHandlers();
44
+ this.setupErrorHandlers();
45
+ }
46
+
47
+ /**
48
+ * Initialize SDK with AgentConfig
49
+ *
50
+ * Supports two operational modes:
51
+ * 1. Full-access mode (PRIVATE_KEY provided): Uses quickSetup() - all operations available
52
+ * 2. Read-only mode (PRIVATE_KEY not provided): Uses readOnlySetup() - query operations only
53
+ *
54
+ * In read-only mode, signing operations (buy, sell, create tokens, etc.) will throw ValidationError
55
+ * when attempted, but all query operations (fetchPools, fetchBalance, etc.) work normally.
56
+ */
57
+ async initialize() {
58
+ try {
59
+ if (this.debug) {
60
+ console.error('[MCP Server] Initializing SDK...');
61
+ }
62
+
63
+ const hasPrivateKey = Boolean(process.env.PRIVATE_KEY && process.env.PRIVATE_KEY.trim());
64
+ const environment = (process.env.ENVIRONMENT as any) || 'production';
65
+ const timeout = parseInt(process.env.TIMEOUT || '30000', 10);
66
+
67
+ if (hasPrivateKey) {
68
+ // Full-access mode: use quickSetup() to enable signing operations
69
+ if (this.debug) {
70
+ console.error('[MCP Server] PRIVATE_KEY detected - initializing in full-access mode');
71
+ }
72
+
73
+ const { sdk, validation } = await AgentConfig.quickSetup({
74
+ environment,
75
+ privateKey: process.env.PRIVATE_KEY,
76
+ timeout,
77
+ debug: this.debug,
78
+ autoValidate: false,
79
+ });
80
+
81
+ this.sdk = sdk;
82
+
83
+ if (this.debug) {
84
+ console.error('[MCP Server] SDK initialized successfully (full-access mode)');
85
+ if (validation) {
86
+ console.error(`[MCP Server] Validation - Ready: ${validation.ready}`);
87
+ console.error(`[MCP Server] Validation - Can Trade: ${validation.capabilities.canTrade}`);
88
+ }
89
+ }
90
+
91
+ if (validation && !validation.ready) {
92
+ console.error('[MCP Server] Warning: SDK not ready', validation.issues);
93
+ }
94
+ } else {
95
+ // Read-only mode: use readOnlySetup() for query-only operations
96
+ if (this.debug) {
97
+ console.error('[MCP Server] PRIVATE_KEY not provided - initializing in read-only mode');
98
+ }
99
+
100
+ const { sdk } = await AgentConfig.readOnlySetup({
101
+ environment,
102
+ timeout,
103
+ debug: this.debug,
104
+ });
105
+
106
+ this.sdk = sdk;
107
+
108
+ if (this.debug) {
109
+ console.error('[MCP Server] SDK initialized successfully (read-only mode)');
110
+ console.error('[MCP Server] Note: Signing operations will fail - wallet required');
111
+ }
112
+ }
113
+ } catch (error) {
114
+ console.error('[MCP Server] Failed to initialize SDK:', error);
115
+ throw error;
116
+ }
117
+ }
118
+
119
+ /**
120
+ * Setup tool handlers
121
+ */
122
+ private setupToolHandlers() {
123
+ // Register tools/list handler
124
+ this.server.setRequestHandler(ListToolsRequestSchema, async () => {
125
+ if (this.debug) {
126
+ console.error(`[MCP Server] Listing ${tools.length} tools`);
127
+ }
128
+
129
+ return {
130
+ tools: tools.map((tool) => ({
131
+ name: tool.name,
132
+ description: tool.description,
133
+ inputSchema: tool.inputSchema,
134
+ })),
135
+ };
136
+ });
137
+
138
+ // Register tools/call handler
139
+ this.server.setRequestHandler(CallToolRequestSchema, async (request) => {
140
+ const toolName = request.params.name as string;
141
+ const args = request.params.arguments || {};
142
+
143
+ if (this.debug) {
144
+ console.error(`[MCP Server] Executing tool: ${toolName}`);
145
+ console.error(`[MCP Server] Arguments:`, JSON.stringify(args, null, 2));
146
+ }
147
+
148
+ const tool = tools.find((t) => t.name === toolName);
149
+
150
+ if (!tool) {
151
+ throw new Error(`Tool not found: ${toolName}`);
152
+ }
153
+
154
+ if (!this.sdk) {
155
+ throw new Error('SDK not initialized. Failed during startup - check logs for details.');
156
+ }
157
+
158
+ try {
159
+ const result = await tool.handler(this.sdk, args);
160
+
161
+ if (this.debug) {
162
+ console.error(`[MCP Server] Tool execution successful: ${toolName}`);
163
+ }
164
+
165
+ return result as any;
166
+ } catch (error) {
167
+ console.error(`[MCP Server] Tool execution failed: ${toolName}`, error);
168
+ throw error;
169
+ }
170
+ });
171
+ }
172
+
173
+ /**
174
+ * Setup prompt handlers
175
+ */
176
+ private setupPromptHandlers() {
177
+ // Register prompts/list handler
178
+ this.server.setRequestHandler(ListPromptsRequestSchema, async () => {
179
+ if (this.debug) {
180
+ console.error(`[MCP Server] Listing ${prompts.length} prompts`);
181
+ }
182
+
183
+ return {
184
+ prompts: prompts.map((prompt) => ({
185
+ name: prompt.name,
186
+ description: prompt.description,
187
+ arguments: prompt.arguments || [],
188
+ })),
189
+ };
190
+ });
191
+
192
+ // Register prompts/get handler
193
+ this.server.setRequestHandler(GetPromptRequestSchema, async (request) => {
194
+ const promptName = request.params.name as string;
195
+ const args = (request.params.arguments || {}) as Record<string, string>;
196
+
197
+ if (this.debug) {
198
+ console.error(`[MCP Server] Getting prompt: ${promptName}`);
199
+ console.error(`[MCP Server] Arguments:`, JSON.stringify(args, null, 2));
200
+ }
201
+
202
+ const prompt = getPrompt(promptName);
203
+
204
+ if (!prompt) {
205
+ throw new Error(`Prompt not found: ${promptName}`);
206
+ }
207
+
208
+ try {
209
+ const messages = prompt.handler(args);
210
+
211
+ if (this.debug) {
212
+ console.error(`[MCP Server] Prompt generated ${messages.length} messages`);
213
+ }
214
+
215
+ return {
216
+ messages,
217
+ };
218
+ } catch (error) {
219
+ console.error(`[MCP Server] Prompt generation failed: ${promptName}`, error);
220
+ throw error;
221
+ }
222
+ });
223
+ }
224
+
225
+ /**
226
+ * Setup error handlers
227
+ */
228
+ private setupErrorHandlers() {
229
+ this.server.onerror = (error) => {
230
+ console.error('[MCP Server] Protocol error:', error);
231
+ };
232
+
233
+ process.on('SIGINT', () => {
234
+ if (this.debug) {
235
+ console.error('[MCP Server] Received SIGINT, shutting down...');
236
+ }
237
+ this.cleanup();
238
+ process.exit(0);
239
+ });
240
+
241
+ process.on('SIGTERM', () => {
242
+ if (this.debug) {
243
+ console.error('[MCP Server] Received SIGTERM, shutting down...');
244
+ }
245
+ this.cleanup();
246
+ process.exit(0);
247
+ });
248
+ }
249
+
250
+ /**
251
+ * Start the MCP server
252
+ */
253
+ async start() {
254
+ await this.initialize();
255
+
256
+ const transport = new StdioServerTransport();
257
+ await this.server.connect(transport);
258
+
259
+ if (this.debug) {
260
+ console.error('[MCP Server] Gala Launchpad MCP server running on stdio');
261
+ console.error(`[MCP Server] Registered ${tools.length} tools`);
262
+ console.error(`[MCP Server] Registered ${prompts.length} prompts (slash commands)`);
263
+ }
264
+ }
265
+
266
+ /**
267
+ * Cleanup resources
268
+ */
269
+ cleanup() {
270
+ if (this.sdk) {
271
+ this.sdk.cleanup();
272
+ if (this.debug) {
273
+ console.error('[MCP Server] SDK cleaned up');
274
+ }
275
+ }
276
+ }
277
+ }