UNPKG

@bjoaquinc/mcp-error-formatter

Version:

Simple utility to format MCP tool errors like Cursor

38 lines 1.93 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.createNetworkError = exports.createTimeoutError = exports.createUserAbortedError = exports.ErrorType = exports.formatMCPError = void 0; const formatter_1 = require("./formatter"); const types_1 = require("./types"); var formatter_2 = require("./formatter"); Object.defineProperty(exports, "formatMCPError", { enumerable: true, get: function () { return formatter_2.formatMCPError; } }); var types_2 = require("./types"); Object.defineProperty(exports, "ErrorType", { enumerable: true, get: function () { return types_2.ErrorType; } }); // Convenience functions for common errors const createUserAbortedError = (requestId) => (0, formatter_1.formatMCPError)(new Error('User aborted request'), { errorType: types_1.ErrorType.USER_ABORTED, title: 'User aborted request.', detail: 'Tool call ended before result was received', requestId, }); exports.createUserAbortedError = createUserAbortedError; const createTimeoutError = (timeoutMs, requestId) => { const timeout = timeoutMs || 'unknown'; return (0, formatter_1.formatMCPError)(new Error(`Operation timed out after ${timeout}ms`), { errorType: types_1.ErrorType.TIMEOUT, title: `Request timed out after ${timeout}ms`, detail: 'The operation took too long to complete', requestId, }); }; exports.createTimeoutError = createTimeoutError; const createNetworkError = (originalError, requestId) => { const errorMessage = originalError?.message || 'Unknown network error'; return (0, formatter_1.formatMCPError)(originalError || new Error(errorMessage), { errorType: types_1.ErrorType.NETWORK_ERROR, title: 'Network connection failed', detail: `Failed to establish connection: ${errorMessage}`, requestId, }); }; exports.createNetworkError = createNetworkError; //# sourceMappingURL=index.js.map