Skip to content

Feature Request: Auto-Discovery of Tools from MCP Servers #39

@alejandro-alarcon-t

Description

@alejandro-alarcon-t

Summary

Add automatic tool discovery functionality for MCP servers with support for latent server definitions and per-user tool access, eliminating the need for manual tool definition while enabling dynamic tool instantiation based on user permissions and configuration.

Current Behavior

When configuring MCP servers in the system:

  1. Admin manually configures MCP server connection details in the admin portal
  2. MCP servers are defined but not actually instantiated until user access
  3. Tools available on servers must be manually defined/configured without knowing actual capabilities
  4. No way to handle per-user tool access based on different API keys or permissions
  5. Tool definitions can become outdated if the MCP server adds/removes/modifies tools
  6. No automatic synchronization between server capabilities and configured tools

Proposed Feature

Implement a latent MCP server definition system with auto-discovery that:

1. Latent Server Configuration

  • Define server templates in admin portal with command (e.g., npx) and environment variable requirements
  • Defer instantiation until actual user access with proper credentials
  • Support per-user configurations with different API keys/permissions leading to different available tools
  • Enable configuration validation without requiring actual server connection

2. Dynamic Tool Discovery

  • Auto-discover tools on first user instantiation when user provides required environment variables
  • Cache discovered tools per user/configuration to avoid repeated discovery calls
  • Sync tool definitions with what the server actually provides for each user context
  • Update tool configurations when server capabilities change
  • Provide manual override options for custom tool configurations

3. User-Specific Tool Access

  • Different tools for different users based on their API keys and permissions
  • Isolated tool discovery ensuring users only see tools they have access to
  • Dynamic tool loading based on user session and credentials

Expected Benefits

  • Reduced Manual Work: No need to manually define each tool before knowing server capabilities
  • User-Specific Access: Tools automatically reflect what each user can actually access
  • Always Up-to-Date: Tools automatically reflect current server capabilities per user
  • Error Prevention: Eliminates mismatched tool definitions and permission issues
  • Better UX: Faster MCP server onboarding with proper user isolation
  • Scalable Maintenance: Automatic updates when servers change their APIs
  • Flexible Deployment: Support for different user permissions and configurations

Implementation Approach

1. Latent Server Definition

# Pseudo-code example
class LatentMCPServer:
    def __init__(self, name, command, env_variables, description):
        self.name = name
        self.command = command  # e.g., "npx @some/mcp-server"
        self.required_env_vars = env_variables  # e.g., ["API_KEY", "ENDPOINT_URL"]
        self.description = description
        self.auto_discovery_enabled = True
        self.is_instantiated = False
        
    def can_instantiate(self, user_env):
        """Check if user has all required environment variables"""
        return all(var in user_env for var in self.required_env_vars)
        
    def get_user_specific_config(self, user_env):
        """Generate user-specific configuration"""
        return {var: user_env[var] for var in self.required_env_vars}

class UserMCPInstance:
    def __init__(self, latent_server, user_config):
        self.latent_server = latent_server
        self.user_config = user_config
        self.discovered_tools = None
        self.last_discovery = None
        
    async def discover_tools(self):
        """Discover tools for this specific user configuration"""
        if not self.latent_server.can_instantiate(self.user_config):
            raise ValueError("Missing required environment variables")
            
        # Instantiate MCP server with user-specific config
        client = await self.instantiate_mcp_client()
        available_tools = await client.list_tools()
        
        user_tools = []
        for tool_info in available_tools:
            tool = UserTool(
                name=tool_info.name,
                description=tool_info.description,
                config_json=tool_info.schema,
                user_id=self.user_config.get('user_id'),
                server_instance_id=self.generate_instance_id(),
                auto_discovered=True,
                last_synced=datetime.now()
            )
            user_tools.append(tool)
            
        self.discovered_tools = user_tools
        self.last_discovery = datetime.now()
        return user_tools

2. Admin Portal Configuration

# Admin defines latent server
latent_server = LatentMCPServer(
    name="Notion API",
    command="npx @notion/mcp-server",
    env_variables=["NOTION_API_KEY", "NOTION_DATABASE_ID"],
    description="Notion workspace integration"
)

