Package com.tnsai.mcp.registry
Class UnifiedMcpRegistry
java.lang.Object
com.tnsai.mcp.registry.UnifiedMcpRegistry
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 Summary
ConstructorsConstructorDescriptionCreates a UnifiedMcpRegistry with all default registry sources and default cache TTL.UnifiedMcpRegistry(List<McpRegistrySource> sources, Duration cacheTtl) Creates a UnifiedMcpRegistry with specified sources and cache TTL. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddSource(McpRegistrySource source) Adds a registry source.voidClears all cached entries.intReturns the number of cached entries.Gets a specific server by name, trying sources in priority order.Returns all registered sources.voidremoveSource(String sourceName) Removes a registry source by name.Searches across all sources, filters incompatible protocol versions, deduplicates by name (keeping highest priority), and sorts results.
-
Constructor Details
-
UnifiedMcpRegistry
public UnifiedMcpRegistry()Creates a UnifiedMcpRegistry with all default registry sources and default cache TTL. -
UnifiedMcpRegistry
Creates a UnifiedMcpRegistry with specified sources and cache TTL.- Parameters:
sources- registry sources to aggregatecacheTtl- cache time-to-live duration
-
-
Method Details
-
search
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
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
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
Adds a registry source.- Parameters:
source- the source to add
-
removeSource
Removes a registry source by name.- Parameters:
sourceName- the source name to remove
-