Skip to content

refactor: extract ManagedMcpClient and handle session expiry (#232)#338

Merged
DearVa merged 3 commits intoDearVa:0.7.0from
TheNotoBarth:feature/mcp-session-expiry
Apr 11, 2026
Merged

refactor: extract ManagedMcpClient and handle session expiry (#232)#338
DearVa merged 3 commits intoDearVa:0.7.0from
TheNotoBarth:feature/mcp-session-expiry

Conversation

@TheNotoBarth
Copy link
Copy Markdown
Collaborator

Type of Change

  • 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)
  • Refactoring (no functional changes, no api changes)
  • Documentation update
  • CI/CD or Build changes

Checklist

  • My code follows the code style of this project
  • I have performed a self-review of my own code
  • I have added XML documentation to any related classes

Fixed Issues

Fixes #232

Copilot AI review requested due to automatic review settings April 11, 2026 06:21
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 ChatPluginManager into ManagedMcpClient.
  • 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.

Comment thread src/Everywhere.Core/Chat/Plugins/Mcp/ManagedMcpClient.cs
Comment thread src/Everywhere.Core/Chat/Plugins/McpExtensions/ManagedMcpClient.cs Outdated
Comment thread src/Everywhere.Core/Chat/Plugins/McpExtensions/ManagedMcpClient.cs Outdated
Comment thread src/Everywhere.Core/Chat/Plugins/McpExtensions/McpSessionExpiryHandler.cs Outdated
Copy link
Copy Markdown
Owner

@DearVa DearVa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

copilot说的挺多都没问题,我来修改一下

@DearVa DearVa merged commit 631dc27 into DearVa:0.7.0 Apr 11, 2026
1 check passed
@github-actions github-actions bot locked and limited conversation to collaborators Apr 11, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants