
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="f949ce8f-b3b9-5584-b28f-90867694cbee")}catch(e){}}();
import { ErrorCode, McpError } from '@modelcontextprotocol/sdk/types.js';
import { TOOL_STATUS } from '../const.js';
import { getHttpStatusCode } from './logging.js';
/**
 * Central helper to classify an error into a ToolStatus value.
 *
 * - TOOL_STATUS.ABORTED   → Request was explicitly aborted by the client.
 * - TOOL_STATUS.SOFT_FAIL → User/client errors (HTTP 4xx, InvalidParams, validation issues).
 * - TOOL_STATUS.FAILED    → Server errors (HTTP 5xx, unknown, or unexpected exceptions).
 */
export function getToolStatusFromError(error, isAborted) {
    if (isAborted) {
        return TOOL_STATUS.ABORTED;
    }
    const statusCode = getHttpStatusCode(error);
    // HTTP client errors (4xx) are treated as user errors
    if (statusCode !== undefined && statusCode >= 400 && statusCode < 500) {
        return TOOL_STATUS.SOFT_FAIL;
    }
    // MCP InvalidParams errors are also user errors
    if (error instanceof McpError && error.code === ErrorCode.InvalidParams) {
        return TOOL_STATUS.SOFT_FAIL;
    }
    // Everything else is considered a server / unexpected failure
    return TOOL_STATUS.FAILED;
}
//# sourceMappingURL=tool_status.js.map
//# debugId=f949ce8f-b3b9-5584-b28f-90867694cbee
