refactor: extract ManagedMcpClient and handle session expiry (#232)#338
Merged
DearVa merged 3 commits intoDearVa:0.7.0from Apr 11, 2026
Merged
refactor: extract ManagedMcpClient and handle session expiry (#232)#338DearVa merged 3 commits intoDearVa:0.7.0from
DearVa merged 3 commits intoDearVa:0.7.0from
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR refactors MCP client startup into a dedicated ManagedMcpClient and adds logic to detect MCP session expiry (e.g., some servers returning 401/4xx) to trigger reconnection and retry, addressing issue #232.
Changes:
- Extract MCP client lifecycle/transport/watchdog logic from
ChatPluginManagerintoManagedMcpClient. - Introduce an HTTP handler (
McpSessionExpiryHandler) to rewrite “session expired” 4xx responses into 404 so the MCP SDK’s session-expiry path is triggered. - Register a dedicated named
HttpClient(JsonRpcClient) for MCP HTTP transport with required handlers.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| src/Everywhere.Core/Initialization/NetworkInitializer.cs | Removes named JSON-RPC client setup from network config; exposes ContentLengthBufferingHandler for reuse. |
| src/Everywhere.Core/Extensions/ServiceExtension.cs | Wires MCP HTTP client/handlers registration into chat service setup via AddManagedMcp(). |
| src/Everywhere.Core/Chat/Plugins/McpExtensions/McpSessionExpiryHandler.cs | Adds handler to detect session-expiry response bodies and rewrite status to 404. |
| src/Everywhere.Core/Chat/Plugins/McpExtensions/McpServiceExtension.cs | Registers named MCP HttpClient pipeline (proxy + expiry + content-length buffering). |
| src/Everywhere.Core/Chat/Plugins/McpExtensions/ManagedMcpClientTool.cs | Wraps MCP tools to auto-reconnect and retry once on session expiry errors. |
| src/Everywhere.Core/Chat/Plugins/McpExtensions/ManagedMcpClient.cs | New managed client handling transports, reconnect, tool listing/wrapping, watchdog registration. |
| src/Everywhere.Core/Chat/Plugins/ChatPluginManager.cs | Uses ManagedMcpClient instead of directly creating/owning McpClient. |
| src/Everywhere.Core/Chat/Plugins/ChatFunction.cs | Updates MCP function wrapper to accept ManagedMcpClientTool. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Type of Change
Checklist
Fixed Issues
Fixes #232