Skip to content

Comments

fix(core): create new McpClient on restart to apply updated config#20126

Merged
scidomino merged 1 commit intogoogle-gemini:mainfrom
h30s:fix/mcp-client-config-reuse
Feb 24, 2026
Merged

fix(core): create new McpClient on restart to apply updated config#20126
scidomino merged 1 commit intogoogle-gemini:mainfrom
h30s:fix/mcp-client-config-reuse

Conversation

@h30s
Copy link
Contributor

@h30s h30s commented Feb 24, 2026

Summary

Fix McpClient instance reuse during server restart/reload that silently ignores updated configurations. Always create a new McpClient with the current config instead of reusing the stale instance.

Details

In maybeDiscoverMcpServer(), the existing McpClient was disconnected but then reused via existing ?? new McpClient(...). Since McpClient stores its serverConfig as private readonly, any updated configuration (changed command, args, env, timeout) was silently ignored. The fix disconnects and removes the old client, then always constructs a new McpClient with the updated config.

Related Issues

Fixes #19792

How to Validate

  1. Run the new test directly:
    npm test -w @google/gemini-cli-core -- src/tools/mcp-client-manager.test.ts
  2. Verify the new test should create a new McpClient with updated config on restart passes.
  3. Verify all 20 existing tests in the file continue to pass.
  4. Run full CI checks:
    npm run typecheck
    npm run lint
    npm run test

Pre-Merge Checklist

  • Updated relevant documentation and README (if needed)
  • Added/updated tests (if needed)
  • Noted breaking changes (if any)
  • Validated on required platforms/methods:
    • MacOS
      • npm run
      • npx
      • Docker
      • Podman
      • Seatbelt
    • Windows
      • npm run
      • npx
      • Docker
    • Linux
      • npm run
      • npx
      • Docker

@h30s h30s requested a review from a team as a code owner February 24, 2026 05:53
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @h30s, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses a critical bug where configuration changes for McpClient were not being applied after a server restart or reload due to the reuse of stale client instances. The fix ensures that the system always creates a fresh McpClient with the latest configuration, thereby guaranteeing that all updates are correctly recognized and utilized. This improves the reliability and responsiveness of the application to configuration changes.

Highlights

  • Configuration Reload Fix: Resolved an issue where McpClient instances were being reused during server restarts or reloads, causing updated configurations to be silently ignored. The system now ensures a new McpClient is created with the current configuration.
  • Client Management Logic: Modified the McpClientManager to explicitly disconnect and remove old McpClient instances from its internal map before constructing a new one, guaranteeing that all configuration changes are applied.
  • New Test Case: Added a dedicated test case to verify that McpClient correctly re-initializes with updated configurations upon a simulated restart.
Changelog
  • packages/core/src/tools/mcp-client-manager.test.ts
    • Added a new test case to validate that a new McpClient is created with updated configuration on restart.
  • packages/core/src/tools/mcp-client-manager.ts
    • Modified maybeDiscoverMcpServer to explicitly delete the existing McpClient from the clients map before creating a new one.
    • Changed the client instantiation logic to always create a new McpClient instance with the current configuration, instead of potentially reusing an old one.
    • Ensured that the newly created client is always set in the clients map and that the mcp-client-update event is emitted.
Activity
  • No human activity has occurred on this pull request yet.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request correctly addresses a bug where updated configurations for MCP servers were ignored on restart or reload. The fix ensures that a new McpClient instance is always created with the latest configuration, instead of reusing a stale one. The accompanying test effectively validates this change. I've added one suggestion to improve the robustness of the client disconnection logic to prevent potential issues with stale clients if the disconnection process fails.

@h30s h30s force-pushed the fix/mcp-client-config-reuse branch from 031bd9d to 6aa647e Compare February 24, 2026 06:01
@h30s
Copy link
Contributor Author

h30s commented Feb 24, 2026

@scidomino Please take a look whenever you have time. The PR is ready from my side 😊

@gemini-cli gemini-cli bot added area/core Issues related to User Interface, OS Support, Core Functionality help wanted We will accept PRs from all issues marked as "help wanted". Thanks for your support! labels Feb 24, 2026
@scidomino scidomino enabled auto-merge February 24, 2026 17:45
@scidomino scidomino added this pull request to the merge queue Feb 24, 2026
Merged via the queue into google-gemini:main with commit e4204d5 Feb 24, 2026
26 of 27 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/core Issues related to User Interface, OS Support, Core Functionality help wanted We will accept PRs from all issues marked as "help wanted". Thanks for your support!

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[core] Local MCP Server configurations are silently ignored during restart/reload due to McpClient instance reuse

2 participants