@gala-chain/launchpad-mcp-server 1.24.1 → 1.25.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.
- package/CHANGELOG.md +30 -0
- package/dist/generated/version.d.ts +1 -1
- package/dist/generated/version.js +1 -1
- package/dist/tools/index.d.ts +2 -2
- package/dist/tools/index.js +3 -3
- package/dist/tools/pools/index.d.ts.map +1 -1
- package/dist/tools/pools/index.js +4 -0
- package/dist/tools/pools/index.js.map +1 -1
- package/dist/tools/pools/onDexPoolCreation.d.ts +6 -0
- package/dist/tools/pools/onDexPoolCreation.d.ts.map +1 -0
- package/dist/tools/pools/onDexPoolCreation.js +60 -0
- package/dist/tools/pools/onDexPoolCreation.js.map +1 -0
- package/dist/tools/pools/onLaunchpadTokenCreation.d.ts +6 -0
- package/dist/tools/pools/onLaunchpadTokenCreation.d.ts.map +1 -0
- package/dist/tools/pools/onLaunchpadTokenCreation.js +54 -0
- package/dist/tools/pools/onLaunchpadTokenCreation.js.map +1 -0
- package/package.json +2 -2
- package/docs/AI-AGENT-PATTERNS.md +0 -555
- package/docs/CONSTRAINTS-REFERENCE.md +0 -454
- package/docs/PROMPT-TOOL-MAPPING.md +0 -352
- package/docs/examples/default-values-pattern.md +0 -240
- package/docs/examples/tool-factory-pattern.md +0 -217
- package/jest.config.js +0 -94
- package/src/__tests__/integration/fetchTokenDetails.integration.test.ts +0 -258
- package/src/__tests__/integration/poolTools.integration.test.ts +0 -185
- package/src/__tests__/server.test.ts +0 -255
- package/src/constants/mcpToolNames.ts +0 -183
- package/src/index.ts +0 -19
- package/src/prompts/__tests__/promptStructure.test.ts +0 -187
- package/src/prompts/__tests__/registry.test.ts +0 -349
- package/src/prompts/analysis.ts +0 -380
- package/src/prompts/balances.ts +0 -182
- package/src/prompts/create-token.ts +0 -123
- package/src/prompts/creation-utils.ts +0 -103
- package/src/prompts/dex-trading.ts +0 -86
- package/src/prompts/discover-tokens.ts +0 -86
- package/src/prompts/explore-dex-pools.ts +0 -138
- package/src/prompts/index.ts +0 -178
- package/src/prompts/liquidity-positions.ts +0 -237
- package/src/prompts/pools.ts +0 -496
- package/src/prompts/portfolio.ts +0 -208
- package/src/prompts/social.ts +0 -94
- package/src/prompts/trading-calculations.ts +0 -414
- package/src/prompts/trading.ts +0 -160
- package/src/prompts/transfers.ts +0 -97
- package/src/prompts/utility-tools.ts +0 -266
- package/src/prompts/utility.ts +0 -77
- package/src/prompts/utils/handlerHelpers.ts +0 -55
- package/src/prompts/utils/textTemplates.ts +0 -73
- package/src/prompts/utils/workflowTemplates.ts +0 -511
- package/src/schemas/common-schemas.ts +0 -393
- package/src/scripts/test-all-prompts.ts +0 -184
- package/src/server.ts +0 -367
- package/src/tools/__tests__/dex-tools.test.ts +0 -562
- package/src/tools/__tests__/liquidity-positions.test.ts +0 -673
- package/src/tools/balance/index.ts +0 -174
- package/src/tools/creation/index.ts +0 -182
- package/src/tools/dex/fetchAllDexPools.ts +0 -45
- package/src/tools/dex/fetchDexPools.ts +0 -58
- package/src/tools/dex/index.ts +0 -231
- package/src/tools/dex/liquidity-positions.ts +0 -547
- package/src/tools/index.ts +0 -94
- package/src/tools/pools/fetchAllPools.ts +0 -47
- package/src/tools/pools/fetchAllPriceHistory.ts +0 -119
- package/src/tools/pools/fetchPoolDetails.ts +0 -27
- package/src/tools/pools/fetchPoolDetailsForCalculation.ts +0 -22
- package/src/tools/pools/fetchPools.ts +0 -47
- package/src/tools/pools/fetchPriceHistory.ts +0 -124
- package/src/tools/pools/fetchTokenDetails.ts +0 -77
- package/src/tools/pools/index.ts +0 -284
- package/src/tools/social/index.ts +0 -64
- package/src/tools/trading/index.ts +0 -605
- package/src/tools/transfers/index.ts +0 -75
- package/src/tools/utils/clearCache.ts +0 -36
- package/src/tools/utils/createWallet.ts +0 -19
- package/src/tools/utils/explainSdkUsage.ts +0 -1446
- package/src/tools/utils/getAddress.ts +0 -12
- package/src/tools/utils/getCacheInfo.ts +0 -14
- package/src/tools/utils/getConfig.ts +0 -21
- package/src/tools/utils/getEnvironment.ts +0 -17
- package/src/tools/utils/getEthereumAddress.ts +0 -12
- package/src/tools/utils/getUrlByTokenName.ts +0 -12
- package/src/tools/utils/getVersion.ts +0 -25
- package/src/tools/utils/getWallet.ts +0 -25
- package/src/tools/utils/hasWallet.ts +0 -15
- package/src/tools/utils/index.ts +0 -37
- package/src/tools/utils/isTokenGraduated.ts +0 -16
- package/src/tools/utils/setWallet.ts +0 -41
- package/src/tools/utils/switchEnvironment.ts +0 -28
- package/src/types/mcp.ts +0 -72
- package/src/utils/__tests__/validation.test.ts +0 -147
- package/src/utils/constraints.ts +0 -155
- package/src/utils/default-values.ts +0 -208
- package/src/utils/error-handler.ts +0 -69
- package/src/utils/error-templates.ts +0 -273
- package/src/utils/response-formatter.ts +0 -51
- package/src/utils/tool-factory.ts +0 -303
- package/src/utils/tool-registry.ts +0 -296
- package/src/utils/validation.ts +0 -429
- package/tests/wallet-management-integration.test.ts +0 -284
- package/tsconfig.json +0 -23
|
@@ -1,217 +0,0 @@
|
|
|
1
|
-
# Tool Factory Pattern Examples
|
|
2
|
-
|
|
3
|
-
Demonstrates how to use `tool-factory.ts` utilities to eliminate duplication. These examples show the before/after comparison for common tool patterns.
|
|
4
|
-
|
|
5
|
-
**See**: `src/utils/tool-factory.ts`
|
|
6
|
-
|
|
7
|
-
---
|
|
8
|
-
|
|
9
|
-
## Example 1: Simple Token Fetch Tool (BEFORE vs AFTER)
|
|
10
|
-
|
|
11
|
-
### ❌ BEFORE: Manual duplication (22 lines)
|
|
12
|
-
|
|
13
|
-
```typescript
|
|
14
|
-
export const fetchPoolDetailsToolOLD: MCPTool = {
|
|
15
|
-
name: 'gala_launchpad_fetch_pool_details',
|
|
16
|
-
description: 'Get detailed pool state from GalaChain bonding curve',
|
|
17
|
-
inputSchema: {
|
|
18
|
-
type: 'object',
|
|
19
|
-
properties: {
|
|
20
|
-
tokenName: TOKEN_NAME_SCHEMA,
|
|
21
|
-
},
|
|
22
|
-
required: ['tokenName'],
|
|
23
|
-
},
|
|
24
|
-
handler: withErrorHandling(async (sdk, args) => {
|
|
25
|
-
const result = await sdk.fetchPoolDetails(args.tokenName);
|
|
26
|
-
return formatSuccess(result);
|
|
27
|
-
}),
|
|
28
|
-
};
|
|
29
|
-
```
|
|
30
|
-
|
|
31
|
-
### ✅ AFTER: Using factory (6 lines - 73% reduction)
|
|
32
|
-
|
|
33
|
-
```typescript
|
|
34
|
-
export const fetchPoolDetailsToolNEW = createSimpleTokenFetchTool({
|
|
35
|
-
name: 'gala_launchpad_fetch_pool_details',
|
|
36
|
-
description: 'Get detailed pool state from GalaChain bonding curve',
|
|
37
|
-
handler: (sdk, tokenName) => sdk.fetchPoolDetails(tokenName),
|
|
38
|
-
});
|
|
39
|
-
```
|
|
40
|
-
|
|
41
|
-
---
|
|
42
|
-
|
|
43
|
-
## Example 2: Boolean Check Tool (BEFORE vs AFTER)
|
|
44
|
-
|
|
45
|
-
### ❌ BEFORE: Manual duplication (25 lines)
|
|
46
|
-
|
|
47
|
-
```typescript
|
|
48
|
-
export const checkTokenNameToolOLD: MCPTool = {
|
|
49
|
-
name: 'gala_launchpad_check_token_name',
|
|
50
|
-
description: 'Check if token name is available',
|
|
51
|
-
inputSchema: {
|
|
52
|
-
type: 'object',
|
|
53
|
-
properties: {
|
|
54
|
-
tokenName: {
|
|
55
|
-
type: 'string',
|
|
56
|
-
pattern: '^[a-z0-9_-]{2,20}$',
|
|
57
|
-
description: 'Token name to check',
|
|
58
|
-
},
|
|
59
|
-
},
|
|
60
|
-
required: ['tokenName'],
|
|
61
|
-
},
|
|
62
|
-
handler: withErrorHandling(async (sdk, args) => {
|
|
63
|
-
const available = await sdk.isTokenNameAvailable(args.tokenName);
|
|
64
|
-
return formatBoolean(
|
|
65
|
-
available,
|
|
66
|
-
available ? 'Token name is available' : 'Token name is already taken'
|
|
67
|
-
);
|
|
68
|
-
}),
|
|
69
|
-
};
|
|
70
|
-
```
|
|
71
|
-
|
|
72
|
-
### ✅ AFTER: Using factory (10 lines - 60% reduction)
|
|
73
|
-
|
|
74
|
-
```typescript
|
|
75
|
-
export const checkTokenNameToolNEW = createBooleanCheckTool({
|
|
76
|
-
name: 'gala_launchpad_check_token_name',
|
|
77
|
-
description: 'Check if token name is available',
|
|
78
|
-
paramName: 'tokenName',
|
|
79
|
-
paramSchema: TOKEN_NAME_SCHEMA,
|
|
80
|
-
handler: (sdk, tokenName) => sdk.isTokenNameAvailable(tokenName),
|
|
81
|
-
messages: {
|
|
82
|
-
true: 'Token name is available',
|
|
83
|
-
false: 'Token name is already taken',
|
|
84
|
-
},
|
|
85
|
-
});
|
|
86
|
-
```
|
|
87
|
-
|
|
88
|
-
---
|
|
89
|
-
|
|
90
|
-
## Example 3: Resolution Tool (BEFORE vs AFTER)
|
|
91
|
-
|
|
92
|
-
### ❌ BEFORE: Manual duplication (22 lines)
|
|
93
|
-
|
|
94
|
-
```typescript
|
|
95
|
-
export const resolveVaultAddressToolOLD: MCPTool = {
|
|
96
|
-
name: 'gala_launchpad_resolve_vault_address',
|
|
97
|
-
description: 'Get GalaChain vault address for a token (useful for debugging)',
|
|
98
|
-
inputSchema: {
|
|
99
|
-
type: 'object',
|
|
100
|
-
properties: {
|
|
101
|
-
tokenName: TOKEN_NAME_SCHEMA,
|
|
102
|
-
},
|
|
103
|
-
required: ['tokenName'],
|
|
104
|
-
},
|
|
105
|
-
handler: withErrorHandling(async (sdk, args) => {
|
|
106
|
-
const vaultAddress = await sdk.resolveVaultAddress(args.tokenName);
|
|
107
|
-
return formatSuccess({ tokenName: args.tokenName, vaultAddress });
|
|
108
|
-
}),
|
|
109
|
-
};
|
|
110
|
-
```
|
|
111
|
-
|
|
112
|
-
### ✅ AFTER: Using factory (6 lines - 73% reduction)
|
|
113
|
-
|
|
114
|
-
```typescript
|
|
115
|
-
export const resolveVaultAddressToolNEW = createResolutionTool({
|
|
116
|
-
name: 'gala_launchpad_resolve_vault_address',
|
|
117
|
-
description: 'Get GalaChain vault address for a token (useful for debugging)',
|
|
118
|
-
resolver: (sdk, tokenName) => sdk.resolveVaultAddress(tokenName),
|
|
119
|
-
resultKey: 'vaultAddress',
|
|
120
|
-
});
|
|
121
|
-
```
|
|
122
|
-
|
|
123
|
-
---
|
|
124
|
-
|
|
125
|
-
## Example 4: Complex Fetch Tool with Custom Schema (BEFORE vs AFTER)
|
|
126
|
-
|
|
127
|
-
### ❌ BEFORE: Manual duplication (28 lines)
|
|
128
|
-
|
|
129
|
-
```typescript
|
|
130
|
-
export const fetchPoolsToolOLD: MCPTool = {
|
|
131
|
-
name: 'gala_launchpad_fetch_pools',
|
|
132
|
-
description: 'Fetch token pools from Gala Launchpad with filtering and pagination',
|
|
133
|
-
inputSchema: {
|
|
134
|
-
type: 'object',
|
|
135
|
-
properties: {
|
|
136
|
-
type: {
|
|
137
|
-
type: 'string',
|
|
138
|
-
enum: Object.values(POOL_TYPES),
|
|
139
|
-
description: 'Type of pools to fetch (default: recent)',
|
|
140
|
-
},
|
|
141
|
-
page: PAGE_SCHEMA,
|
|
142
|
-
limit: createLimitSchema('pool', 20),
|
|
143
|
-
},
|
|
144
|
-
},
|
|
145
|
-
handler: withErrorHandling(async (sdk, args) => {
|
|
146
|
-
const result = await sdk.fetchPools({
|
|
147
|
-
type: args.type || 'recent',
|
|
148
|
-
page: args.page || 1,
|
|
149
|
-
limit: args.limit || 20,
|
|
150
|
-
});
|
|
151
|
-
return formatSuccess(result);
|
|
152
|
-
}),
|
|
153
|
-
};
|
|
154
|
-
```
|
|
155
|
-
|
|
156
|
-
### ✅ AFTER: Using factory (21 lines - 25% reduction)
|
|
157
|
-
|
|
158
|
-
```typescript
|
|
159
|
-
export const fetchPoolsToolNEW = createFetchTool({
|
|
160
|
-
name: 'gala_launchpad_fetch_pools',
|
|
161
|
-
description: 'Fetch token pools from Gala Launchpad with filtering and pagination',
|
|
162
|
-
inputSchema: {
|
|
163
|
-
type: 'object',
|
|
164
|
-
properties: {
|
|
165
|
-
type: {
|
|
166
|
-
type: 'string',
|
|
167
|
-
enum: Object.values(POOL_TYPES),
|
|
168
|
-
description: 'Type of pools to fetch (default: recent)',
|
|
169
|
-
},
|
|
170
|
-
page: PAGE_SCHEMA,
|
|
171
|
-
limit: createLimitSchema('pool', 20),
|
|
172
|
-
},
|
|
173
|
-
},
|
|
174
|
-
handler: (sdk, args) =>
|
|
175
|
-
sdk.fetchPools({
|
|
176
|
-
type: args.type || 'recent',
|
|
177
|
-
page: args.page || 1,
|
|
178
|
-
limit: args.limit || 20,
|
|
179
|
-
}),
|
|
180
|
-
});
|
|
181
|
-
```
|
|
182
|
-
|
|
183
|
-
---
|
|
184
|
-
|
|
185
|
-
## Summary Statistics
|
|
186
|
-
|
|
187
|
-
### IMPACT ANALYSIS:
|
|
188
|
-
|
|
189
|
-
**Tools that can use createSimpleTokenFetchTool (73% reduction):**
|
|
190
|
-
- fetchPoolDetailsTool
|
|
191
|
-
- fetchTokenDistributionTool
|
|
192
|
-
- fetchTokenBadgesTool
|
|
193
|
-
- Total: ~15 tools across the codebase
|
|
194
|
-
|
|
195
|
-
**Tools that can use createBooleanCheckTool (60% reduction):**
|
|
196
|
-
- checkTokenNameTool
|
|
197
|
-
- checkTokenSymbolTool
|
|
198
|
-
- isTokenGraduatedTool
|
|
199
|
-
- Total: ~3 tools
|
|
200
|
-
|
|
201
|
-
**Tools that can use createResolutionTool (73% reduction):**
|
|
202
|
-
- resolveVaultAddressTool
|
|
203
|
-
- resolveTokenClassKeyTool
|
|
204
|
-
- Total: ~2 tools
|
|
205
|
-
|
|
206
|
-
**Tools that can use createFetchTool (25% reduction):**
|
|
207
|
-
- fetchPoolsTool
|
|
208
|
-
- fetchTradesTool
|
|
209
|
-
- fetchTokensHeldTool
|
|
210
|
-
- fetchTokensCreatedTool
|
|
211
|
-
- Total: ~10 tools
|
|
212
|
-
|
|
213
|
-
### OVERALL IMPACT:
|
|
214
|
-
- ~30 out of 47 tools can use factory pattern
|
|
215
|
-
- Average reduction: 50% fewer lines per tool
|
|
216
|
-
- Total saved: ~500-700 lines of duplicated code
|
|
217
|
-
- Improved maintainability: Changes to error handling, formatting, etc. only need to be made once
|
package/jest.config.js
DELETED
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Jest Configuration for Gala Launchpad MCP Server
|
|
3
|
-
*
|
|
4
|
-
* TypeScript-first testing configuration with comprehensive coverage thresholds
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
module.exports = {
|
|
8
|
-
// Use ts-jest for TypeScript support
|
|
9
|
-
preset: 'ts-jest',
|
|
10
|
-
|
|
11
|
-
// Node.js environment (MCP server is server-side)
|
|
12
|
-
testEnvironment: 'node',
|
|
13
|
-
|
|
14
|
-
// Test file location patterns
|
|
15
|
-
roots: ['<rootDir>/src'],
|
|
16
|
-
testMatch: [
|
|
17
|
-
'**/__tests__/**/*.test.ts',
|
|
18
|
-
'**/__tests__/**/*.spec.ts',
|
|
19
|
-
],
|
|
20
|
-
|
|
21
|
-
// Coverage collection
|
|
22
|
-
collectCoverageFrom: [
|
|
23
|
-
'src/**/*.ts',
|
|
24
|
-
'!src/**/__tests__/**',
|
|
25
|
-
'!src/**/*.d.ts',
|
|
26
|
-
'!src/index.ts', // Entry point - covered by integration tests
|
|
27
|
-
],
|
|
28
|
-
|
|
29
|
-
// Coverage thresholds disabled for mixed codebase
|
|
30
|
-
// Note: New code has 92%+ coverage (validation.ts, prompt refactoring)
|
|
31
|
-
// Existing tools (47 MCP tools) are tested via integration, not unit tests
|
|
32
|
-
// This is intentional - unit testing tools would require mocking entire SDK
|
|
33
|
-
//
|
|
34
|
-
// Coverage Summary:
|
|
35
|
-
// - validation.ts: 92% branches, 100% functions, 91% lines (EXCELLENT)
|
|
36
|
-
// - Prompt tests: 119/119 passing with comprehensive edge cases
|
|
37
|
-
// - Overall: 30% due to untested tools (tested via real SDK integration)
|
|
38
|
-
//
|
|
39
|
-
// Uncomment below to enforce thresholds when tool coverage is added:
|
|
40
|
-
// coverageThreshold: {
|
|
41
|
-
// global: { branches: 80, functions: 80, lines: 80, statements: 80 },
|
|
42
|
-
// },
|
|
43
|
-
|
|
44
|
-
// Coverage reporters
|
|
45
|
-
coverageReporters: ['text', 'text-summary', 'html', 'lcov'],
|
|
46
|
-
|
|
47
|
-
// Module path aliases and extension mapping
|
|
48
|
-
moduleNameMapper: {
|
|
49
|
-
'^@/(.*)$': '<rootDir>/src/$1',
|
|
50
|
-
'^(\\.{1,2}/.*)\\.js$': '$1', // Map .js imports to .ts files
|
|
51
|
-
},
|
|
52
|
-
|
|
53
|
-
// Transform files with ts-jest
|
|
54
|
-
transform: {
|
|
55
|
-
'^.+\\.ts$': ['ts-jest', {
|
|
56
|
-
tsconfig: {
|
|
57
|
-
// Use ES modules
|
|
58
|
-
module: 'commonjs',
|
|
59
|
-
// Ensure strict type checking in tests
|
|
60
|
-
strict: true,
|
|
61
|
-
esModuleInterop: true,
|
|
62
|
-
skipLibCheck: true,
|
|
63
|
-
},
|
|
64
|
-
}],
|
|
65
|
-
},
|
|
66
|
-
|
|
67
|
-
// File extensions to consider
|
|
68
|
-
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json'],
|
|
69
|
-
|
|
70
|
-
// Ignore patterns
|
|
71
|
-
testPathIgnorePatterns: [
|
|
72
|
-
'/node_modules/',
|
|
73
|
-
'/dist/',
|
|
74
|
-
'/.history/',
|
|
75
|
-
'/integration/', // Integration tests have their own config
|
|
76
|
-
],
|
|
77
|
-
|
|
78
|
-
// Transform ESM packages in node_modules
|
|
79
|
-
transformIgnorePatterns: [
|
|
80
|
-
'node_modules/(?!(uuid|@gala-chain)/)',
|
|
81
|
-
],
|
|
82
|
-
|
|
83
|
-
// Setup files (if needed for global test setup)
|
|
84
|
-
// setupFilesAfterEnv: ['<rootDir>/src/__tests__/setup.ts'],
|
|
85
|
-
|
|
86
|
-
// Clear mocks between tests
|
|
87
|
-
clearMocks: true,
|
|
88
|
-
|
|
89
|
-
// Verbose output
|
|
90
|
-
verbose: true,
|
|
91
|
-
|
|
92
|
-
// Maximum worker threads (optimize for CI/CD)
|
|
93
|
-
maxWorkers: '50%',
|
|
94
|
-
};
|
|
@@ -1,258 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Integration Tests for fetchTokenDetails Tool
|
|
3
|
-
*
|
|
4
|
-
* Tests for comprehensive token details retrieval from DEX API platform.
|
|
5
|
-
* Requires valid PRIVATE_KEY environment variable.
|
|
6
|
-
*
|
|
7
|
-
* Run with: npm run test:integration
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
import { AgentConfig } from '@gala-chain/launchpad-sdk';
|
|
11
|
-
import { fetchTokenDetailsTool } from '../../tools/pools/index.js';
|
|
12
|
-
|
|
13
|
-
describe('fetchTokenDetails Tool Integration', () => {
|
|
14
|
-
let sdk: any;
|
|
15
|
-
|
|
16
|
-
beforeAll(async () => {
|
|
17
|
-
// Skip tests if no private key available
|
|
18
|
-
if (!process.env.PRIVATE_KEY) {
|
|
19
|
-
console.warn('⚠️ Skipping integration tests: PRIVATE_KEY environment variable not set');
|
|
20
|
-
return;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
// Initialize SDK with AgentConfig
|
|
24
|
-
const { sdk: initializedSdk } = await AgentConfig.quickSetup({
|
|
25
|
-
environment: (process.env.ENVIRONMENT as any) || 'development',
|
|
26
|
-
privateKey: process.env.PRIVATE_KEY,
|
|
27
|
-
timeout: 30000,
|
|
28
|
-
debug: false,
|
|
29
|
-
autoValidate: false,
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
sdk = initializedSdk;
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
afterAll(() => {
|
|
36
|
-
if (sdk) {
|
|
37
|
-
sdk.cleanup();
|
|
38
|
-
}
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
describe('fetchTokenDetailsTool with string tokenId', () => {
|
|
42
|
-
it('should fetch token details with string format tokenId', async () => {
|
|
43
|
-
if (!sdk) {
|
|
44
|
-
return; // Skip if SDK not initialized
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
// Use a known token format
|
|
48
|
-
const result = await fetchTokenDetailsTool.handler(sdk, {
|
|
49
|
-
tokenId: 'Token|Unit|GALA|none:none',
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
expect(result).toBeDefined();
|
|
53
|
-
expect(result.content).toBeDefined();
|
|
54
|
-
expect(Array.isArray(result.content)).toBe(true);
|
|
55
|
-
|
|
56
|
-
if (!result.isError) {
|
|
57
|
-
const response = JSON.parse(result.content[0].text!);
|
|
58
|
-
expect(response).toHaveProperty('symbol');
|
|
59
|
-
expect(response).toHaveProperty('decimals');
|
|
60
|
-
expect(response).toHaveProperty('name');
|
|
61
|
-
}
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
it('should return error for invalid tokenId format (empty)', async () => {
|
|
65
|
-
if (!sdk) {
|
|
66
|
-
return;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
const result = await fetchTokenDetailsTool.handler(sdk, {
|
|
70
|
-
tokenId: '',
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
expect(result).toBeDefined();
|
|
74
|
-
expect(result.isError).toBe(true);
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
it('should return error for non-existent token', async () => {
|
|
78
|
-
if (!sdk) {
|
|
79
|
-
return;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
const result = await fetchTokenDetailsTool.handler(sdk, {
|
|
83
|
-
tokenId: 'Token|Unit|NONEXISTENT|eth:0x0000000000000000000000000000000000000000',
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
expect(result).toBeDefined();
|
|
87
|
-
expect(result.isError).toBe(true);
|
|
88
|
-
});
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
describe('fetchTokenDetailsTool with object tokenId', () => {
|
|
92
|
-
it('should fetch token details with object format tokenId', async () => {
|
|
93
|
-
if (!sdk) {
|
|
94
|
-
return;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
// Use object format
|
|
98
|
-
const result = await fetchTokenDetailsTool.handler(sdk, {
|
|
99
|
-
tokenId: {
|
|
100
|
-
collection: 'Token',
|
|
101
|
-
category: 'Unit',
|
|
102
|
-
type: 'GALA',
|
|
103
|
-
additionalKey: 'none:none',
|
|
104
|
-
},
|
|
105
|
-
});
|
|
106
|
-
|
|
107
|
-
expect(result).toBeDefined();
|
|
108
|
-
expect(result.content).toBeDefined();
|
|
109
|
-
expect(Array.isArray(result.content)).toBe(true);
|
|
110
|
-
|
|
111
|
-
if (!result.isError) {
|
|
112
|
-
const response = JSON.parse(result.content[0].text!);
|
|
113
|
-
expect(response).toHaveProperty('symbol');
|
|
114
|
-
expect(response).toHaveProperty('decimals');
|
|
115
|
-
expect(response).toHaveProperty('name');
|
|
116
|
-
}
|
|
117
|
-
});
|
|
118
|
-
|
|
119
|
-
it('should validate required fields in object format', async () => {
|
|
120
|
-
if (!sdk) {
|
|
121
|
-
return;
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
// Missing additionalKey - should fail
|
|
125
|
-
const result = await fetchTokenDetailsTool.handler(sdk, {
|
|
126
|
-
tokenId: {
|
|
127
|
-
collection: 'Token',
|
|
128
|
-
category: 'Unit',
|
|
129
|
-
type: 'GALA',
|
|
130
|
-
// additionalKey is missing
|
|
131
|
-
} as any,
|
|
132
|
-
});
|
|
133
|
-
|
|
134
|
-
expect(result).toBeDefined();
|
|
135
|
-
// Either returns error or throws during validation
|
|
136
|
-
expect(result.isError || !result.content).toBe(true);
|
|
137
|
-
});
|
|
138
|
-
});
|
|
139
|
-
|
|
140
|
-
describe('MCP Response Format', () => {
|
|
141
|
-
it('should return valid MCP response structure for successful token details', async () => {
|
|
142
|
-
if (!sdk) {
|
|
143
|
-
return;
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
const result = await fetchTokenDetailsTool.handler(sdk, {
|
|
147
|
-
tokenId: 'Token|Unit|GALA|none:none',
|
|
148
|
-
});
|
|
149
|
-
|
|
150
|
-
// Validate MCP response structure
|
|
151
|
-
expect(result).toHaveProperty('content');
|
|
152
|
-
expect(Array.isArray(result.content)).toBe(true);
|
|
153
|
-
|
|
154
|
-
if (!result.isError) {
|
|
155
|
-
expect(result.content[0]).toHaveProperty('type', 'text');
|
|
156
|
-
expect(result.content[0]).toHaveProperty('text');
|
|
157
|
-
|
|
158
|
-
// Parse and validate JSON response
|
|
159
|
-
const response = JSON.parse(result.content[0].text!);
|
|
160
|
-
expect(response).toBeDefined();
|
|
161
|
-
expect(typeof response).toBe('object');
|
|
162
|
-
}
|
|
163
|
-
});
|
|
164
|
-
|
|
165
|
-
it('should return error MCP response for invalid token', async () => {
|
|
166
|
-
if (!sdk) {
|
|
167
|
-
return;
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
const result = await fetchTokenDetailsTool.handler(sdk, {
|
|
171
|
-
tokenId: 'Token|Unit|INVALID|eth:0x0000000000000000000000000000000000000000',
|
|
172
|
-
});
|
|
173
|
-
|
|
174
|
-
// Validate error MCP response structure
|
|
175
|
-
expect(result).toBeDefined();
|
|
176
|
-
expect(result.isError).toBe(true);
|
|
177
|
-
expect(result.content).toBeDefined();
|
|
178
|
-
});
|
|
179
|
-
});
|
|
180
|
-
|
|
181
|
-
describe('Token Details Response Structure', () => {
|
|
182
|
-
it('should include all expected token detail fields when successful', async () => {
|
|
183
|
-
if (!sdk) {
|
|
184
|
-
return;
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
const result = await fetchTokenDetailsTool.handler(sdk, {
|
|
188
|
-
tokenId: 'Token|Unit|GALA|none:none',
|
|
189
|
-
});
|
|
190
|
-
|
|
191
|
-
if (!result.isError && result.content.length > 0) {
|
|
192
|
-
const response = JSON.parse(result.content[0].text!);
|
|
193
|
-
|
|
194
|
-
// Check for key token detail fields
|
|
195
|
-
const expectedFields = ['symbol', 'decimals', 'name'];
|
|
196
|
-
expectedFields.forEach(field => {
|
|
197
|
-
expect(response).toHaveProperty(field);
|
|
198
|
-
});
|
|
199
|
-
}
|
|
200
|
-
});
|
|
201
|
-
|
|
202
|
-
it('should handle special characters in tokenId', async () => {
|
|
203
|
-
if (!sdk) {
|
|
204
|
-
return;
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
// Test with colon in additionalKey
|
|
208
|
-
const result = await fetchTokenDetailsTool.handler(sdk, {
|
|
209
|
-
tokenId: {
|
|
210
|
-
collection: 'Token',
|
|
211
|
-
category: 'Unit',
|
|
212
|
-
type: 'TEST',
|
|
213
|
-
additionalKey: 'eth:0xabc123def456',
|
|
214
|
-
},
|
|
215
|
-
});
|
|
216
|
-
|
|
217
|
-
expect(result).toBeDefined();
|
|
218
|
-
// Should handle without throwing errors
|
|
219
|
-
expect(result.content).toBeDefined();
|
|
220
|
-
});
|
|
221
|
-
});
|
|
222
|
-
|
|
223
|
-
describe('Error Handling', () => {
|
|
224
|
-
it('should gracefully handle network errors', async () => {
|
|
225
|
-
if (!sdk) {
|
|
226
|
-
return;
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
// Try to fetch with invalid format that won't match
|
|
230
|
-
const result = await fetchTokenDetailsTool.handler(sdk, {
|
|
231
|
-
tokenId: 'Invalid|Format|Missing|Components',
|
|
232
|
-
});
|
|
233
|
-
|
|
234
|
-
expect(result).toBeDefined();
|
|
235
|
-
// Should return error response, not throw
|
|
236
|
-
if (result.isError) {
|
|
237
|
-
expect(result.content).toBeDefined();
|
|
238
|
-
}
|
|
239
|
-
});
|
|
240
|
-
|
|
241
|
-
it('should include error message in response', async () => {
|
|
242
|
-
if (!sdk) {
|
|
243
|
-
return;
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
const result = await fetchTokenDetailsTool.handler(sdk, {
|
|
247
|
-
tokenId: 'Token|Unit|NONEXISTENT|eth:0x0000000000000000000000000000000000000000',
|
|
248
|
-
});
|
|
249
|
-
|
|
250
|
-
if (result.isError) {
|
|
251
|
-
expect(result.content).toBeDefined();
|
|
252
|
-
expect(result.content[0]).toHaveProperty('type', 'text');
|
|
253
|
-
const errorText = result.content[0].text || '';
|
|
254
|
-
expect(errorText.length).toBeGreaterThan(0);
|
|
255
|
-
}
|
|
256
|
-
});
|
|
257
|
-
});
|
|
258
|
-
});
|