-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Feature/add enable disable methods tools #728
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Feature/add enable disable methods tools #728
Conversation
…ble-methods-tools
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe it needs a spec change as well. Do we already have a PR for it?
I've added it to the README in this commit: |
Thank you for this contribution. While dynamic tool enabling/disabling could be useful for testing, we're closing this PR because:
For testing, we recommend using different server configurations or mocking at the application level instead. |
I understand concerns about API complexity, but I'd like to offer a real-world perspective. The TypeScript MCP SDK already implements this pattern via the RegisteredTool type with methods like Their docs show a practical example for progressive auth: const putMessageTool = server.tool("putMessage", /* ... */);
putMessageTool.disable(); // User must authenticate first
const upgradeAuthTool = server.tool("upgradeAuth", /* ... */, async ({ permission }) => {
const { ok, previous } = await upgradeAuthAndStoreToken(permission);
if (previous === "read") putMessageTool.enable();
if (permission === "admin") upgradeAuthTool.remove();
}); This approach cleanly supports stateful logic, e.g., enabling tools based on auth state or feature flags, without complex conditions or restarts. It’s not just for testing; it solves real production needs where server behavior must adapt dynamically. |
Please can you expand on this? The Typescript Feature mentioned is for Dynamic Servers, is the intention here to support it in Python SDK? |
Yes, this feature implements the same Dynamic Servers capability from the TypeScript sdk.
Implementation:
|
Added the ability to dynamically enable and disable tools at runtime with client notifications.
Motivation and Context
This change allows developers to temporarily restrict access to specific tools without removing them from the tool manager. This is useful for implementing feature flags, managing resource availability, or controlling access to functionality based on runtime conditions.
How Has This Been Tested?
Breaking Changes
The tool list now includes the enabled state of each tool. However, all tools are initialized with enabled=True by default, maintaining backward compatibility with existing code.
Types of changes
Checklist