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

62 lines 1.96 kB
"use strict"; /** * Error Handler Utility * * Formats errors for MCP protocol responses with AI-friendly tips. * Uses centralized error templates from error-templates.ts. * * @see src/utils/error-templates.ts */ Object.defineProperty(exports, "__esModule", { value: true }); exports.formatError = formatError; exports.withErrorHandling = withErrorHandling; const error_templates_js_1 = require("./error-templates.js"); /** * Format error for MCP response with AI-friendly tips */ function formatError(error) { const errorMessage = error instanceof Error ? error.message : String(error); // Sanitize sensitive information from error messages const sanitized = sanitizeError(errorMessage); // Add AI-friendly tips using centralized templates const withTips = (0, error_templates_js_1.enhanceErrorMessage)(sanitized); return { content: [ { type: 'text', text: `Error: ${withTips}`, }, ], isError: true, }; } /** * Sanitize error messages to remove sensitive information */ function sanitizeError(message) { // Remove private keys let sanitized = message.replace(/0x[a-fA-F0-9]{64}/g, '0x***'); // Remove eth| addresses but keep format visible sanitized = sanitized.replace(/(eth\|)[a-fA-F0-9]{40}/g, '$1***'); // Remove 0x addresses but keep format visible sanitized = sanitized.replace(/(0x)[a-fA-F0-9]{40}/g, '$1***'); return sanitized; } /** * Wrap handler with error handling * * @template TArgs - Array of argument types * @param handler - Handler function to wrap with error handling * @returns Wrapped handler with automatic error formatting */ function withErrorHandling(handler) { return async (...args) => { try { return await handler(...args); } catch (error) { return formatError(error); } }; } //# sourceMappingURL=error-handler.js.map