2025-10-05 06:37:57 -04:00
|
|
|
import { logger } from '@librechat/data-schemas';
|
2025-11-10 19:05:30 -05:00
|
|
|
import {
|
|
|
|
|
EModelEndpoint,
|
|
|
|
|
removeNullishValues,
|
|
|
|
|
normalizeEndpointName,
|
|
|
|
|
} from 'librechat-data-provider';
|
2025-09-06 00:21:02 +09:00
|
|
|
import type { TCustomConfig, TEndpoint, TTransactionsConfig } from 'librechat-data-provider';
|
2025-10-05 06:37:57 -04:00
|
|
|
import type { AppConfig } from '@librechat/data-schemas';
|
2025-11-10 19:05:30 -05:00
|
|
|
import { isEnabled } from '~/utils';
|
2025-08-26 12:10:18 -04:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Retrieves the balance configuration object
|
|
|
|
|
* */
|
|
|
|
|
export function getBalanceConfig(appConfig?: AppConfig): Partial<TCustomConfig['balance']> | null {
|
|
|
|
|
const isLegacyEnabled = isEnabled(process.env.CHECK_BALANCE);
|
|
|
|
|
const startBalance = process.env.START_BALANCE;
|
|
|
|
|
/** @type {} */
|
|
|
|
|
const config: Partial<TCustomConfig['balance']> = removeNullishValues({
|
|
|
|
|
enabled: isLegacyEnabled,
|
|
|
|
|
startBalance: startBalance != null && startBalance ? parseInt(startBalance, 10) : undefined,
|
|
|
|
|
});
|
|
|
|
|
if (!appConfig) {
|
|
|
|
|
return config;
|
|
|
|
|
}
|
|
|
|
|
return { ...config, ...(appConfig?.['balance'] ?? {}) };
|
|
|
|
|
}
|
|
|
|
|
|
2025-09-06 00:21:02 +09:00
|
|
|
/**
|
|
|
|
|
* Retrieves the transactions configuration object
|
|
|
|
|
* */
|
2025-10-05 06:37:57 -04:00
|
|
|
export function getTransactionsConfig(appConfig?: AppConfig): Partial<TTransactionsConfig> {
|
2025-09-06 00:21:02 +09:00
|
|
|
const defaultConfig: TTransactionsConfig = { enabled: true };
|
|
|
|
|
|
|
|
|
|
if (!appConfig) {
|
|
|
|
|
return defaultConfig;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const transactionsConfig = appConfig?.['transactions'] ?? defaultConfig;
|
|
|
|
|
const balanceConfig = getBalanceConfig(appConfig);
|
|
|
|
|
|
|
|
|
|
// If balance is enabled but transactions are disabled, force transactions to be enabled
|
|
|
|
|
// and log a warning
|
|
|
|
|
if (balanceConfig?.enabled && !transactionsConfig.enabled) {
|
|
|
|
|
logger.warn(
|
|
|
|
|
'Configuration warning: transactions.enabled=false is incompatible with balance.enabled=true. ' +
|
|
|
|
|
'Transactions will be enabled to ensure balance tracking works correctly.',
|
|
|
|
|
);
|
|
|
|
|
return { ...transactionsConfig, enabled: true };
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return transactionsConfig;
|
|
|
|
|
}
|
|
|
|
|
|
2025-08-26 12:10:18 -04:00
|
|
|
export const getCustomEndpointConfig = ({
|
|
|
|
|
endpoint,
|
|
|
|
|
appConfig,
|
|
|
|
|
}: {
|
|
|
|
|
endpoint: string | EModelEndpoint;
|
|
|
|
|
appConfig?: AppConfig;
|
|
|
|
|
}): Partial<TEndpoint> | undefined => {
|
|
|
|
|
if (!appConfig) {
|
|
|
|
|
throw new Error(`Config not found for the ${endpoint} custom endpoint.`);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const customEndpoints = appConfig.endpoints?.[EModelEndpoint.custom] ?? [];
|
|
|
|
|
return customEndpoints.find(
|
🗝️ feat: Credential Variables for DB-Sourced MCP Servers (#12044)
* feat: Allow Credential Variables in Headers for DB-sourced MCP Servers
- Removed the hasCustomUserVars check from ToolService.js, directly retrieving userMCPAuthMap.
- Updated MCPConnectionFactory and related classes to include a dbSourced flag for better handling of database-sourced configurations.
- Added integration tests to ensure proper behavior of dbSourced servers, verifying that sensitive placeholders are not resolved while allowing customUserVars.
- Adjusted various MCP-related files to accommodate the new dbSourced logic, ensuring consistent handling across the codebase.
* chore: MCPConnectionFactory Tests with Additional Flow Metadata for typing
- Updated MCPConnectionFactory tests to include new fields in flowMetadata: serverUrl and state.
- Enhanced mockFlowData in multiple test cases to reflect the updated structure, ensuring comprehensive coverage of the OAuth flow scenarios.
- Added authorization_endpoint to metadata in the test setup for improved validation of the OAuth process.
* refactor: Simplify MCPManager Configuration Handling
- Removed unnecessary type assertions and streamlined the retrieval of server configuration in MCPManager.
- Enhanced the handling of OAuth and database-sourced flags for improved clarity and efficiency.
- Updated tests to reflect changes in user object structure and ensure proper processing of MCP environment variables.
* refactor: Optimize User MCP Auth Map Retrieval in ToolService
- Introduced conditional loading of userMCPAuthMap based on the presence of MCP-delimited tools, improving efficiency by avoiding unnecessary calls.
- Updated the loadToolDefinitionsWrapper and loadAgentTools functions to reflect this change, enhancing overall performance and clarity.
* test: Add userMCPAuthMap gating tests in ToolService
- Introduced new tests to validate the logic for determining if MCP tools are present in the agent's tool list.
- Implemented various scenarios to ensure accurate detection of MCP tools, including edge cases for empty, undefined, and null tool lists.
- Enhanced clarity and coverage of the ToolService capability checking logic.
* refactor: Enhance MCP Environment Variable Processing
- Simplified the handling of the dbSourced parameter in the processMCPEnv function.
- Introduced a failsafe mechanism to derive dbSourced from options if not explicitly provided, improving robustness and clarity in MCP environment variable processing.
* refactor: Update Regex Patterns for Credential Placeholders in ServerConfigsDB
- Modified regex patterns to include additional credential/env placeholders that should not be allowed in user-provided configurations.
- Clarified comments to emphasize the security risks associated with credential exfiltration when MCP servers are shared between users.
* chore: field order
* refactor: Clean Up dbSourced Parameter Handling in processMCPEnv
- Reintroduced the failsafe mechanism for deriving the dbSourced parameter from options, ensuring clarity and robustness in MCP environment variable processing.
- Enhanced code readability by maintaining consistent comment structure.
* refactor: Update MCPOptions Type to Include Optional dbId
- Modified the processMCPEnv function to extend the MCPOptions type, allowing for an optional dbId property.
- Simplified the logic for deriving the dbSourced parameter by directly checking the dbId property, enhancing code clarity and maintainability.
2026-03-03 18:02:37 -05:00
|
|
|
(endpointConfig) =>
|
|
|
|
|
normalizeEndpointName(endpointConfig.name) === normalizeEndpointName(endpoint),
|
2025-08-26 12:10:18 -04:00
|
|
|
);
|
|
|
|
|
};
|