You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Add support for MCP dynamic tool update by notifications/tools/list_changed #13850
Support for MCP server dynamic tool updates via the notifications/tools/list_changed notification mechanism.
When an MCP server sends a notifications/tools/list_changed notification (as defined in the MCP specification), the Gemini CLI should automatically:
Remove the old tool list from the affected MCP server
Re-query the server's tools using listTools()
Register the updated tools in the tool registry
Make the new tools available to the model without requiring a CLI restart
Why is this needed?
ManySome MCP servers dynamically update their available tools based on runtime conditions (e.g., authentication state changes, resource availability, or configuration updates). Currently, users must restart the Gemini CLI to pick up these changes, which disrupts their workflow.
Supporting the notifications/tools/list_changed notification would:
Enable seamless tool updates without CLI restarts
Improve user experience when working with dynamic MCP servers
Align with the MCP specification's design for tool lifecycle management
Allow MCP servers to add or remove tools in response to runtime changes (such as credential refresh, resource state changes, etc.)
Example use cases:
An MCP server that exposes different tools based on authenticated user permissions
A server that dynamically enables/disables tools based on resource availability
A server that adds new tools after completing initialization tasks
Additional context
he MCP specification defines tools.listChanged as a server capability and notifications/tools/list_changed as the notification method for signaling tool updates. The implementation should:
Only enable this feature for servers that advertise tools.listChanged: true capability
Properly handle the notification callback registered via setNotificationHandler()
I tried running gemini-cli at latest version 0.29.2 and I can see the merged code in pull request #14375 exists in that tag. I am using below code to add a dynamic tool via python
`"""
MCP Server that demonstrates dynamic tool registration with notifications/tools/list_changed.
Flow:
Server starts with one initial tool: "unlock_secret_tool"
When a client calls "unlock_secret_tool", the server dynamically registers a new tool
called "secret_calculator" and sends a notifications/tools/list_changed notification.
The client (e.g., Gemini CLI) picks up the notification and re-fetches the tool list,
making "secret_calculator" available for use.
"""
import asyncio
import logging
from mcp.server.fastmcp import FastMCP, Context
mcp = FastMCP(
name="dynamic-tools-server",
instructions="This server starts with an 'unlock_secret_tool' tool. Call it to unlock a hidden 'secret_calculator' tool dynamically.",
)
Track whether the secret tool has been added
_secret_tool_added = False
def _secret_calculator(a: float, b: float, operation: str) -> str:
"""A secret calculator that was dynamically unlocked!
Performs basic arithmetic operations.
Args:
a: First number
b: Second number
operation: One of 'add', 'subtract', 'multiply', 'divide'
Returns:
The result of the calculation as a string.
"""
if operation == "add":
result = a + b
elif operation == "subtract":
result = a - b
elif operation == "multiply":
result = a * b
elif operation == "divide":
if b == 0:
return "Error: Division by zero!"
result = a / b
else:
return f"Error: Unknown operation '{operation}'. Use add, subtract, multiply, or divide."
return f"🔓 Secret Calculator Result: {a} {operation} {b} = {result}"
@mcp.tool()
async def unlock_secret_tool(ctx: Context) -> str:
"""Unlock a hidden secret tool! Call this to dynamically add a new 'secret_calculator' tool to the server.
Once called, a powerful secret calculator tool will become available.
The client will be notified via notifications/tools/list_changed so it can discover the new tool.
Returns:
A message confirming whether the secret tool was unlocked.
"""
global _secret_tool_added
if _secret_tool_added:
return "🔓 The secret tool is already unlocked! You can use 'secret_calculator' now."
logger.info("🔑 Unlocking the secret calculator tool...")
# Dynamically add the new tool to the server
mcp.add_tool(
fn=_secret_calculator,
name="secret_calculator",
title="Secret Calculator",
description="A secret calculator that was dynamically unlocked! Performs add, subtract, multiply, divide operations on two numbers.",
)
_secret_tool_added = True
logger.info("✅ Secret calculator tool added to the server!")
# Send notifications/tools/list_changed to notify connected clients
# The Context object gives us access to the session to send notifications
try:
session = ctx.session
await session.send_tool_list_changed()
logger.info("📢 Sent notifications/tools/list_changed to client!")
except Exception as e:
logger.warning(f"Could not send tool list changed notification: {e}")
return (
"🔓 Secret tool unlocked! A new tool 'secret_calculator' is now available.\n"
"It supports operations: add, subtract, multiply, divide.\n"
"Example: secret_calculator(a=10, b=5, operation='add')\n"
"The client has been notified about the new tool via notifications/tools/list_changed."
)
@mcp.tool()
async def list_available_info(ctx: Context) -> str:
"""List information about currently available tools and whether the secret tool has been unlocked.
Returns:
Status information about the server and available tools.
"""
global _secret_tool_added
status = "🔓 UNLOCKED" if _secret_tool_added else "🔒 LOCKED"
return (
f"Dynamic Tools Server Status:\n"
f"----------------------------\n"
f"Secret Calculator: {status}\n"
f"\n"
f"Available tools:\n"
f" 1. unlock_secret_tool - Call this to unlock the secret calculator\n"
f" 2. list_available_info - This tool (shows server status)\n"
+ (f" 3. secret_calculator - Performs arithmetic (add/subtract/multiply/divide)\n" if _secret_tool_added else
f" 3. ??? - Call 'unlock_secret_tool' to reveal!\n")
)
if name == "main":
logger.info("Starting Dynamic Tools MCP Server...")
logger.info("Initial tools: unlock_secret_tool, list_available_info")
logger.info("Call 'unlock_secret_tool' to dynamically add 'secret_calculator'")
mcp.run(transport="stdio")
`
in the raw protocol logs I can see these logs: [2026-02-19T12:02:21.339689] SERVER >>> {"jsonrpc":"2.0","id":0,"result":{"protocolVersion":"2025-11-25","capabilities":{"experimental":{},"prompts":{"listChanged":false},"resources":{"subscribe":false,"listChanged":false},"tools":{"listChanged":false}},"serverInfo":{"name":"dynamic-tools-server","version":"1.26.0"},"instructions":"This server starts with an 'unlock_secret_tool' tool. Call it to unlock a hidden 'secret_calculator' tool dynamically."}} [2026-02-19T12:02:21.348501] SERVER >>> {"jsonrpc":"2.0","id":1,"result":{"prompts":[]}} [2026-02-19T12:02:21.355812] SERVER >>> {"jsonrpc":"2.0","id":2,"result":{"tools":[{"name":"unlock_secret_tool","description":"Unlock a hidden secret tool! Call this to dynamically add a new 'secret_calculator' tool to the server.\n \n Once called, a powerful secret calculator tool will become available.\n The client will be notified via notifications/tools/list_changed so it can discover the new tool.\n \n Returns:\n A message confirming whether the secret tool was unlocked.\n ","inputSchema":{"properties":{},"title":"unlock_secret_toolArguments","type":"object"},"outputSchema":{"properties":{"result":{"title":"Result","type":"string"}},"required":["result"],"title":"unlock_secret_toolOutput","type":"object"}},{"name":"list_available_info","description":"List information about currently available tools and whether the secret tool has been unlocked.\n \n Returns:\n Status information about the server and available tools.\n ","inputSchema":{"properties":{},"title":"list_available_infoArguments","type":"object"},"outputSchema":{"properties":{"result":{"title":"Result","type":"string"}},"required":["result"],"title":"list_available_infoOutput","type":"object"}}]}} [2026-02-19T12:02:21.362494] SERVER >>> {"jsonrpc":"2.0","id":3,"result":{"resources":[]}} [2026-02-19T12:06:17.024684] SERVER >>> {"method":"notifications/tools/list_changed","jsonrpc":"2.0"} [2026-02-19T12:06:17.025062] SERVER >>> {"jsonrpc":"2.0","id":4,"result":{"content":[{"type":"text","text":"🔓 Secret tool unlocked! A new tool 'secret_calculator' is now available.\nIt supports operations: add, subtract, multiply, divide.\nExample: secret_calculator(a=10, b=5, operation='add')\nThe client has been notified about the new tool via notifications/tools/list_changed."}],"structuredContent":{"result":"🔓 Secret tool unlocked! A new tool 'secret_calculator' is now available.\nIt supports operations: add, subtract, multiply, divide.\nExample: secret_calculator(a=10, b=5, operation='add')\nThe client has been notified about the new tool via notifications/tools/list_changed."},"isError":false}} [2026-02-19T12:06:24.501775] SERVER >>> {"jsonrpc":"2.0","id":5,"result":{"content":[{"type":"text","text":"Dynamic Tools Server Status:\n----------------------------\nSecret Calculator: 🔓 UNLOCKED\n\nAvailable tools:\n 1. unlock_secret_tool - Call this to unlock the secret calculator\n 2. list_available_info - This tool (shows server status)\n 3. secret_calculator - Performs arithmetic (add/subtract/multiply/divide)\n"}],"structuredContent":{"result":"Dynamic Tools Server Status:\n----------------------------\nSecret Calculator: 🔓 UNLOCKED\n\nAvailable tools:\n 1. unlock_secret_tool - Call this to unlock the secret calculator\n 2. list_available_info - This tool (shows server status)\n 3. secret_calculator - Performs arithmetic (add/subtract/multiply/divide)\n"},"isError":false}}
But still gemini-cli is not loading the updated tool: I see this on CLI:
Call unlock_secret_tool
▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
╭──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ ✓ unlock_secret_tool (dynamic-tools MCP Server) {} │
│ │
│ 🔓 Secret tool unlocked! A new tool 'secret_calculator' is now available. │
│ It supports operations: add, subtract, multiply, divide. │
│ Example: secret_calculator(a=10, b=5, operation='add') │
│ The client has been notified about the new tool via notifications/tools/list_changed. │
╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
✦ I have unlocked the secret_calculator tool, but its definition is not yet available to me. I will call list_available_info to refresh my tool list and see if the new tool becomes
available.
╭──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ ✓ list_available_info (dynamic-tools MCP Server) {} │
│ │
│ Dynamic Tools Server Status: │
│ --- │
│ Secret Calculator: 🔓 UNLOCKED │
│ │
│ Available tools: │
│ 1. unlock_secret_tool - Call this to unlock the secret calculator │
│ 2. list_available_info - This tool (shows server status) │
│ 3. secret_calculator - Performs arithmetic (add/subtract/multiply/divide) │
│ │
╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
ℹ ⚠️ Response stopped due to unexpected tool call.
╭──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ x secret_calculator {"a":5,"operation":"add","b":7} │
│ │
│ Tool "secret_calculator" not found. Did you mean one of: "list_directory", "grep_search", "replace"? │
╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
✦ I am unable to call the secret_calculator tool, even though it appears to be unlocked. I will try to refresh the list of available tools again to see if that resolves the issue.
I am not sure whether this feature is working or if I am wrong somewhere.
Activity
Adib234 commentedon Nov 29, 2025
hi there! I can try taking this on
trapezoid commentedon Dec 2, 2025
Thank you!
thecuriouscoding commentedon Feb 19, 2026
I tried running gemini-cli at latest version 0.29.2 and I can see the merged code in pull request #14375 exists in that tag. I am using below code to add a dynamic tool via python
`"""
MCP Server that demonstrates dynamic tool registration with notifications/tools/list_changed.
Flow:
called "secret_calculator" and sends a
notifications/tools/list_changednotification.making "secret_calculator" available for use.
"""
import asyncio
import logging
from mcp.server.fastmcp import FastMCP, Context
Configure logging
logging.basicConfig(level=logging.INFO, format="%(asctime)s - %(name)s - %(levelname)s - %(message)s")
logger = logging.getLogger("dynamic-tools-server")
Create the MCP server
mcp = FastMCP(
name="dynamic-tools-server",
instructions="This server starts with an 'unlock_secret_tool' tool. Call it to unlock a hidden 'secret_calculator' tool dynamically.",
)
Track whether the secret tool has been added
_secret_tool_added = False
def _secret_calculator(a: float, b: float, operation: str) -> str:
"""A secret calculator that was dynamically unlocked!
@mcp.tool()
async def unlock_secret_tool(ctx: Context) -> str:
"""Unlock a hidden secret tool! Call this to dynamically add a new 'secret_calculator' tool to the server.
@mcp.tool()
async def list_available_info(ctx: Context) -> str:
"""List information about currently available tools and whether the secret tool has been unlocked.
if name == "main":
logger.info("Starting Dynamic Tools MCP Server...")
logger.info("Initial tools: unlock_secret_tool, list_available_info")
logger.info("Call 'unlock_secret_tool' to dynamically add 'secret_calculator'")
mcp.run(transport="stdio")
`
in the raw protocol logs I can see these logs:
[2026-02-19T12:02:21.339689] SERVER >>> {"jsonrpc":"2.0","id":0,"result":{"protocolVersion":"2025-11-25","capabilities":{"experimental":{},"prompts":{"listChanged":false},"resources":{"subscribe":false,"listChanged":false},"tools":{"listChanged":false}},"serverInfo":{"name":"dynamic-tools-server","version":"1.26.0"},"instructions":"This server starts with an 'unlock_secret_tool' tool. Call it to unlock a hidden 'secret_calculator' tool dynamically."}} [2026-02-19T12:02:21.348501] SERVER >>> {"jsonrpc":"2.0","id":1,"result":{"prompts":[]}} [2026-02-19T12:02:21.355812] SERVER >>> {"jsonrpc":"2.0","id":2,"result":{"tools":[{"name":"unlock_secret_tool","description":"Unlock a hidden secret tool! Call this to dynamically add a new 'secret_calculator' tool to the server.\n \n Once called, a powerful secret calculator tool will become available.\n The client will be notified via notifications/tools/list_changed so it can discover the new tool.\n \n Returns:\n A message confirming whether the secret tool was unlocked.\n ","inputSchema":{"properties":{},"title":"unlock_secret_toolArguments","type":"object"},"outputSchema":{"properties":{"result":{"title":"Result","type":"string"}},"required":["result"],"title":"unlock_secret_toolOutput","type":"object"}},{"name":"list_available_info","description":"List information about currently available tools and whether the secret tool has been unlocked.\n \n Returns:\n Status information about the server and available tools.\n ","inputSchema":{"properties":{},"title":"list_available_infoArguments","type":"object"},"outputSchema":{"properties":{"result":{"title":"Result","type":"string"}},"required":["result"],"title":"list_available_infoOutput","type":"object"}}]}} [2026-02-19T12:02:21.362494] SERVER >>> {"jsonrpc":"2.0","id":3,"result":{"resources":[]}} [2026-02-19T12:06:17.024684] SERVER >>> {"method":"notifications/tools/list_changed","jsonrpc":"2.0"} [2026-02-19T12:06:17.025062] SERVER >>> {"jsonrpc":"2.0","id":4,"result":{"content":[{"type":"text","text":"🔓 Secret tool unlocked! A new tool 'secret_calculator' is now available.\nIt supports operations: add, subtract, multiply, divide.\nExample: secret_calculator(a=10, b=5, operation='add')\nThe client has been notified about the new tool via notifications/tools/list_changed."}],"structuredContent":{"result":"🔓 Secret tool unlocked! A new tool 'secret_calculator' is now available.\nIt supports operations: add, subtract, multiply, divide.\nExample: secret_calculator(a=10, b=5, operation='add')\nThe client has been notified about the new tool via notifications/tools/list_changed."},"isError":false}} [2026-02-19T12:06:24.501775] SERVER >>> {"jsonrpc":"2.0","id":5,"result":{"content":[{"type":"text","text":"Dynamic Tools Server Status:\n----------------------------\nSecret Calculator: 🔓 UNLOCKED\n\nAvailable tools:\n 1. unlock_secret_tool - Call this to unlock the secret calculator\n 2. list_available_info - This tool (shows server status)\n 3. secret_calculator - Performs arithmetic (add/subtract/multiply/divide)\n"}],"structuredContent":{"result":"Dynamic Tools Server Status:\n----------------------------\nSecret Calculator: 🔓 UNLOCKED\n\nAvailable tools:\n 1. unlock_secret_tool - Call this to unlock the secret calculator\n 2. list_available_info - This tool (shows server status)\n 3. secret_calculator - Performs arithmetic (add/subtract/multiply/divide)\n"},"isError":false}}But still gemini-cli is not loading the updated tool: I see this on CLI:
╭──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ ✓ list_available_info (dynamic-tools MCP Server) {} │
│ │
│ Dynamic Tools Server Status: │
│ --- │
│ Secret Calculator: 🔓 UNLOCKED │
│ │
│ Available tools: │
│ 1. unlock_secret_tool - Call this to unlock the secret calculator │
│ 2. list_available_info - This tool (shows server status) │
│ 3. secret_calculator - Performs arithmetic (add/subtract/multiply/divide) │
│ │
╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
ℹ⚠️ Response stopped due to unexpected tool call.
╭──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ x secret_calculator {"a":5,"operation":"add","b":7} │
│ │
│ Tool "secret_calculator" not found. Did you mean one of: "list_directory", "grep_search", "replace"? │
╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
✦ I am unable to call the secret_calculator tool, even though it appears to be unlocked. I will try to refresh the list of available tools again to see if that resolves the issue.
I am not sure whether this feature is working or if I am wrong somewhere.