From 394bb6242b5d45c4805b41b8be2313674a5573b7 Mon Sep 17 00:00:00 2001 From: Danny Avila Date: Thu, 4 Dec 2025 19:52:32 -0500 Subject: [PATCH] =?UTF-8?q?=F0=9F=93=A6=20chore:=20Bump=20MCP=20SDK:=20Fix?= =?UTF-8?q?=20Types=20and=20MCP=20OAuth=20due=20to=20Update=20(#10811)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * chore: Bump @modelcontextprotocol/sdk to version 1.24.3 * refactor: Update resource handling in MCP parsers and types - Simplified resource text checks in `parseAsString` and `formatToolContent` functions to ensure proper existence checks. - Removed unnecessary resource name and description handling to streamline output. - Updated type definitions in `index.ts` to align with the new structure from `@modelcontextprotocol/sdk`, enhancing type safety and clarity. - Added `logo_uri` and `tos_uri` properties to `MCPOAuthHandler` for improved OAuth metadata support. * refactor: Update custom endpoint configurations and type definitions - Removed unused type imports and streamlined the custom parameters handling in `loadCustomEndpointsConfig`. - Adjusted the `TCustomEndpointsConfig` type to utilize `TConfig` instead of `TEndpoint`, enhancing type accuracy. - Made the endpoint schema optional in the configuration to improve flexibility. * fix: Implement token cleanup and error handling for invalid OAuth tokens - Added `cleanupInvalidTokens` method to remove invalid OAuth tokens from storage when detected. - Introduced `isInvalidTokenError` method to identify errors indicating revoked or expired tokens. - Integrated token cleanup logic into the connection attempt process to ensure fresh OAuth flow on invalid token detection. * feat: Add revoke OAuth functionality in Server Initialization - Introduced a new button to revoke OAuth for servers, enhancing user control over OAuth permissions. - Updated the `useMCPServerManager` hook to include a standalone `revokeOAuthForServer` function for managing OAuth revocation. - Adjusted the UI to conditionally render the revoke button based on server requirements. * fix: error handling for authentication in MCPConnection - Updated the error handling logic in MCPConnection to better identify various authentication error indicators, including 401 status, invalid tokens, and unauthorized messages. - Removed the deprecated cleanupInvalidTokens method and integrated its logic into the connection attempt process for improved clarity and efficiency. - Adjusted the MCPConnectionFactory to streamline the connection attempt process and handle OAuth errors more effectively. * refactor: Update button rendering in ServerInitializationSection - Removed the existing button for server initialization and replaced it with a new button implementation, maintaining the same functionality. - Ensured consistent rendering of the button within the component's layout. * chore: update resource type usage in parsers.test.ts --- api/package.json | 2 +- .../MCP/ServerInitializationSection.tsx | 28 +++++++---- client/src/hooks/MCP/useMCPServerManager.ts | 14 ++++++ package-lock.json | 45 ++++++++++++------ packages/api/package.json | 2 +- packages/api/src/endpoints/custom/config.ts | 4 +- packages/api/src/mcp/MCPConnectionFactory.ts | 46 +++++++++++++------ .../api/src/mcp/__tests__/parsers.test.ts | 23 ++-------- packages/api/src/mcp/connection.ts | 26 ++++++++--- packages/api/src/mcp/oauth/handler.ts | 15 +++++- packages/api/src/mcp/parsers.ts | 16 +------ packages/api/src/mcp/types/index.ts | 17 +++++-- packages/api/src/types/endpoints.ts | 4 +- packages/data-provider/src/config.ts | 3 +- 14 files changed, 155 insertions(+), 90 deletions(-) diff --git a/api/package.json b/api/package.json index 555064d195..cdcb71e748 100644 --- a/api/package.json +++ b/api/package.json @@ -47,7 +47,7 @@ "@librechat/api": "*", "@librechat/data-schemas": "*", "@microsoft/microsoft-graph-client": "^3.0.7", - "@modelcontextprotocol/sdk": "^1.21.0", + "@modelcontextprotocol/sdk": "^1.24.3", "@node-saml/passport-saml": "^5.1.0", "@smithy/node-http-handler": "^4.4.5", "axios": "^1.12.1", diff --git a/client/src/components/MCP/ServerInitializationSection.tsx b/client/src/components/MCP/ServerInitializationSection.tsx index d736b5cd7b..b5f71335d7 100644 --- a/client/src/components/MCP/ServerInitializationSection.tsx +++ b/client/src/components/MCP/ServerInitializationSection.tsx @@ -1,8 +1,7 @@ import React from 'react'; -import { RefreshCw } from 'lucide-react'; +import { RefreshCw, Trash2 } from 'lucide-react'; import { Button, Spinner } from '@librechat/client'; import { useLocalize, useMCPServerManager, useMCPConnectionStatus } from '~/hooks'; -import { useGetStartupConfig } from '~/data-provider'; interface ServerInitializationSectionProps { sidePanel?: boolean; @@ -22,12 +21,13 @@ export default function ServerInitializationSection({ const localize = useLocalize(); const { + getOAuthUrl, + isCancellable, + isInitializing, + cancelOAuthFlow, initializeServer, availableMCPServers, - cancelOAuthFlow, - isInitializing, - isCancellable, - getOAuthUrl, + revokeOAuthForServer, } = useMCPServerManager({ conversationId }); const { connectionStatus } = useMCPConnectionStatus({ @@ -73,7 +73,6 @@ export default function ServerInitializationSection({ // Unified button rendering const isReinit = shouldShowReinit; - const outerClass = isReinit ? 'flex justify-start' : 'flex justify-end'; const buttonVariant = isReinit ? undefined : 'default'; let buttonText = ''; @@ -94,13 +93,24 @@ export default function ServerInitializationSection({ ); return ( -
+
+ {requiresOAuth && revokeOAuthForServer && ( + + )}