Skip to content

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

Open
wants to merge 10 commits into
base: main
Choose a base branch
from

Conversation

davila7
Copy link

@davila7 davila7 commented May 15, 2025

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?

  • Added unit tests for enabling/disabling tools
  • Verified that disabled tools don't appear in tool listings and cannot be called
  • Tested re-enabling previously disabled tools

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

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update

Checklist

  • I have read the MCP Documentation
  • My code follows the repository's style guidelines
  • New and existing tests pass locally
  • I have added appropriate error handling
  • I have added or updated documentation as needed

Copy link

@bzsurbhi bzsurbhi left a 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?

@davila7
Copy link
Author

davila7 commented May 20, 2025

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:
fd71115#diff-b335630551682c19a781afebcf4d07bf978fb1f8ac04c6bf87428ed5106870f5R253

@davila7 davila7 requested a review from bzsurbhi May 23, 2025 14:26
@ihrpr
Copy link
Contributor

ihrpr commented May 23, 2025

Thank you for this contribution. While dynamic tool enabling/disabling could be useful for testing, we're closing this PR because:

  1. It creates API confusion (disabled vs non-existent tools)
  2. Requires MCP protocol changes to be added to SDK
  3. Adds maintenance burden without clear production benefits

For testing, we recommend using different server configurations or mocking at the application level instead.

@ihrpr ihrpr closed this May 23, 2025
@davila7
Copy link
Author

davila7 commented May 23, 2025

@ihrpr

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 enable(), disable(), and update().

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.

@ihrpr ihrpr reopened this May 23, 2025
@ihrpr ihrpr added this to the r-06-25 milestone May 23, 2025
@ihrpr
Copy link
Contributor

ihrpr commented May 23, 2025

Added the ability to dynamically enable and disable tools at runtime with client notifications.

Please can you expand on this?

The Typescript Feature mentioned is for Dynamic Servers, is the intention here to support it in Python SDK?

@davila7
Copy link
Author

davila7 commented May 23, 2025

Added the ability to dynamically enable and disable tools at runtime with client notifications.

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.

  • enable/disable tools without server restart
  • tools appear/disappear based on context (auth, resources, etc.)
  • automatic updates when tool lists change

Implementation:

  • Added enabled: bool field to tools
  • enable()/disable() methods with client notifications
  • Filtered tool listing (only enabled tools shown)
  • Runtime validation preventing disabled tool execution

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants