UNPKG

@gala-chain/launchpad-mcp-server

Version:

MCP server for Gala Launchpad SDK with 55 tools + 14 slash commands - Production-grade AI agent integration with comprehensive validation, optimized performance, and 80%+ test coverage

194 lines 6.57 kB
"use strict"; /** * Tool Factory Pattern Utilities * * DRY utilities for creating MCP tools with common patterns. * Eliminates duplication across 47 tool definitions. * * @see Phase 2.1 of refactoring plan */ Object.defineProperty(exports, "__esModule", { value: true }); exports.toolFactory = void 0; exports.createSimpleTokenFetchTool = createSimpleTokenFetchTool; exports.createBooleanCheckTool = createBooleanCheckTool; exports.createFetchTool = createFetchTool; exports.createResolutionTool = createResolutionTool; exports.createNoParamTool = createNoParamTool; const error_handler_js_1 = require("./error-handler.js"); const response_formatter_js_1 = require("./response-formatter.js"); const common_schemas_js_1 = require("../schemas/common-schemas.js"); // ============================================================================= // Factory Functions // ============================================================================= /** * Creates a simple fetch tool that takes tokenName and calls an SDK method * * @example * ```typescript * export const fetchPoolDetailsTool = createSimpleTokenFetchTool({ * name: 'gala_launchpad_fetch_pool_details', * description: 'Get detailed pool state from GalaChain bonding curve', * handler: (sdk, tokenName) => sdk.fetchPoolDetails(tokenName), * }); * ``` */ function createSimpleTokenFetchTool(config) { return { name: config.name, description: config.description, inputSchema: { type: 'object', properties: { tokenName: common_schemas_js_1.TOKEN_NAME_SCHEMA, }, required: ['tokenName'], }, handler: (0, error_handler_js_1.withErrorHandling)(async (sdk, args) => { const result = await config.handler(sdk, args.tokenName); return (0, response_formatter_js_1.formatSuccess)(result); }), }; } /** * Creates a boolean check tool (e.g., isTokenNameAvailable, isTokenSymbolAvailable) * * @example * ```typescript * export const checkTokenNameTool = createBooleanCheckTool({ * name: 'gala_launchpad_check_token_name', * description: 'Check if token name is available', * paramName: 'tokenName', * paramSchema: TOKEN_NAME_SCHEMA, * handler: (sdk, tokenName) => sdk.isTokenNameAvailable(tokenName), * messages: { * true: 'Token name is available', * false: 'Token name is already taken', * }, * }); * ``` */ function createBooleanCheckTool(config) { return { name: config.name, description: config.description, inputSchema: { type: 'object', properties: { [config.paramName]: config.paramSchema, }, required: [config.paramName], }, handler: (0, error_handler_js_1.withErrorHandling)(async (sdk, args) => { const value = args[config.paramName]; const available = await config.handler(sdk, value); return (0, response_formatter_js_1.formatBoolean)(available, available ? config.messages.true : config.messages.false); }), }; } /** * Creates a generic fetch tool with custom input schema and handler * * @example * ```typescript * export const fetchPoolsTool = createFetchTool({ * name: 'gala_launchpad_fetch_pools', * description: 'Fetch token pools from Gala Launchpad', * inputSchema: { * type: 'object', * properties: { * type: { type: 'string', enum: ['recent', 'popular'] }, * page: PAGE_SCHEMA, * limit: createLimitSchema('pool', 20), * }, * }, * handler: (sdk, args) => sdk.fetchPools({ * type: args.type || 'recent', * page: args.page || 1, * limit: args.limit || 20, * }), * }); * ``` */ function createFetchTool(config) { return { name: config.name, description: config.description, inputSchema: config.inputSchema, handler: (0, error_handler_js_1.withErrorHandling)(async (sdk, args) => { const result = await config.handler(sdk, args); return (0, response_formatter_js_1.formatSuccess)(result); }), }; } /** * Creates a resolution tool that maps tokenName to some resolved value * * @example * ```typescript * export const resolveVaultAddressTool = createResolutionTool({ * name: 'gala_launchpad_resolve_vault_address', * description: 'Get GalaChain vault address for a token', * resolver: (sdk, tokenName) => sdk.resolveVaultAddress(tokenName), * resultKey: 'vaultAddress', * }); * ``` */ function createResolutionTool(config) { return { name: config.name, description: config.description, inputSchema: { type: 'object', properties: { tokenName: common_schemas_js_1.TOKEN_NAME_SCHEMA, }, required: ['tokenName'], }, handler: (0, error_handler_js_1.withErrorHandling)(async (sdk, args) => { const resolvedValue = await config.resolver(sdk, args.tokenName); return (0, response_formatter_js_1.formatSuccess)({ tokenName: args.tokenName, [config.resultKey]: resolvedValue, }); }), }; } /** * Creates a no-parameter tool that only needs SDK instance * * @example * ```typescript * export const getAddressTool = createNoParamTool({ * name: 'gala_launchpad_get_address', * description: 'Get the GalaChain address format (eth|0x...) for the authenticated wallet.', * handler: (sdk) => sdk.getAddress(), * resultKey: 'address', * }); * ``` */ function createNoParamTool(config) { return { name: config.name, description: config.description, inputSchema: { type: 'object', properties: {}, }, handler: (0, error_handler_js_1.withErrorHandling)(async (sdk) => { const result = await config.handler(sdk); // If resultKey provided, wrap in object; otherwise return result directly return (0, response_formatter_js_1.formatSuccess)(config.resultKey ? { [config.resultKey]: result } : result); }), }; } // ============================================================================= // Exports // ============================================================================= exports.toolFactory = { createSimpleTokenFetchTool, createBooleanCheckTool, createFetchTool, createResolutionTool, createNoParamTool, }; //# sourceMappingURL=tool-factory.js.map