Skip to content

🏹 feat: Concurrent MCP Initialization Support #8677

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jul 28, 2025

Conversation

dustinhealy
Copy link
Collaborator

@dustinhealy dustinhealy commented Jul 26, 2025

Summary

This PR enhances MCP initializations to handle multiple server connections and OAuth flows concurrently. It refactors existing single-server initialization processes to work in parallel, creating a smoother experience when managing server connections for users. Key changes include the extraction of reusable utility functions for MCP server status management, the replacement of the previous initialization hook with a centralized server manager, and the addition of a new per-server connection status endpoint.

Core Features

Frontend Changes: MCP Panel and Server Initialization

  • Replaced the useMCPServerInitialization hook with a new useMCPServerManager hook to centralize server management logic, enabling support for multiple OAuth flows and improving initialization handling. [1] [2]
  • Updated the ServerInitializationSection component to use the new useMCPServerManager hook, simplifying state management and aligning with the updated backend logic. [1] [2] [3] [4] [5]

Backend Changes: MCP Server Status Management

  • Refactored the /connection/status endpoint to use new utility functions (getMCPSetupData, checkOAuthFlowStatus, getServerConnectionStatus) for modular handling of MCP server connection statuses. These functions centralize logic for retrieving configuration, checking OAuth flows, and determining connection states.
  • Added a new /connection/status/:serverName endpoint to fetch the connection status of a specific MCP server, improving granularity and user-specific responses.

Change Type

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update
  • Translation update

Details & Change Breakdown

1. Server-Side Refactor (mcp.js)

  • Added new helper functions: getMCPSetupData, checkOAuthFlowStatus, and getServerConnectionStatus for improved modularity and clarity.
  • Added /connection/status/:serverName endpoins for per-server reporting of server connection status.

2. Client-Side Refactor

  • MCPPanel.tsx: Refactored to use centralized logic for handling multiple server connections and states.
  • ServerInitializationSection.tsx: Updated to handle OAuth flows and connection status using the shared initialization hook (useMCPServerManager).

3. React Queries and Hooks

  • useMCPServerManager Hook: Refactored useMCPServerInitialization into the new shared useMCPServerManager hook to manage concurrent server initializations and connection states.
  • New Query: Added useMCPServerConnectionStatusQuery for server-specific connection status checks in react-query-service.ts.

4. Localization and Data Provider Improvements

  • Localization Updates:

    • translation.json: Minor adjustments for connection status and server initialization strings.
  • Data Provider Updates:

    • Added new endpoints for server-specific connection status (api-endpoints.ts).
    • Introduced new types for MCP server connection status response (packages/data-provider/src/types/queries.ts).

Testing

  • Confirmed UI components reflect real-time server connection status and MCP selection at all times across MCPSelect, MCPSubMenu, and MCPPanel - especially during initialization, OAuth flows, and post cancellation.
  • Tested simultaneous OAuth flow handling, initialization, and cancellation for github-mcp, filesystem, playwright, atlassian, and spotify servers to ensure resilient and consistent status reporting, UI updates, and initalization / OAuth flow management.

Checklist

  • My code adheres to this project's style guidelines
  • I have performed a self-review of my own code
  • I have commented in any complex areas of my code
  • I have made pertinent documentation changes
  • My changes do not introduce new warnings
  • Local unit tests pass with my changes

This comment was marked as resolved.

@dustinhealy dustinhealy marked this pull request as ready for review July 26, 2025 22:35
@danny-avila

This comment was marked as resolved.

@danny-avila danny-avila marked this pull request as draft July 27, 2025 16:48
- Introduced new functions to retrieve and manage connection status for multiple MCP servers, including OAuth flow checks and server-specific status retrieval.
- Refactored the MCP connection status endpoints to support both all servers and individual server queries.
- Replaced the old server initialization hook with a new `useMCPServerManager` hook for improved state management and handling of multiple OAuth flows.
- Updated the MCPPanel component to utilize the new context provider for better state handling and UI updates.
- Fixed a number of UI bugs when initializing servers
@dustinhealy dustinhealy force-pushed the feat/per-server-polling branch from cbf270d to d5a8a49 Compare July 27, 2025 22:51
@dustinhealy dustinhealy force-pushed the feat/per-server-polling branch from d5a8a49 to 2c70ace Compare July 27, 2025 23:28
@dustinhealy dustinhealy marked this pull request as ready for review July 27, 2025 23:38
@danny-avila danny-avila merged commit 0ef3fef into dev Jul 28, 2025
7 checks passed
@danny-avila danny-avila deleted the feat/per-server-polling branch July 28, 2025 16:25
jhrozek pushed a commit to StacklokLabs/LibreChat that referenced this pull request Jul 31, 2025
* ✨ feat: Enhance MCP Connection Status Management

- Introduced new functions to retrieve and manage connection status for multiple MCP servers, including OAuth flow checks and server-specific status retrieval.
- Refactored the MCP connection status endpoints to support both all servers and individual server queries.
- Replaced the old server initialization hook with a new `useMCPServerManager` hook for improved state management and handling of multiple OAuth flows.
- Updated the MCPPanel component to utilize the new context provider for better state handling and UI updates.
- Fixed a number of UI bugs when initializing servers

* 🗣️ i18n: Remove unused strings from translation.json

* refactor: move helper functions out of the route module into mcp service file

* ci: add tests for newly added functions in mcp service file

* fix: memoize setMCPValues to avoid render loop
xycjscs pushed a commit to xycjscs/LibreChat that referenced this pull request Aug 9, 2025
* ✨ feat: Enhance MCP Connection Status Management

- Introduced new functions to retrieve and manage connection status for multiple MCP servers, including OAuth flow checks and server-specific status retrieval.
- Refactored the MCP connection status endpoints to support both all servers and individual server queries.
- Replaced the old server initialization hook with a new `useMCPServerManager` hook for improved state management and handling of multiple OAuth flows.
- Updated the MCPPanel component to utilize the new context provider for better state handling and UI updates.
- Fixed a number of UI bugs when initializing servers

* 🗣️ i18n: Remove unused strings from translation.json

* refactor: move helper functions out of the route module into mcp service file

* ci: add tests for newly added functions in mcp service file

* fix: memoize setMCPValues to avoid render loop
miguelwon pushed a commit to miguelwon/LibreChat that referenced this pull request Aug 10, 2025
* ✨ feat: Enhance MCP Connection Status Management

- Introduced new functions to retrieve and manage connection status for multiple MCP servers, including OAuth flow checks and server-specific status retrieval.
- Refactored the MCP connection status endpoints to support both all servers and individual server queries.
- Replaced the old server initialization hook with a new `useMCPServerManager` hook for improved state management and handling of multiple OAuth flows.
- Updated the MCPPanel component to utilize the new context provider for better state handling and UI updates.
- Fixed a number of UI bugs when initializing servers

* 🗣️ i18n: Remove unused strings from translation.json

* refactor: move helper functions out of the route module into mcp service file

* ci: add tests for newly added functions in mcp service file

* fix: memoize setMCPValues to avoid render loop
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants