Class UnifiedMcpRegistry

java.lang.Object
com.tnsai.mcp.registry.UnifiedMcpRegistry

public class UnifiedMcpRegistry extends Object
Unified MCP registry that aggregates results from multiple registry sources.

Features:

  • Multi-source aggregation with configurable source priority
  • Deduplication by server name (keeps highest priority source)
  • Protocol version compatibility filtering
  • Time-based caching with configurable TTL
  • Resilient: continues with remaining sources if one fails
  • Thread-safe implementation using ConcurrentHashMap

Source priority ranking (highest first): official > camel > smithery > mcpservers.org

Example usage:


 UnifiedMcpRegistry registry = new UnifiedMcpRegistry();
 List<McpServerEntry> results = registry.search("filesystem");
 Optional<McpServerEntry> server = registry.getServer("filesystem");
 
  • Constructor Details

    • UnifiedMcpRegistry

      public UnifiedMcpRegistry()
      Creates a UnifiedMcpRegistry with all default registry sources and default cache TTL.
    • UnifiedMcpRegistry

      public UnifiedMcpRegistry(List<McpRegistrySource> sources, Duration cacheTtl)
      Creates a UnifiedMcpRegistry with specified sources and cache TTL.
      Parameters:
      sources - registry sources to aggregate
      cacheTtl - cache time-to-live duration
  • Method Details

    • search

      public List<McpServerEntry> search(String query)
      Searches across all sources, filters incompatible protocol versions, deduplicates by name (keeping highest priority), and sorts results.
      Parameters:
      query - search query string
      Returns:
      deduplicated and sorted list of compatible server entries
    • getServer

      public Optional<McpServerEntry> getServer(String name)
      Gets a specific server by name, trying sources in priority order. Filters out servers with incompatible protocol versions.
      Parameters:
      name - the server name to look up
      Returns:
      the server entry if found in any source and protocol-compatible
    • getSources

      public List<McpRegistrySource> getSources()
      Returns all registered sources.
      Returns:
      unmodifiable list of registry sources
    • clearCache

      public void clearCache()
      Clears all cached entries.
    • getCacheSize

      public int getCacheSize()
      Returns the number of cached entries.
      Returns:
      cache size
    • addSource

      public void addSource(McpRegistrySource source)
      Adds a registry source.
      Parameters:
      source - the source to add
    • removeSource

      public void removeSource(String sourceName)
      Removes a registry source by name.
      Parameters:
      sourceName - the source name to remove