Repository navigation
👯 fix: Preserve MCP Connect Results Across Replicas - #17571
Conversation
|
@codex review |
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 72981b317d
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
@codex review |
There was a problem hiding this comment.
🟡 Changes recommended
OAuth cancellation can leave initialization stuck or block polling on retries, while recovery-related timestamp changes can invalidate a successful connection result and incorrectly show Disconnected.
3 open issues
What changed in this PR
This PR preserves explicit MCP Connect outcomes within the signed-in browser session, preventing status reads from a replica without a local connection from incorrectly showing Disconnected.
Changes:
- Moves Connect handling and status resolution into the TypeScript API package, with explicit status sources and authorization generations.
- Adds session-scoped Connect results, retry ordering, logout cleanup, and shared status presentation.
- Adds focused regressions and a two-replica browser test wired into CI.
| File | Description |
|---|---|
packages/data-provider/src/types/queries.ts |
Adds connection status source metadata. |
packages/data-provider/src/types/mcpServers.ts |
Adds authorization generation to Connect responses. |
packages/data-provider/src/data-service.ts |
Applies the configurable Connect timeout. |
packages/data-provider/src/clientLimits.ts |
Defines the Connect timeout setting and default. |
packages/data-provider/src/clientLimits.spec.ts |
Tests Connect timeout defaults and validation. |
packages/api/src/mcp/readiness.ts |
Resolves transport and authorization status separately. |
packages/api/src/mcp/readiness.spec.ts |
Tests replica-local status observations. |
packages/api/src/mcp/connection.ts |
Exposes the local connection state. |
packages/api/src/mcp/connect.ts |
Implements injected Connect handling and fresh retries. |
packages/api/src/mcp/connect.spec.ts |
Tests Connect outcomes, OAuth responses, and safe errors. |
packages/api/src/index.ts |
Exports the new MCP handlers. |
e2e/specs/mock/mcp-connect-replicas.spec.ts |
Tests cross-replica status, tool calls, and retry recovery. |
e2e/setup/start-server-cluster.js |
Adds replica targeting and controlled primary shutdown. |
e2e/setup/fake-model.js |
Adds a deterministic replica-test tool call. |
e2e/setup/fake-mcp-status-server.js |
Provides a controllable MCP server fixture. |
e2e/playwright.config.mock.ts |
Configures the MCP connection fixture. |
e2e/playwright.config.mcp-connect.ts |
Defines the dedicated browser-test configuration. |
client/src/store/mcp.ts |
Stores session-owned Connect results and reset behavior. |
client/src/Providers/__tests__/BadgeRowContext.spec.tsx |
Supplies authentication context for manager consumers. |
client/src/locales/en/translation.json |
Removes the obsolete Offline translation key. |
client/src/hooks/MCP/useMCPServerManager.ts |
Integrates Connect results, attempt ordering, and cleanup. |
client/src/hooks/MCP/connection.ts |
Applies results using owner, configuration, and generation checks. |
client/src/hooks/MCP/__tests__/useMCPServerManager.spec.tsx |
Tests polling, retry ordering, and session invalidation. |
client/src/hooks/MCP/__tests__/connection.spec.ts |
Tests configuration identity and metadata changes. |
client/src/hooks/AuthContext.tsx |
Clears MCP session state at logout. |
client/src/hooks/__tests__/AuthContext.spec.tsx |
Tests logout cleanup of MCP state. |
client/src/components/SidePanel/MCPBuilder/MCPStatusBadge.tsx |
Removes the builder-specific badge implementation. |
client/src/components/SidePanel/MCPBuilder/MCPServerCard.tsx |
Uses shared status helpers and configuration readiness. |
client/src/components/SidePanel/MCPBuilder/MCPServerCard.spec.tsx |
Updates the shared badge mock. |
client/src/components/MCP/MCPStatusBadge.tsx |
Provides shared status badge rendering. |
client/src/components/MCP/MCPStatusBadge.spec.tsx |
Tests visibility of request-scoped errors. |
client/src/components/MCP/mcpServerUtils.ts |
Unifies status presentation and required-variable checks. |
client/src/components/MCP/mcpServerUtils.spec.ts |
Tests attachment blocking when variables are missing. |
client/src/components/MCP/MCPServerStatusIcon.tsx |
Uses shared status colors. |
client/src/components/MCP/MCPConfigDialog.tsx |
Reuses shared status labels and badges. |
client/src/components/Chat/__tests__/ChatView.subagent.spec.tsx |
Supplies authentication context in chat tests. |
api/server/services/MCP.spec.js |
Updates assertions for the status resolver contract. |
api/server/services/MCP.js |
Delegates status resolution to the TypeScript package. |
api/server/routes/mcp.js |
Wires the Connect handler and exposes status sources. |
api/server/routes/__tests__/mcp.spec.js |
Updates credential-loading assertions after extraction. |
.github/workflows/playwright-mock.yml |
Runs the Connect regression in the two-replica job. |
Review effort: Balanced
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 4ec35977da
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 2b2b3adff8
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: f4a87db393
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
@codex review |
|
Codex Review: Didn't find any major issues. 🎉 Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
7bce4c0 to
deafe9d
Compare
|
@codex review |
|
/quality risk scopes=api,server |
Quality reportOutdated: this request is for an earlier PR commit. Gate: open. The selected checks completed. Scores and risk levels are advisory. Status: completed (success). Actions run, attempt 1.
Change riskTakeaway: 4 changed lines have no test. Highest CRAP among changed functions:
Changed lines with no test
|
| Function | Complexity | Coverage | CRAP | Location |
|---|---|---|---|---|
(anonymous) |
31 | 96% | 31.1 | packages/api/src/mcp/connect.ts:86 |
resolveMCPConnectionStatus |
29 | 95% | 29.1 | packages/api/src/mcp/readiness.ts:26 |
(anonymous) |
8 | 100% | 8.0 | api/server/routes/mcp.js:1005 |
(anonymous) |
5 | 100% | 5.0 | api/server/routes/mcp.js:960 |
getMCPReinitializeOAuthTimeout |
3 | 100% | 3.0 | packages/api/src/mcp/connect.ts:64 |
getServerConnectionStatus |
2 | 100% | 2.0 | api/server/services/MCP.js:1727 |
getMCPUnavailableStatus |
2 | 100% | 2.0 | packages/api/src/mcp/readiness.ts:108 |
getConnectionState |
1 | 0% | 2.0 | packages/api/src/mcp/connection.ts:3255 |
abort |
1 | 50% | 1.1 | packages/api/src/mcp/connect.ts:149 |
getOAuthFlowId |
1 | 100% | 1.0 | api/server/routes/mcp.js:923 |
4 more functions below the threshold (or cut for size) are in report.md.
CRAP = complexity² × (1 − coverage)³ + complexity
Jobs (2)
| Check | Result |
|---|---|
| Change risk (api) | success |
| Change risk (server) | success |
All data (quality-report artifact) · Run page
The gate opens only when the workflow, source selection, tooling verification, and every report job succeed. A report job fails on a failed test in its workspace's own Jest run, a tool error, a job timeout, or an incomplete mutation report, including a mutation shard that reaches its execution budget. A cancelled workflow keeps the gate closed. Scores are advisory. A change-risk file marked incomplete or unavailable, for example by a failed api/ source-alias suite, does not close the gate.
|
Codex Review: Didn't find any major issues. Breezy! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
deafe9d to
2dc26b5
Compare
2dc26b5 to
1488c72
Compare
1488c72 to
c303962
Compare
|
/quality ignore |
|
@codex review |
Quality reportOutdated: this request is for an earlier PR commit. Gate: open. Quality checks explicitly ignored for this commit.
The gate opens only when the workflow, source selection, tooling verification, and every report job succeed. A report job fails on a failed test in its workspace's own Jest run, a tool error, a job timeout, or an incomplete mutation report, including a mutation shard that reaches its execution budget. A cancelled workflow keeps the gate closed. Scores are advisory. A change-risk file marked incomplete or unavailable, for example by a failed |
|
Codex Review: Didn't find any major issues. 🚀 Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
|
@codex review |
|
/quality ignore |
Quality reportGate: open. Quality checks explicitly ignored for this commit.
The gate opens only when the workflow, source selection, tooling verification, and every report job succeed. A report job fails on a failed test in its workspace's own Jest run, a tool error, a job timeout, or an incomplete mutation report, including a mutation shard that reaches its execution budget. A cancelled workflow keeps the gate closed. Scores are advisory. A change-risk file marked incomplete or unavailable, for example by a failed |
|
Codex Review: Didn't find any major issues. What shall we delve into next? Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |

Summary
In a multi-replica deployment, Connect can succeed on one replica and the next status request can land on a replica that has never opened the MCP transport. The settings row then returns to Connect, and some tool controls treat the server as unusable.
A successful Connect keeps the existing Reconnect action and tool selection available in the current browser session. The status dot stays neutral when the serving replica has no transport observation. The connection result is acknowledged by the existing toast. A real failure shows the existing Error and leaves Connect available for retry.
How it works
The API distinguishes actual transport observations, durable authorization, and the absence of an observation. The client combines these observations with the current Connect result. The existing status indicators describe known observations. With no transport observation, Settings and the compact palette keep a neutral dot and announce the server name without a status label. The expanded catalog shows the existing MCP Servers category subtitle. Agent Builder leaves out the status strip and keeps any applicable controls. The composer can attach a ready on-demand server, and Agent Builder selects discovered tools after a successful Connect.
The operation result is scoped to the browser session, user, tenant, server configuration, and authorization generation. Attempt ordering and later observations fence out obsolete results. React Query keeps the original server responses. Each API process still owns its transport. The status and operation fields used here come from #18473.
Type of change
Testing
Tested environments and configuration
Chromium with production builds, two LibreChat API processes, shared disposable MongoDB and Redis, a real MCP SDK HTTP fixture, a credential-dependent stdio fixture, and a local OAuth consent provider.
Connect on A and verify the existing success toast. Refresh status from cold B and reload before B opens any transport. Settings retains Reconnect in the current session and offers Connect after reload. The MCP fixture recorded one initialization through those steps. The first tool call on B added one initialization. A second tool call used the same transport after A stopped.
Make the fixture reject a real reconnect. Settings shows Error and Connect, then returns to Connected after a successful retry.
Connect from Agent Builder and route the next status request to cold B. The discovered tools are selected. Save custom variables and initialize the stdio server. Complete OAuth consent and confirm tool discovery and selection. An authorization-only status read from cold B keeps Reconnect and selection without a transport label. Exercise the existing pending and cancel controls.
In the expanded composer catalog, verify the selected card shows its standard subtitle after a cold status read. A failed reconnect still shows Error. Both checks ran in light and dark mode.
Automated tests
Screenshots / recordings
Matched captures from the running application with identical fixtures, permissions, and 1280 × 720 viewports. The images use matching crops where the affected controls are small. The before column uses current dev at
584102d9b1. Expand the groups to inspect light and dark mode.MCP Settings
Hover the connection action after Connect on A and a status read from cold B. Current dev offers Connect again. The revision keeps the existing Reconnect action with a neutral dot.
Fail a real reconnect and hover the available action. Current dev still shows Connected and Reconnect. The revision shows the error dot and the existing Connect action.
Restore the MCP fixture and retry. The revision confirms recovery with the connected dot and Reconnect. The prior capture shows that the same appearance on dev can survive a failed response.
Credential configuration
Open the variables dialog before entering a value. The original Disconnected badge, field, and actions are shown.
Save a value and initialize on A. The dialog shows Set, Active, and Reinitialize.
Keep the dialog open and read status from cold B. The revision keeps Reinitialize without showing an Active badge. Current dev shows Disconnected and Initialize.
Composer tool palette
Open Attach and tools after ordinary Connect and a cold-replica status read. The selected server remains in the composer, and the existing palette rows and dots are visible.
Select an on-demand server with its required variables already set. Current dev opens the variables dialog again. The revision attaches the server and keeps Configure available.
Open Show all MCP Servers after a successful Connect on A and a status read from cold B. Both cards are selected, as shown by the green outline and checkmark. The revision shows the standard MCP Servers subtitle.
Open the expanded catalog after a failed Reconnect on the replica that attempted it. The card shows the existing Error status.
Agent Builder
Inspect the already available server after Connect elsewhere in the same session. Current dev still offers the full-width Connect action. The revision keeps the tool controls and omits the status strip.
Connect from the server detail itself and read status from cold B. Current dev leaves the discovered tool unchecked. The revision checks the tool and bulk selector, and the library card shows the existing selection check.
Inspect a previously initialized server with saved variables after a status read on cold B. The revision keeps the existing Configure key button and leaves out the unobserved status.
Pending OAuth
Connect to a server that requires OAuth. The existing prompt shows the link, copy and QR controls, and Continue with OAuth.
Dismiss the prompt while authorization is pending, then hover the settings action. The existing Cancel control remains available.
Accessibility and behavior
Risk / compatibility
The client uses additive status metadata. Older API responses follow conservative handling. Operation results are session-local and do not change persisted data. A fresh browser load at a cold replica shows the server name and existing Connect action until the browser receives a transport observation or starts a connection.
The cold status request and reload produced zero extra MCP initializations in the controlled browser scenario. The revised presentation adds no periodic network requests. Reconciliation compares configuration and authorization generations locally. Large server collections and production Connect latency were not benchmarked.
Checklist