Enhanced ChatGPT Clone: Features Agents, MCP, Skills, DeepSeek, Anthropic, AWS, OpenAI, Responses API, Azure, Groq, o1, GPT-5, Mistral, OpenRouter, Vertex AI, Gemini, Artifacts, AI model switching, message search, Code Interpreter, langchain, DALL-E-3, OpenAPI Actions, Functions, Secure Multi-User Auth, Presets, open-source for self-hosting. Active
TypeScript aianthropicartifactsawsazurechatgptchatgpt-cloneclaudeclonedeepseekgeminigooglegpt-5librechatmcpo1openairesponses-apivisionwebui
🪵 chore: Remove Unnecessary Comments
Danny Avila32081245dad8
diff --git a/api/server/routes/mcp.js b/api/server/routes/mcp.jsindex 270c8525a9..4e35052cd7 100644--- a/api/server/routes/mcp.js+++ b/api/server/routes/mcp.js@@ -93,7 +93,6 @@ router.get('/:serverName/oauth/callback', async (req, res) => {return res.redirect('/oauth/error?error=missing_state');}- // Extract flow ID from stateconst flowId = state;logger.debug('[MCP OAuth] Using flow ID from state', { flowId });@@ -116,22 +115,17 @@ router.get('/:serverName/oauth/callback', async (req, res) => {hasCodeVerifier: !!flowState.codeVerifier,});- // Complete the OAuth flowlogger.debug('[MCP OAuth] Completing OAuth flow');const tokens = await MCPOAuthHandler.completeOAuthFlow(flowId, code, flowManager);logger.info('[MCP OAuth] OAuth flow completed, tokens received in callback route');- // Try to establish the MCP connection with the new tokenstry {const mcpManager = getMCPManager(flowState.userId);logger.debug(`[MCP OAuth] Attempting to reconnect ${serverName} with new OAuth tokens`);- // For user-level OAuth, try to establish the connectionif (flowState.userId !== 'system') {- // We need to get the user object - in this case we'll need to reconstruct itconst user = { id: flowState.userId };- // Try to establish connection with the new tokensconst userConnection = await mcpManager.getUserConnection({user,serverName,@@ -148,10 +142,8 @@ router.get('/:serverName/oauth/callback', async (req, res) => {`[MCP OAuth] Successfully reconnected ${serverName} for user ${flowState.userId}`,);- // Fetch and cache tools now that we have a successful connectionconst userTools = (await getCachedTools({ userId: flowState.userId })) || {};- // Remove any old tools from this server in the user's cacheconst mcpDelimiter = Constants.mcp_delimiter;for (const key of Object.keys(userTools)) {if (key.endsWith(`${mcpDelimiter}${serverName}`)) {@@ -159,7 +151,6 @@ router.get('/:serverName/oauth/callback', async (req, res) => {}}- // Add the new tools from this serverconst tools = await userConnection.fetchTools();for (const tool of tools) {const name = `${tool.name}${Constants.mcp_delimiter}${serverName}`;@@ -173,7 +164,6 @@ router.get('/:serverName/oauth/callback', async (req, res) => {};}- // Save the updated user tool cacheawait setCachedTools(userTools, { userId: flowState.userId });logger.debug(@@ -183,7 +173,6 @@ router.get('/:serverName/oauth/callback', async (req, res) => {logger.debug(`[MCP OAuth] System-level OAuth completed for ${serverName}`);}} catch (error) {- // Don't fail the OAuth callback if reconnection fails - the tokens are still savedlogger.warn(`[MCP OAuth] Failed to reconnect ${serverName} after OAuth, but tokens are saved:`,error,@@ -219,7 +208,6 @@ router.get('/oauth/tokens/:flowId', requireJwtAuth, async (req, res) => {return res.status(401).json({ error: 'User not authenticated' });}- // Allow system flows or user-owned flowsif (!flowId.startsWith(`${user.id}:`) && !flowId.startsWith('system:')) {return res.status(403).json({ error: 'Access denied' });}@@ -287,11 +275,7 @@ router.post('/oauth/cancel/:serverName', requireJwtAuth, async (req, res) => {const flowsCache = getLogStores(CacheKeys.FLOWS);const flowManager = getFlowStateManager(flowsCache);-- // Generate the flow ID for this user/server combinationconst flowId = MCPOAuthHandler.generateFlowId(user.id, serverName);-- // Check if flow existsconst flowState = await flowManager.getFlowState(flowId, 'mcp_oauth');if (!flowState) {@@ -302,7 +286,6 @@ router.post('/oauth/cancel/:serverName', requireJwtAuth, async (req, res) => {});}- // Cancel the flow by marking it as failedawait flowManager.failFlow(flowId, 'mcp_oauth', 'User cancelled OAuth flow');logger.info(`[MCP OAuth Cancel] Successfully cancelled OAuth flow for ${serverName}`);@@ -379,8 +362,7 @@ router.post('/:serverName/reinitialize', requireJwtAuth, async (req, res) => {createToken,deleteTokens,},- returnOnOAuth: true, // Return immediately when OAuth is initiated- // Add OAuth handlers to capture the OAuth URL when needed+ returnOnOAuth: true,oauthStart: async (authURL) => {logger.info(`[MCP Reinitialize] OAuth URL received: ${authURL}`);oauthUrl = authURL;@@ -395,7 +377,6 @@ router.post('/:serverName/reinitialize', requireJwtAuth, async (req, res) => {`[MCP Reinitialize] OAuth state - oauthRequired: ${oauthRequired}, oauthUrl: ${oauthUrl ? 'present' : 'null'}`,);- // Check if this is an OAuth error - if so, the flow state should be set up nowconst isOAuthError =err.message?.includes('OAuth') ||err.message?.includes('authentication') ||@@ -408,7 +389,6 @@ router.post('/:serverName/reinitialize', requireJwtAuth, async (req, res) => {`[MCP Reinitialize] OAuth required for ${serverName} (isOAuthError: ${isOAuthError}, oauthRequired: ${oauthRequired}, isOAuthFlowInitiated: ${isOAuthFlowInitiated})`,);oauthRequired = true;- // Don't return error - continue so frontend can handle OAuth} else {logger.error(`[MCP Reinitialize] Error initializing MCP server ${serverName} for user:`,@@ -418,11 +398,9 @@ router.post('/:serverName/reinitialize', requireJwtAuth, async (req, res) => {}}- // Only fetch and cache tools if we successfully connected (no OAuth required)if (userConnection && !oauthRequired) {const userTools = (await getCachedTools({ userId: user.id })) || {};- // Remove any old tools from this server in the user's cacheconst mcpDelimiter = Constants.mcp_delimiter;for (const key of Object.keys(userTools)) {if (key.endsWith(`${mcpDelimiter}${serverName}`)) {@@ -430,7 +408,6 @@ router.post('/:serverName/reinitialize', requireJwtAuth, async (req, res) => {}}- // Add the new tools from this serverconst tools = await userConnection.fetchTools();for (const tool of tools) {const name = `${tool.name}${Constants.mcp_delimiter}${serverName}`;@@ -444,7 +421,6 @@ router.post('/:serverName/reinitialize', requireJwtAuth, async (req, res) => {};}- // Save the updated user tool cacheawait setCachedTools(userTools, { userId: user.id });}@@ -593,19 +569,16 @@ router.get('/:serverName/auth-values', requireJwtAuth, async (req, res) => {const pluginKey = `${Constants.mcp_prefix}${serverName}`;const authValueFlags = {};- // Check existence of saved values for each custom user variable (don't fetch actual values)if (serverConfig.customUserVars && typeof serverConfig.customUserVars === 'object') {for (const varName of Object.keys(serverConfig.customUserVars)) {try {const value = await getUserPluginAuthValue(user.id, varName, false, pluginKey);- // Only store boolean flag indicating if value existsauthValueFlags[varName] = !!(value && value.length > 0);} catch (err) {logger.error(`[MCP Auth Value Flags] Error checking ${varName} for user ${user.id}:`,err,);- // Default to false if we can't checkauthValueFlags[varName] = false;}}diff --git a/client/src/components/Chat/Input/MCPSelect.tsx b/client/src/components/Chat/Input/MCPSelect.tsxindex 01c4d72a4d..e3d1878ffe 100644--- a/client/src/components/Chat/Input/MCPSelect.tsx+++ b/client/src/components/Chat/Input/MCPSelect.tsx@@ -35,8 +35,10 @@ function MCPSelect() {const statusIconProps = getServerStatusIconProps(serverName);const isServerInitializing = isInitializing(serverName);- // Common wrapper for the main content (check mark + text)- // Ensures Check & Text are adjacent and the group takes available space.+ /**+ Common wrapper for the main content (check mark + text).+ Ensures Check & Text are adjacent and the group takes available space.+ */const mainContentWrapper = (<buttontype="button"@@ -66,12 +68,10 @@ function MCPSelect() {[getServerStatusIconProps, isInitializing],);- // Don't render if no servers are selected and not pinnedif ((!mcpValues || mcpValues.length === 0) && !isPinned) {return null;}- // Don't render if no MCP servers are configuredif (!configuredServers || configuredServers.length === 0) {return null;}diff --git a/client/src/hooks/MCP/useMCPServerManager.ts b/client/src/hooks/MCP/useMCPServerManager.tsindex b42854545b..74e9dd7c77 100644--- a/client/src/hooks/MCP/useMCPServerManager.ts+++ b/client/src/hooks/MCP/useMCPServerManager.ts@@ -3,15 +3,15 @@ import { useToastContext } from '@librechat/client';import { useQueryClient } from '@tanstack/react-query';import { Constants, QueryKeys } from 'librechat-data-provider';import {+ useCancelMCPOAuthMutation,useUpdateUserPluginsMutation,useReinitializeMCPServerMutation,- useCancelMCPOAuthMutation,} from 'librechat-data-provider/react-query';-import { useMCPConnectionStatusQuery } from '~/data-provider/Tools/queries';import type { TUpdateUserPlugins, TPlugin } from 'librechat-data-provider';import type { ConfigFieldDetail } from '~/components/MCP/MCPConfigDialog';-import { useLocalize } from '~/hooks';+import { useMCPConnectionStatusQuery } from '~/data-provider/Tools/queries';import { useBadgeRowContext } from '~/Providers';+import { useLocalize } from '~/hooks';interface ServerState {isInitializing: boolean;@@ -273,10 +273,8 @@ export function useMCPServerManager() {const cancelOAuthFlow = useCallback((serverName: string) => {- // Call backend cancellation first, then clean up frontend state on successcancelOAuthMutation.mutate(serverName, {onSuccess: () => {- // Only clean up frontend state after backend confirms cancellationcleanupServerState(serverName);queryClient.invalidateQueries([QueryKeys.mcpConnectionStatus]);