mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-18 09:20:15 +01:00
🔧 refactor: Clean up logging statements
This commit is contained in:
parent
cfb19175fb
commit
4b4741b1aa
3 changed files with 12 additions and 43 deletions
|
|
@ -202,28 +202,13 @@ const getAvailableTools = async (req, res) => {
|
||||||
const serverName = parts[parts.length - 1];
|
const serverName = parts[parts.length - 1];
|
||||||
const serverConfig = customConfig?.mcpServers?.[serverName];
|
const serverConfig = customConfig?.mcpServers?.[serverName];
|
||||||
|
|
||||||
logger.warn(
|
|
||||||
`[getAvailableTools] Processing MCP tool:`,
|
|
||||||
JSON.stringify({
|
|
||||||
pluginKey: plugin.pluginKey,
|
|
||||||
serverName,
|
|
||||||
hasServerConfig: !!serverConfig,
|
|
||||||
hasCustomUserVars: !!serverConfig?.customUserVars,
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
|
|
||||||
if (!serverConfig) {
|
if (!serverConfig) {
|
||||||
logger.warn(
|
|
||||||
`[getAvailableTools] No server config found for ${serverName}, skipping auth check`,
|
|
||||||
);
|
|
||||||
toolsOutput.push(toolToAdd);
|
toolsOutput.push(toolToAdd);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handle MCP servers with customUserVars (user-level auth required)
|
// Handle MCP servers with customUserVars (user-level auth required)
|
||||||
if (serverConfig.customUserVars) {
|
if (serverConfig.customUserVars) {
|
||||||
logger.warn(`[getAvailableTools] Processing user-level MCP server: ${serverName}`);
|
|
||||||
|
|
||||||
// Build authConfig for MCP tools
|
// Build authConfig for MCP tools
|
||||||
toolToAdd.authConfig = Object.entries(serverConfig.customUserVars).map(([key, value]) => ({
|
toolToAdd.authConfig = Object.entries(serverConfig.customUserVars).map(([key, value]) => ({
|
||||||
authField: key,
|
authField: key,
|
||||||
|
|
@ -237,10 +222,6 @@ const getAvailableTools = async (req, res) => {
|
||||||
const mcpManager = getMCPManager(userId);
|
const mcpManager = getMCPManager(userId);
|
||||||
const connectionStatus = await mcpManager.getUserConnectionStatus(userId, serverName);
|
const connectionStatus = await mcpManager.getUserConnectionStatus(userId, serverName);
|
||||||
toolToAdd.authenticated = connectionStatus.connected;
|
toolToAdd.authenticated = connectionStatus.connected;
|
||||||
logger.warn(`[getAvailableTools] User-level connection status for ${serverName}:`, {
|
|
||||||
connected: connectionStatus.connected,
|
|
||||||
hasConnection: connectionStatus.hasConnection,
|
|
||||||
});
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error(
|
logger.error(
|
||||||
`[getAvailableTools] Error checking connection status for ${serverName}:`,
|
`[getAvailableTools] Error checking connection status for ${serverName}:`,
|
||||||
|
|
@ -254,38 +235,21 @@ const getAvailableTools = async (req, res) => {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Handle app-level MCP servers (no auth required)
|
// Handle app-level MCP servers (no auth required)
|
||||||
logger.warn(`[getAvailableTools] Processing app-level MCP server: ${serverName}`);
|
|
||||||
toolToAdd.authConfig = [];
|
toolToAdd.authConfig = [];
|
||||||
|
|
||||||
// Check if the app-level connection is active
|
// Check if the app-level connection is active
|
||||||
try {
|
try {
|
||||||
const mcpManager = getMCPManager();
|
const mcpManager = getMCPManager();
|
||||||
const allConnections = mcpManager.getAllConnections();
|
const allConnections = mcpManager.getAllConnections();
|
||||||
logger.warn(`[getAvailableTools] All app-level connections:`, {
|
|
||||||
connectionNames: Array.from(allConnections.keys()),
|
|
||||||
serverName,
|
|
||||||
});
|
|
||||||
|
|
||||||
const appConnection = mcpManager.getConnection(serverName);
|
const appConnection = mcpManager.getConnection(serverName);
|
||||||
logger.warn(`[getAvailableTools] Checking app-level connection for ${serverName}:`, {
|
|
||||||
hasConnection: !!appConnection,
|
|
||||||
connectionState: appConnection?.getConnectionState?.(),
|
|
||||||
});
|
|
||||||
|
|
||||||
if (appConnection) {
|
if (appConnection) {
|
||||||
const connectionState = appConnection.getConnectionState();
|
const connectionState = appConnection.getConnectionState();
|
||||||
logger.warn(`[getAvailableTools] App-level connection status for ${serverName}:`, {
|
|
||||||
connectionState,
|
|
||||||
hasConnection: !!appConnection,
|
|
||||||
});
|
|
||||||
|
|
||||||
// For app-level connections, consider them authenticated if they're in 'connected' state
|
// For app-level connections, consider them authenticated if they're in 'connected' state
|
||||||
// This is more reliable than isConnected() which does network calls
|
// This is more reliable than isConnected() which does network calls
|
||||||
toolToAdd.authenticated = connectionState === 'connected';
|
toolToAdd.authenticated = connectionState === 'connected';
|
||||||
logger.warn(`[getAvailableTools] Final authenticated status for ${serverName}:`, {
|
|
||||||
authenticated: toolToAdd.authenticated,
|
|
||||||
connectionState,
|
|
||||||
});
|
|
||||||
} else {
|
} else {
|
||||||
logger.warn(`[getAvailableTools] No app-level connection found for ${serverName}`);
|
logger.warn(`[getAvailableTools] No app-level connection found for ${serverName}`);
|
||||||
toolToAdd.authenticated = false;
|
toolToAdd.authenticated = false;
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,8 @@ const { getLogStores } = require('~/cache');
|
||||||
|
|
||||||
const router = Router();
|
const router = Router();
|
||||||
|
|
||||||
|
const suppressLogging = true;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initiate OAuth flow
|
* Initiate OAuth flow
|
||||||
* This endpoint is called when the user clicks the auth link in the UI
|
* This endpoint is called when the user clicks the auth link in the UI
|
||||||
|
|
@ -221,7 +223,7 @@ router.get('/connection/status', requireJwtAuth, async (req, res) => {
|
||||||
const connectionStatus = {};
|
const connectionStatus = {};
|
||||||
|
|
||||||
// Get all MCP server names from custom config
|
// Get all MCP server names from custom config
|
||||||
const config = await loadCustomConfig();
|
const config = await loadCustomConfig(suppressLogging);
|
||||||
const mcpConfig = config?.mcpServers;
|
const mcpConfig = config?.mcpServers;
|
||||||
|
|
||||||
if (mcpConfig) {
|
if (mcpConfig) {
|
||||||
|
|
@ -297,7 +299,7 @@ router.get('/:serverName/auth-values', requireJwtAuth, async (req, res) => {
|
||||||
return res.status(401).json({ error: 'User not authenticated' });
|
return res.status(401).json({ error: 'User not authenticated' });
|
||||||
}
|
}
|
||||||
|
|
||||||
const config = await loadCustomConfig();
|
const config = await loadCustomConfig(suppressLogging);
|
||||||
if (!config || !config.mcpServers || !config.mcpServers[serverName]) {
|
if (!config || !config.mcpServers || !config.mcpServers[serverName]) {
|
||||||
return res.status(404).json({
|
return res.status(404).json({
|
||||||
error: `MCP server '${serverName}' not found in configuration`,
|
error: `MCP server '${serverName}' not found in configuration`,
|
||||||
|
|
@ -494,7 +496,7 @@ router.post('/:serverName/reinitialize', requireJwtAuth, async (req, res) => {
|
||||||
|
|
||||||
logger.info(`[MCP Reinitialize] Reinitializing server: ${serverName}`);
|
logger.info(`[MCP Reinitialize] Reinitializing server: ${serverName}`);
|
||||||
|
|
||||||
const config = await loadCustomConfig();
|
const config = await loadCustomConfig(suppressLogging);
|
||||||
if (!config || !config.mcpServers || !config.mcpServers[serverName]) {
|
if (!config || !config.mcpServers || !config.mcpServers[serverName]) {
|
||||||
responseSent = true;
|
responseSent = true;
|
||||||
return res.status(404).json({
|
return res.status(404).json({
|
||||||
|
|
|
||||||
|
|
@ -23,9 +23,10 @@ let i = 0;
|
||||||
* Load custom configuration files and caches the object if the `cache` field at root is true.
|
* Load custom configuration files and caches the object if the `cache` field at root is true.
|
||||||
* Validation via parsing the config file with the config schema.
|
* Validation via parsing the config file with the config schema.
|
||||||
* @function loadCustomConfig
|
* @function loadCustomConfig
|
||||||
|
* @param {boolean} [suppressLogging=false] - If true, suppresses the verbose config logging of the entire config when called.
|
||||||
* @returns {Promise<TCustomConfig | null>} A promise that resolves to null or the custom config object.
|
* @returns {Promise<TCustomConfig | null>} A promise that resolves to null or the custom config object.
|
||||||
* */
|
* */
|
||||||
async function loadCustomConfig() {
|
async function loadCustomConfig(suppressLogging = false) {
|
||||||
// Use CONFIG_PATH if set, otherwise fallback to defaultConfigPath
|
// Use CONFIG_PATH if set, otherwise fallback to defaultConfigPath
|
||||||
const configPath = process.env.CONFIG_PATH || defaultConfigPath;
|
const configPath = process.env.CONFIG_PATH || defaultConfigPath;
|
||||||
|
|
||||||
|
|
@ -108,10 +109,12 @@ https://www.librechat.ai/docs/configuration/stt_tts`);
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
} else {
|
} else {
|
||||||
|
if (!suppressLogging) {
|
||||||
logger.info('Custom config file loaded:');
|
logger.info('Custom config file loaded:');
|
||||||
logger.info(JSON.stringify(customConfig, null, 2));
|
logger.info(JSON.stringify(customConfig, null, 2));
|
||||||
logger.debug('Custom config:', customConfig);
|
logger.debug('Custom config:', customConfig);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
(customConfig.endpoints?.custom ?? [])
|
(customConfig.endpoints?.custom ?? [])
|
||||||
.filter((endpoint) => endpoint.customParams)
|
.filter((endpoint) => endpoint.customParams)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue