Skip to content

Add support for MCP dynamic tool update by notifications/tools/list_changed - #14375

Merged
Adib234 merged 7 commits into
mainfrom
adibakm/support-dynamic-tool-update
Dec 4, 2025
Merged

Adib234 merged 7 commits into
mainfrom
adibakm/support-dynamic-tool-update

Conversation

@Adib234

@Adib234 Adib234 commented Dec 2, 2025

Copy link
Copy Markdown
Contributor

Summary

Support for MCP server dynamic tool updates via the notifications/tools/list_changed notification mechanism.

Details

This PR uses the event handler for notifications in the model-context-protocol package to update the tool registry if an MCP server has a new tool. We don't need a restart to include new tools from an MCP server, they can happen during a user's session.

Related Issues

Related to #13850

How to Validate

Setup a MCP server that initially has 1 tool, and then after 5 seconds it has 2 tools

Code for script -> https://paste.googleplex.com/6170557420797952

What it looks like in the CLI (initially there was 1 tool for test-server, but after an update there's 2)

image

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

@Adib234 Adib234 self-assigned this Dec 2, 2025
@Adib234
Adib234 requested a review from a team as a code owner December 2, 2025 16:36
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @Adib234, 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 significantly enhances the Model Context Protocol (MCP) integration by enabling dynamic tool updates. It allows the CLI to automatically detect and incorporate new tools provided by an MCP server in real-time, eliminating the need for manual restarts and ensuring that users always have access to the latest tool definitions during their session. This improves the responsiveness and usability of the tool ecosystem.

Highlights

  • Dynamic Tool Updates: Introduced support for dynamic tool updates from Model Context Protocol (MCP) servers, allowing new tools to be registered without requiring a restart of the CLI.
  • Notification Handler: Implemented a notification handler for notifications/tools/list_changed within the McpClient to listen for and react to tool changes from connected MCP servers.
  • Tool Refresh Mechanism: Added a refreshTools method to McpClient which purges existing tools for a server, re-discovers new tools, registers them, and updates the Gemini context.
  • McpClient Constructor Update: The McpClient constructor now accepts the Config object and an optional onToolsUpdated callback, enabling external components (like McpClientManager) to be notified when tools are refreshed.
  • Comprehensive Testing: New unit tests were added to cover various scenarios for dynamic tool updates, including capability checks, successful updates, and error handling during the refresh process.
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. ↩

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

Copy link
Copy Markdown
Contributor

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 adds support for dynamic tool updates from MCP servers, which is a great feature. The implementation correctly uses the tools/list_changed notification to trigger a refresh of the tool registry. The changes are well-tested. I've found one potential race condition in the tool refresh logic that could lead to a stale state if multiple notifications are processed concurrently. I've suggested a fix to serialize the refresh operations.

Comment thread packages/core/src/tools/mcp-client.ts Resolved
@github-actions

github-actions Bot commented Dec 2, 2025 •

Copy link
Copy Markdown

Size Change: +3.63 kB (+0.02%)

Total Size: 21.5 MB

Filename Size Change
./bundle/gemini.js 21.5 MB +3.63 kB (+0.02%)
ℹ️ View Unchanged
Filename Size
./bundle/sandbox-macos-permissive-closed.sb 1.03 kB
./bundle/sandbox-macos-permissive-open.sb 890 B
./bundle/sandbox-macos-permissive-proxied.sb 1.31 kB
./bundle/sandbox-macos-restrictive-closed.sb 3.29 kB
./bundle/sandbox-macos-restrictive-open.sb 3.36 kB
./bundle/sandbox-macos-restrictive-proxied.sb 3.56 kB

compressed-size-action

@jackwotherspoon jackwotherspoon left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Does this PR add support for MCP notifications or just a single type of notification?

@Adib234

Adib234 commented Dec 4, 2025

Copy link
Copy Markdown
Contributor Author

Does this PR add support for MCP notifications or just a single type of notification?

Single type of notification. Only for tools update from an MCP server.

Comment thread packages/core/src/tools/mcp-client.ts Resolved
Comment thread packages/core/src/tools/mcp-client.ts Resolved
Comment thread packages/core/src/tools/mcp-client.ts Resolved
Comment thread packages/core/src/tools/mcp-client.ts Resolved
Add 2 tests to test timeouts being triggered in discoverTools and onToolsUpdated call
Remove some doc
Add abort signal for timeouts
@Adib234
Adib234 added this pull request to the merge queue Dec 4, 2025
Merged via the queue into main with commit 5f60281 Dec 4, 2025
@Adib234
Adib234 deleted the adibakm/support-dynamic-tool-update branch December 4, 2025 21:18
MrLesk added a commit to MrLesk/gemini-cli that referenced this pull request Dec 6, 2025
Following PR google-gemini#14375 I tried to make the Resource refreshing consistent with the tools logic.
I added coalescence/debounce feature to prevent overwhelming the client and the server in case of frequent updates
@MrLesk MrLesk mentioned this pull request Dec 6, 2025
5 of 18 tasks
MrLesk added a commit to MrLesk/gemini-cli that referenced this pull request Dec 8, 2025
Following PR google-gemini#14375 I tried to make the Resource refreshing consistent with the tools logic.
I added coalescence/debounce feature to prevent overwhelming the client and the server in case of frequent updates
@sripasg sripasg added the size/l A large sized PR label Jun 2, 2026
software-0ficial pushed a commit to software-0ficial/gemini-cli that referenced this pull request Jul 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/l A large sized PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add support for MCP dynamic tool update by notifications/tools/list_changed

4 participants