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
When the ServerCommandsChanged event is triggered, I attempt to:
Remove existing tools using mcpServer.Services.RemoveAll(typeof(McpServerTool))
Re-add tools using mcpServer.WithTools(MCPHelper.GetMcpTools())
However, this approach doesn't seem to work correctly - the tools are not being properly refreshed.
I tried using WithListToolsHandler, which works, but I would also need to implement WithCallToolHandler manually, which is less convenient than using WithTools.
Expected Behavior
I would like to be able to dynamically at runtime:
Remove existing MCP tools
Add new or updated MCP tools
Have these changes take effect immediately without requiring a service restart
Questions
Is Services.RemoveAll(typeof(McpServerTool)) the correct way to remove tools?
Does calling WithTools() at runtime properly re-register the tools?
Are there other recommended approaches for implementing dynamic MCP tools refresh?
Environment Information
ModelContextProtocol version: 0.3.0-preview.2
.NET version: net8.0
Operating System: Windows
Additional Information
This functionality is important for my application as tools may need to be dynamically updated based on changes to server commands. If the current approach is incorrect, could you provide a proper implementation solution?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
Pre-submission Checklist
Question Category
Your Question
Problem Description
I'm encountering an issue when using ModelContextProtocol where I need to dynamically refresh MCP Server tools at runtime.
Current Implementation
Currently, my code looks like this:
Issue
When the
ServerCommandsChanged
event is triggered, I attempt to:mcpServer.Services.RemoveAll(typeof(McpServerTool))
mcpServer.WithTools(MCPHelper.GetMcpTools())
However, this approach doesn't seem to work correctly - the tools are not being properly refreshed.
I tried using
WithListToolsHandler
, which works, but I would also need to implementWithCallToolHandler
manually, which is less convenient than usingWithTools
.Expected Behavior
I would like to be able to dynamically at runtime:
Questions
Services.RemoveAll(typeof(McpServerTool))
the correct way to remove tools?WithTools()
at runtime properly re-register the tools?Environment Information
Additional Information
This functionality is important for my application as tools may need to be dynamically updated based on changes to server commands. If the current approach is incorrect, could you provide a proper implementation solution?
Thank you for your help!
Beta Was this translation helpful? Give feedback.
All reactions