UNPKG

ucm-mcp-server

Version:

Universal Context Manager MCP Server - AI-native artifact management

67 lines 2.76 kB
// MCP-specific error handling following MCP standards export var McpErrorCode; (function (McpErrorCode) { McpErrorCode[McpErrorCode["ParseError"] = -32700] = "ParseError"; McpErrorCode[McpErrorCode["InvalidRequest"] = -32600] = "InvalidRequest"; McpErrorCode[McpErrorCode["MethodNotFound"] = -32601] = "MethodNotFound"; McpErrorCode[McpErrorCode["InvalidParams"] = -32602] = "InvalidParams"; McpErrorCode[McpErrorCode["InternalError"] = -32603] = "InternalError"; McpErrorCode[McpErrorCode["ExternalServiceUnavailable"] = -32001] = "ExternalServiceUnavailable"; // External resource offline/unavailable })(McpErrorCode || (McpErrorCode = {})); export class McpError extends Error { code; data; constructor(code, message, data) { super(message); this.code = code; this.data = data; this.name = 'McpError'; } toResponse() { return { error: { code: this.code, message: this.message, data: this.data } }; } } export class McpErrorHandler { static formatError(error) { if (error instanceof McpError) { return error; } if (error.error) { error = error.error; } if (error instanceof McpError) { return error; } // Extract error message from various sources let message = error.message || error.toString(); if (!message) { message = JSON.stringify(error); } // Map common errors to MCP error codes if (message?.includes('not found')) { return new McpError(McpErrorCode.InvalidParams, message, { originalError: error }); } if (message?.includes('validation')) { return new McpError(McpErrorCode.InvalidParams, 'Parameter validation failed', { originalError: error }); } if (message?.includes('ECONNREFUSED')) { return new McpError(McpErrorCode.ExternalServiceUnavailable, 'External API is unavailable, try the ucm_health_check tool', { originalError: error }); } if (message?.includes('validation') || message?.includes('invalid') || message?.includes('required') || message?.includes('must be')) { return new McpError(McpErrorCode.InvalidParams, message, { originalError: error }); } if (message?.includes('UCM API server error')) { return new McpError(McpErrorCode.InternalError, message, { originalError: error }); } // Don't leak internal errors return new McpError(McpErrorCode.InternalError, message || 'An internal error occurred'); } } //# sourceMappingURL=McpErrorHandler.js.map