# User provides their specific configuration
user_config = {
    "user_id": "user123",
    "NOTION_API_KEY": "secret_user_key",
    "NOTION_DATABASE_ID": "user_specific_db_id"
}

# Discovery happens on first use
user_instance = UserMCPInstance(latent_server, user_config)
discovered_tools = await user_instance.discover_tools()

3. UI/UX Enhancement

  • Latent Server Management: Interface for defining server templates without instantiation
  • User Environment Setup: Allow users to provide required environment variables
  • Auto-Discovery Status: Show discovery status per user/server combination
  • Tool Preview: Display discovered tools before making them available
  • Permission Visualization: Clear indication of which tools each user can access
  • Manual Override Support: Allow custom configurations for auto-discovered tools

4. Configuration Schema

{
  "latent_server_config": {
    "name": "server_name",
    "command": "npx @example/mcp-server",
    "required_env_vars": ["API_KEY", "ENDPOINT"],
    "auto_discovery": {
      "enabled": true,
      "cache_duration": "1h",
      "sync_on_changes": true,
      "allow_user_overrides": true
    },
    "user_isolation": {
      "enabled": true,
      "permission_based_tools": true
    }
  }
}

User Stories

Story 1: Latent Server Definition

As an admin, I want to define MCP server templates without requiring actual instantiation, so I can configure servers that users will access with their own credentials.

Acceptance Criteria:

  • Can define server command and required environment variables
  • Server definition is stored without attempting connection
  • Validation of configuration structure without instantiation
  • Clear documentation of what users need to provide

Story 2: User-Specific Tool Discovery

As a user, I want to provide my credentials and automatically discover tools I have access to, so I can use MCP servers with my specific permissions.

Acceptance Criteria:

  • Can provide required environment variables for configured servers
  • Tools are discovered based on my specific API keys/permissions
  • Only see tools that my credentials can actually access
  • Discovery happens seamlessly on first use

Story 3: Per-User Tool Isolation

As an admin, I want different users to see different tools from the same MCP server based on their permissions, so tool access reflects actual capabilities.

Acceptance Criteria:

  • Users with different API keys see different tool sets
  • Tool discovery is isolated per user session
  • No cross-contamination of tool definitions between users
  • Clear audit trail of who has access to what tools

Story 4: Dynamic Tool Updates

As a user, I want my available tools to update automatically when my permissions change or the server adds new capabilities, so my tool set stays current.

Acceptance Criteria:

  • Periodic re-discovery based on configuration
  • Detection of permission changes
  • Automatic tool set updates
  • Notifications when tool availability changes

Story 5: Graceful Fallback and Error Handling

As a user, I want clear feedback when I can't access certain tools due to missing credentials or permissions, so I understand what I need to provide.

Acceptance Criteria:

  • Clear error messages for missing environment variables
  • Guidance on what credentials are needed
  • Graceful degradation when some tools are unavailable
  • Status indicators for server connectivity and tool availability

Technical Considerations

MCP Protocol Integration

  • Leverage MCP's tools/list capability for discovery
  • Handle authentication/authorization per user context
  • Support for different server instances with same codebase
  • Efficient caching to avoid repeated discovery calls

Security and Isolation

  • Secure storage of user environment variables
  • Proper isolation of user configurations
  • Audit logging of tool access and usage
  • Protection against credential leakage between users

Performance Optimization

  • Intelligent caching of discovered tools
  • Lazy loading of tool definitions
  • Efficient re-discovery triggers
  • Minimal overhead for tool availability checks

Scalability Considerations

  • Support for multiple users accessing the same server type
  • Efficient storage of per-user tool definitions
  • Reasonable limits on discovery frequency
  • Cleanup of stale user configurations

Migration Strategy

  1. Phase 1: Implement latent server definition system
  2. Phase 2: Add user-specific tool discovery
  3. Phase 3: Migrate existing manual tool definitions to auto-discovery
  4. Phase 4: Add advanced features like permission-based filtering and real-time sync

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions