From 4b4741b1aa9c78fc134d58a7dd6d6a40bca56dcb Mon Sep 17 00:00:00 2001 From: Dustin Healy Date: Mon, 21 Jul 2025 09:22:20 -0700 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A7=20refactor:=20Clean=20up=20logging?= =?UTF-8?q?=20statements?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/server/controllers/PluginController.js | 36 ------------------- api/server/routes/mcp.js | 8 +++-- .../services/Config/loadCustomConfig.js | 11 +++--- 3 files changed, 12 insertions(+), 43 deletions(-) diff --git a/api/server/controllers/PluginController.js b/api/server/controllers/PluginController.js index 42054eb03f..08da567fbc 100644 --- a/api/server/controllers/PluginController.js +++ b/api/server/controllers/PluginController.js @@ -202,28 +202,13 @@ const getAvailableTools = async (req, res) => { const serverName = parts[parts.length - 1]; const serverConfig = customConfig?.mcpServers?.[serverName]; - logger.warn( - `[getAvailableTools] Processing MCP tool:`, - JSON.stringify({ - pluginKey: plugin.pluginKey, - serverName, - hasServerConfig: !!serverConfig, - hasCustomUserVars: !!serverConfig?.customUserVars, - }), - ); - if (!serverConfig) { - logger.warn( - `[getAvailableTools] No server config found for ${serverName}, skipping auth check`, - ); toolsOutput.push(toolToAdd); continue; } // Handle MCP servers with customUserVars (user-level auth required) if (serverConfig.customUserVars) { - logger.warn(`[getAvailableTools] Processing user-level MCP server: ${serverName}`); - // Build authConfig for MCP tools toolToAdd.authConfig = Object.entries(serverConfig.customUserVars).map(([key, value]) => ({ authField: key, @@ -237,10 +222,6 @@ const getAvailableTools = async (req, res) => { const mcpManager = getMCPManager(userId); const connectionStatus = await mcpManager.getUserConnectionStatus(userId, serverName); toolToAdd.authenticated = connectionStatus.connected; - logger.warn(`[getAvailableTools] User-level connection status for ${serverName}:`, { - connected: connectionStatus.connected, - hasConnection: connectionStatus.hasConnection, - }); } catch (error) { logger.error( `[getAvailableTools] Error checking connection status for ${serverName}:`, @@ -254,38 +235,21 @@ const getAvailableTools = async (req, res) => { } } else { // Handle app-level MCP servers (no auth required) - logger.warn(`[getAvailableTools] Processing app-level MCP server: ${serverName}`); toolToAdd.authConfig = []; // Check if the app-level connection is active try { const mcpManager = getMCPManager(); const allConnections = mcpManager.getAllConnections(); - logger.warn(`[getAvailableTools] All app-level connections:`, { - connectionNames: Array.from(allConnections.keys()), - serverName, - }); const appConnection = mcpManager.getConnection(serverName); - logger.warn(`[getAvailableTools] Checking app-level connection for ${serverName}:`, { - hasConnection: !!appConnection, - connectionState: appConnection?.getConnectionState?.(), - }); if (appConnection) { 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 // This is more reliable than isConnected() which does network calls toolToAdd.authenticated = connectionState === 'connected'; - logger.warn(`[getAvailableTools] Final authenticated status for ${serverName}:`, { - authenticated: toolToAdd.authenticated, - connectionState, - }); } else { logger.warn(`[getAvailableTools] No app-level connection found for ${serverName}`); toolToAdd.authenticated = false; diff --git a/api/server/routes/mcp.js b/api/server/routes/mcp.js index eb9259e5f4..eb7f439a33 100644 --- a/api/server/routes/mcp.js +++ b/api/server/routes/mcp.js @@ -11,6 +11,8 @@ const { getLogStores } = require('~/cache'); const router = Router(); +const suppressLogging = true; + /** * Initiate OAuth flow * 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 = {}; // Get all MCP server names from custom config - const config = await loadCustomConfig(); + const config = await loadCustomConfig(suppressLogging); const mcpConfig = config?.mcpServers; if (mcpConfig) { @@ -297,7 +299,7 @@ router.get('/:serverName/auth-values', requireJwtAuth, async (req, res) => { 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]) { return res.status(404).json({ 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}`); - const config = await loadCustomConfig(); + const config = await loadCustomConfig(suppressLogging); if (!config || !config.mcpServers || !config.mcpServers[serverName]) { responseSent = true; return res.status(404).json({ diff --git a/api/server/services/Config/loadCustomConfig.js b/api/server/services/Config/loadCustomConfig.js index 393281daf2..3fc1bf74a0 100644 --- a/api/server/services/Config/loadCustomConfig.js +++ b/api/server/services/Config/loadCustomConfig.js @@ -23,9 +23,10 @@ let i = 0; * 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. * @function loadCustomConfig + * @param {boolean} [suppressLogging=false] - If true, suppresses the verbose config logging of the entire config when called. * @returns {Promise} 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 const configPath = process.env.CONFIG_PATH || defaultConfigPath; @@ -108,9 +109,11 @@ https://www.librechat.ai/docs/configuration/stt_tts`); return null; } else { - logger.info('Custom config file loaded:'); - logger.info(JSON.stringify(customConfig, null, 2)); - logger.debug('Custom config:', customConfig); + if (!suppressLogging) { + logger.info('Custom config file loaded:'); + logger.info(JSON.stringify(customConfig, null, 2)); + logger.debug('Custom config:', customConfig); + } } (customConfig.endpoints?.custom ?? [])