fix(core): prevent MCP tool wiping on background discovery failures#25937
fix(core): prevent MCP tool wiping on background discovery failures#25937spencer426 wants to merge 1 commit into
Conversation
Summary of ChangesHello, 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 issue where MCP tools were being inadvertently removed from the registry due to background refresh failures. By ensuring that discovery errors are properly propagated rather than masked as an empty tool list, the system now maintains existing tool registrations during periods of network instability or timeouts. Highlights
Using Gemini Code AssistThe 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
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 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. Footnotes
|
|
Hi @spencer426, thank you so much for your contribution to Gemini CLI! We really appreciate the time and effort you've put into this. We're making some updates to our contribution process to improve how we track and review changes. Please take a moment to review our recent discussion post: Improving Our Contribution Process & Introducing New Guidelines. Key Update: Starting January 26, 2026, the Gemini CLI project will require all pull requests to be associated with an existing issue. Any pull requests not linked to an issue by that date will be automatically closed. Thank you for your understanding and for being a part of our community! |
🛑 Action Required: Evaluation ApprovalSteering changes have been detected in this PR. To prevent regressions, a maintainer must approve the evaluation run before this PR can be merged. Maintainers:
Once approved, the evaluation results will be posted here automatically. |
There was a problem hiding this comment.
Code Review
This pull request updates the discoverTools function in packages/core/src/tools/mcp-client.ts to explicitly re-throw errors encountered during the discovery process. Correspondingly, the test suite in packages/core/src/tools/mcp-client.test.ts has been updated to verify that tools are no longer removed from the registry when a discovery failure occurs. I have no feedback to provide as there were no review comments.
|
Size Change: +17 B (0%) Total Size: 33.7 MB
ℹ️ View Unchanged
|
|
Hi there! Thank you for your interest in contributing to Gemini CLI. To ensure we maintain high code quality and focus on our prioritized roadmap, we only guarantee review and consideration of pull requests for issues that are explicitly labeled as 'help wanted'. This PR will be closed in 7 days if it remains without that designation. We encourage you to find and contribute to existing 'help wanted' issues in our backlog! Thank you for your understanding. |
Summary
This PR fixes an issue where discovered tools from an MCP server are erroneously wiped from the
ToolRegistryif a background refresh operation fails due to network latency or an idle timeout.Details
When an MCP server's background connection is dropped (e.g. idle timeout during a long API request), an attempted background
discoverToolscould fail with a generic network error. Previously,discoverToolscaught this error and returned an empty array[]instead of throwing.refreshToolsinterpreted this empty array as 0 tools on the server and aggressively removed the server's tools from the CLI's registry usingremoveMcpToolsByServer().This PR updates
discoverToolsto correctly re-throw the error when it is not aMethodNotFounderror. This preserves the existing tools in theToolRegistryand avoids the confusing "tool could no longer be found" error when the session later tries to use the registered tool. A regression test case was also added to ensure this behavior is enforced.Related Issues
Fixes https://github.com/google-gemini/maintainers-gemini-cli/issues/1635
How to Validate
packages/core/src/tools/mcp-client.test.tsfor handling graceful tool refresh errors.npm run test -w @google/gemini-cli-core -- src/tools/mcp-client.test.tsnpm run lintandnpm run typecheckPre-Merge Checklist