🔧 refactor: Clean up logging statements

This commit is contained in:
Dustin Healy 2025-07-21 09:22:20 -07:00 committed by Danny Avila
parent cfb19175fb
commit 4b4741b1aa
No known key found for this signature in database
GPG key ID: BF31EEB2C5CA0956
3 changed files with 12 additions and 43 deletions

View file

@ -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;

View file

@ -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({

View file

@ -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<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
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 ?? [])