🔌 feat: MCP OAuth Integration in Chat UI

- **Real-Time Connection Status**: New backend APIs and React Query hooks provide live MCP server connection monitoring with automatic UI updates
- **OAuth Flow Components**: Complete MCPConfigDialog, ServerInitializationSection, and CustomUserVarsSection with OAuth URL handling and polling-based completion
- **Enhanced Server Selection**: MCPSelect component with connection-aware filtering, visual status indicators, and better credential management UX

(still needs a lot of refinement since there is bloat/unused vars and functions leftover from the ideation phase on how to approach OAuth and connection statuses)
This commit is contained in:
Dustin Healy 2025-07-21 01:29:33 -07:00
parent b39b60c012
commit 63140237a6
27 changed files with 1760 additions and 286 deletions

View file

@ -108,8 +108,6 @@ 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);
}

View file

@ -41,6 +41,38 @@ const getUserPluginAuthValue = async (userId, authField, throwError = true) => {
}
};
/**
* Asynchronously retrieves and decrypts the authentication value for a user's specific plugin, based on a specified authentication field and plugin key.
*
* @param {string} userId - The unique identifier of the user for whom the plugin authentication value is to be retrieved.
* @param {string} authField - The specific authentication field (e.g., 'API_KEY', 'URL') whose value is to be retrieved and decrypted.
* @param {string} pluginKey - The plugin key to filter by (e.g., 'mcp_github-mcp').
* @param {boolean} throwError - Whether to throw an error if the authentication value does not exist. Defaults to `true`.
* @returns {Promise<string|null>} A promise that resolves to the decrypted authentication value if found, or `null` if no such authentication value exists for the given user, field, and plugin.
*
* @throws {Error} Throws an error if there's an issue during the retrieval or decryption process, or if the authentication value does not exist.
* @async
*/
const getUserPluginAuthValueByPlugin = async (userId, authField, pluginKey, throwError = true) => {
try {
const pluginAuth = await findOnePluginAuth({ userId, authField, pluginKey });
if (!pluginAuth) {
throw new Error(
`No plugin auth ${authField} found for user ${userId} and plugin ${pluginKey}`,
);
}
const decryptedValue = await decrypt(pluginAuth.value);
return decryptedValue;
} catch (err) {
if (!throwError) {
return null;
}
logger.error('[getUserPluginAuthValueByPlugin]', err);
throw err;
}
};
// const updateUserPluginAuth = async (userId, authField, pluginKey, value) => {
// try {
// const encryptedValue = encrypt(value);
@ -119,6 +151,7 @@ const deleteUserPluginAuth = async (userId, authField, all = false, pluginKey) =
module.exports = {
getUserPluginAuthValue,
getUserPluginAuthValueByPlugin,
updateUserPluginAuth,
deleteUserPluginAuth,
};

View file

@ -10,6 +10,15 @@ const { getLogStores } = require('~/cache');
* @param {import('express').Application} app - Express app instance
*/
async function initializeMCPs(app) {
// TEMPORARY: Reset all OAuth tokens for fresh testing
try {
logger.info('[MCP] Resetting all OAuth tokens for fresh testing...');
await deleteTokens({});
logger.info('[MCP] All OAuth tokens reset successfully');
} catch (error) {
logger.error('[MCP] Error resetting OAuth tokens:', error);
}
const mcpServers = app.locals.mcpConfig;
if (!mcpServers) {
return;
@ -36,7 +45,7 @@ async function initializeMCPs(app) {
const flowManager = flowsCache ? getFlowStateManager(flowsCache) : null;
try {
await mcpManager.initializeMCPs({
const oauthRequirements = await mcpManager.initializeMCPs({
mcpServers: filteredServers,
flowManager,
tokenMethods: {
@ -64,6 +73,9 @@ async function initializeMCPs(app) {
logger.debug('Cleared tools array cache after MCP initialization');
logger.info('MCP servers initialized successfully');
// Store OAuth requirement information in app locals for client access
app.locals.mcpOAuthRequirements = oauthRequirements;
} catch (error) {
logger.error('Failed to initialize MCP servers:', error);
}