Skip to content

Conditional Enablement of MCP Server Tools #30

@eddyv

Description

@eddyv

The number of tools available in this server is growing. Some tools may also only be available when certain environment variables are present. There are also situations where tools are dependent on Confluent Cloud REST APIs and are thus not compatible with CP-based deployments.

Summary

Implement conditional enabling of tools in the MCP server based on specific conditions.

Problem Statement

Currently, the MCP server lacks the functionality to enable or disable tools dynamically based on certain conditions. This can lead to inefficiencies and unnecessary resource usage, as tools are always active regardless of whether they are needed. For example, some tools only work when connecting to Confluent Cloud and will not work when connecting to Confluent Platform.

Some MCP Clients (like cursor at the time of writing https://docs.cursor.com/context/model-context-protocol#limitations) have a limit on the number of tools sent to the client.

Proposed Solution

Introduce functionality that allows tools to be conditionally enabled or disabled based on the following conditions:

  1. Required Environment Variables: Each tool will declare which environment variables it requires. If any are missing, the tool will not be enabled.
  2. (Optional/Future) Explicit Configuration: Allow users to override tool enabling/disabling via environment variables or config files if needed.

Benefits

  • Improved resource management and efficiency.
  • Tailored user experience by enabling only relevant tools.
  • Better control over the MCP server's behavior.
  • Reduces the risk of exposing tools that are not functional in the current environment.
  • Helps stay within client-imposed tool limits.

Implementation Notes

// Extend BaseToolHandler in base-tools.ts
interface ToolHandler {
  // ...existing methods
  getRequiredEnvVars(): string[];
}

// in index.ts
const enabledTools = new Set<ToolName>();

Object.values(ToolName).forEach(toolName => {
  const handler = ToolFactory.createToolHandler(toolName);
 
  // Check if all required environment variables are available
  const missingVars = handler.getRequiredEnvVars().filter(varName => !env[varName]);
  if (missingVars.length === 0) {
    enabledTools.add(toolName);
    toolHandlers.set(toolName, handler);
  }
});
  • Extend the BaseToolHandler interface to include methods like getRequiredEnvVars().
  • During server startup, iterate through all tool handlers and only register those whose requirements are satisfied by the current environment.
  • Ensure existing tool functionality is not disrupted and maintain backward compatibility.
  • (Optional) Add logging to indicate which tools are enabled/disabled and why.

Additional Context

  • Cursor MCP tool limit documentation
  • Example: A tool that manages Flink SQL statements should only be enabled if all Flink-related environment variables are present and the deployment is Confluent Cloud.

Acceptance Criteria

  • Tools are enabled/disabled dynamically based on their declared requirements and the current environment.
  • The enabling/disabling logic is easy to maintain and extend for new tools.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions