Skip to content

Commit 3208124

Browse files
committed
🪵 chore: Remove Unnecessary Comments
1 parent 6fd3b56 commit 3208124

3 files changed

Lines changed: 8 additions & 37 deletions

File tree

api/server/routes/mcp.js

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,6 @@ router.get('/:serverName/oauth/callback', async (req, res) => {
9393
return res.redirect('/oauth/error?error=missing_state');
9494
}
9595

96-
// Extract flow ID from state
9796
const flowId = state;
9897
logger.debug('[MCP OAuth] Using flow ID from state', { flowId });
9998

@@ -116,22 +115,17 @@ router.get('/:serverName/oauth/callback', async (req, res) => {
116115
hasCodeVerifier: !!flowState.codeVerifier,
117116
});
118117

119-
// Complete the OAuth flow
120118
logger.debug('[MCP OAuth] Completing OAuth flow');
121119
const tokens = await MCPOAuthHandler.completeOAuthFlow(flowId, code, flowManager);
122120
logger.info('[MCP OAuth] OAuth flow completed, tokens received in callback route');
123121

124-
// Try to establish the MCP connection with the new tokens
125122
try {
126123
const mcpManager = getMCPManager(flowState.userId);
127124
logger.debug(`[MCP OAuth] Attempting to reconnect ${serverName} with new OAuth tokens`);
128125

129-
// For user-level OAuth, try to establish the connection
130126
if (flowState.userId !== 'system') {
131-
// We need to get the user object - in this case we'll need to reconstruct it
132127
const user = { id: flowState.userId };
133128

134-
// Try to establish connection with the new tokens
135129
const userConnection = await mcpManager.getUserConnection({
136130
user,
137131
serverName,
@@ -148,18 +142,15 @@ router.get('/:serverName/oauth/callback', async (req, res) => {
148142
`[MCP OAuth] Successfully reconnected ${serverName} for user ${flowState.userId}`,
149143
);
150144

151-
// Fetch and cache tools now that we have a successful connection
152145
const userTools = (await getCachedTools({ userId: flowState.userId })) || {};
153146

154-
// Remove any old tools from this server in the user's cache
155147
const mcpDelimiter = Constants.mcp_delimiter;
156148
for (const key of Object.keys(userTools)) {
157149
if (key.endsWith(`${mcpDelimiter}${serverName}`)) {
158150
delete userTools[key];
159151
}
160152
}
161153

162-
// Add the new tools from this server
163154
const tools = await userConnection.fetchTools();
164155
for (const tool of tools) {
165156
const name = `${tool.name}${Constants.mcp_delimiter}${serverName}`;
@@ -173,7 +164,6 @@ router.get('/:serverName/oauth/callback', async (req, res) => {
173164
};
174165
}
175166

176-
// Save the updated user tool cache
177167
await setCachedTools(userTools, { userId: flowState.userId });
178168

179169
logger.debug(
@@ -183,7 +173,6 @@ router.get('/:serverName/oauth/callback', async (req, res) => {
183173
logger.debug(`[MCP OAuth] System-level OAuth completed for ${serverName}`);
184174
}
185175
} catch (error) {
186-
// Don't fail the OAuth callback if reconnection fails - the tokens are still saved
187176
logger.warn(
188177
`[MCP OAuth] Failed to reconnect ${serverName} after OAuth, but tokens are saved:`,
189178
error,
@@ -219,7 +208,6 @@ router.get('/oauth/tokens/:flowId', requireJwtAuth, async (req, res) => {
219208
return res.status(401).json({ error: 'User not authenticated' });
220209
}
221210

222-
// Allow system flows or user-owned flows
223211
if (!flowId.startsWith(`${user.id}:`) && !flowId.startsWith('system:')) {
224212
return res.status(403).json({ error: 'Access denied' });
225213
}
@@ -287,11 +275,7 @@ router.post('/oauth/cancel/:serverName', requireJwtAuth, async (req, res) => {
287275

288276
const flowsCache = getLogStores(CacheKeys.FLOWS);
289277
const flowManager = getFlowStateManager(flowsCache);
290-
291-
// Generate the flow ID for this user/server combination
292278
const flowId = MCPOAuthHandler.generateFlowId(user.id, serverName);
293-
294-
// Check if flow exists
295279
const flowState = await flowManager.getFlowState(flowId, 'mcp_oauth');
296280

297281
if (!flowState) {
@@ -302,7 +286,6 @@ router.post('/oauth/cancel/:serverName', requireJwtAuth, async (req, res) => {
302286
});
303287
}
304288

305-
// Cancel the flow by marking it as failed
306289
await flowManager.failFlow(flowId, 'mcp_oauth', 'User cancelled OAuth flow');
307290

308291
logger.info(`[MCP OAuth Cancel] Successfully cancelled OAuth flow for ${serverName}`);
@@ -379,8 +362,7 @@ router.post('/:serverName/reinitialize', requireJwtAuth, async (req, res) => {
379362
createToken,
380363
deleteTokens,
381364
},
382-
returnOnOAuth: true, // Return immediately when OAuth is initiated
383-
// Add OAuth handlers to capture the OAuth URL when needed
365+
returnOnOAuth: true,
384366
oauthStart: async (authURL) => {
385367
logger.info(`[MCP Reinitialize] OAuth URL received: ${authURL}`);
386368
oauthUrl = authURL;
@@ -395,7 +377,6 @@ router.post('/:serverName/reinitialize', requireJwtAuth, async (req, res) => {
395377
`[MCP Reinitialize] OAuth state - oauthRequired: ${oauthRequired}, oauthUrl: ${oauthUrl ? 'present' : 'null'}`,
396378
);
397379

398-
// Check if this is an OAuth error - if so, the flow state should be set up now
399380
const isOAuthError =
400381
err.message?.includes('OAuth') ||
401382
err.message?.includes('authentication') ||
@@ -408,7 +389,6 @@ router.post('/:serverName/reinitialize', requireJwtAuth, async (req, res) => {
408389
`[MCP Reinitialize] OAuth required for ${serverName} (isOAuthError: ${isOAuthError}, oauthRequired: ${oauthRequired}, isOAuthFlowInitiated: ${isOAuthFlowInitiated})`,
409390
);
410391
oauthRequired = true;
411-
// Don't return error - continue so frontend can handle OAuth
412392
} else {
413393
logger.error(
414394
`[MCP Reinitialize] Error initializing MCP server ${serverName} for user:`,
@@ -418,19 +398,16 @@ router.post('/:serverName/reinitialize', requireJwtAuth, async (req, res) => {
418398
}
419399
}
420400

421-
// Only fetch and cache tools if we successfully connected (no OAuth required)
422401
if (userConnection && !oauthRequired) {
423402
const userTools = (await getCachedTools({ userId: user.id })) || {};
424403

425-
// Remove any old tools from this server in the user's cache
426404
const mcpDelimiter = Constants.mcp_delimiter;
427405
for (const key of Object.keys(userTools)) {
428406
if (key.endsWith(`${mcpDelimiter}${serverName}`)) {
429407
delete userTools[key];
430408
}
431409
}
432410

433-
// Add the new tools from this server
434411
const tools = await userConnection.fetchTools();
435412
for (const tool of tools) {
436413
const name = `${tool.name}${Constants.mcp_delimiter}${serverName}`;
@@ -444,7 +421,6 @@ router.post('/:serverName/reinitialize', requireJwtAuth, async (req, res) => {
444421
};
445422
}
446423

447-
// Save the updated user tool cache
448424
await setCachedTools(userTools, { userId: user.id });
449425
}
450426

@@ -593,19 +569,16 @@ router.get('/:serverName/auth-values', requireJwtAuth, async (req, res) => {
593569
const pluginKey = `${Constants.mcp_prefix}${serverName}`;
594570
const authValueFlags = {};
595571

596-
// Check existence of saved values for each custom user variable (don't fetch actual values)
597572
if (serverConfig.customUserVars && typeof serverConfig.customUserVars === 'object') {
598573
for (const varName of Object.keys(serverConfig.customUserVars)) {
599574
try {
600575
const value = await getUserPluginAuthValue(user.id, varName, false, pluginKey);
601-
// Only store boolean flag indicating if value exists
602576
authValueFlags[varName] = !!(value && value.length > 0);
603577
} catch (err) {
604578
logger.error(
605579
`[MCP Auth Value Flags] Error checking ${varName} for user ${user.id}:`,
606580
err,
607581
);
608-
// Default to false if we can't check
609582
authValueFlags[varName] = false;
610583
}
611584
}

client/src/components/Chat/Input/MCPSelect.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,10 @@ function MCPSelect() {
3535
const statusIconProps = getServerStatusIconProps(serverName);
3636
const isServerInitializing = isInitializing(serverName);
3737

38-
// Common wrapper for the main content (check mark + text)
39-
// Ensures Check & Text are adjacent and the group takes available space.
38+
/**
39+
Common wrapper for the main content (check mark + text).
40+
Ensures Check & Text are adjacent and the group takes available space.
41+
*/
4042
const mainContentWrapper = (
4143
<button
4244
type="button"
@@ -66,12 +68,10 @@ function MCPSelect() {
6668
[getServerStatusIconProps, isInitializing],
6769
);
6870

69-
// Don't render if no servers are selected and not pinned
7071
if ((!mcpValues || mcpValues.length === 0) && !isPinned) {
7172
return null;
7273
}
7374

74-
// Don't render if no MCP servers are configured
7575
if (!configuredServers || configuredServers.length === 0) {
7676
return null;
7777
}

client/src/hooks/MCP/useMCPServerManager.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@ import { useToastContext } from '@librechat/client';
33
import { useQueryClient } from '@tanstack/react-query';
44
import { Constants, QueryKeys } from 'librechat-data-provider';
55
import {
6+
useCancelMCPOAuthMutation,
67
useUpdateUserPluginsMutation,
78
useReinitializeMCPServerMutation,
8-
useCancelMCPOAuthMutation,
99
} from 'librechat-data-provider/react-query';
10-
import { useMCPConnectionStatusQuery } from '~/data-provider/Tools/queries';
1110
import type { TUpdateUserPlugins, TPlugin } from 'librechat-data-provider';
1211
import type { ConfigFieldDetail } from '~/components/MCP/MCPConfigDialog';
13-
import { useLocalize } from '~/hooks';
12+
import { useMCPConnectionStatusQuery } from '~/data-provider/Tools/queries';
1413
import { useBadgeRowContext } from '~/Providers';
14+
import { useLocalize } from '~/hooks';
1515

1616
interface ServerState {
1717
isInitializing: boolean;
@@ -273,10 +273,8 @@ export function useMCPServerManager() {
273273

274274
const cancelOAuthFlow = useCallback(
275275
(serverName: string) => {
276-
// Call backend cancellation first, then clean up frontend state on success
277276
cancelOAuthMutation.mutate(serverName, {
278277
onSuccess: () => {
279-
// Only clean up frontend state after backend confirms cancellation
280278
cleanupServerState(serverName);
281279
queryClient.invalidateQueries([QueryKeys.mcpConnectionStatus]);
282280

0 commit comments

Comments
 (0)