UNPKG

@juspay/neurolink

Version:

The pipe layer of an AI nervous system: one interface connecting provider neurons to your application, across three inference types — generate, stream and decide. `decide` returns typed, calibrated judgements from a non-generative model (~400ms, ~$0.00002

192 lines (191 loc) • 6.27 kB
/** * MCP Registry Client * * Client for discovering MCP servers. It always knows a built-in catalog of * well-known servers plus any custom entries. When remote lookup is enabled * (`remoteLookup: true`, off by default) it also consults: * - the official MCP Registry (https://registry.modelcontextprotocol.io) * - custom registries that serve the same `/v0.1` API * * `npm` and `github` registry sources are accepted in configuration but not * queried. * * @module mcp/mcpRegistryClient * @since 8.39.0 */ import { EventEmitter } from "events"; import type { MCPServerInfo, MCPRegistryClientConfig, RegistryConfig, RegistrySearchOptions, RegistrySearchResult, McpRegistryEntry } from "../types/index.js"; /** * MCP Registry Client * * Provides methods to discover and install MCP servers from registries. * * @example * ```typescript * const client = new MCPRegistryClient(); * * // Search for servers * const results = await client.search({ query: "database" }); * * // Get server details * const entry = await client.getEntry("postgres"); * * // Convert to MCPServerInfo * const serverInfo = client.toServerInfo(entry); * * // Opt in to the official MCP Registry (remote entries are never `verified`) * const remote = new MCPRegistryClient({ remoteLookup: true }); * const found = await remote.getEntry("io.github.example/my-server"); * ``` */ export declare class MCPRegistryClient extends EventEmitter { private config; private cache; private customEntries; constructor(config?: MCPRegistryClientConfig); /** * Search the registry */ search(options?: RegistrySearchOptions): Promise<RegistrySearchResult>; /** * Get a specific entry by ID. * * Checks custom entries, then the built-in catalog. Only when remote * lookup is enabled does a miss fall through to the configured registries * (first hit wins); a registry that fails or answers with something * unreadable is skipped, so the result is `undefined` rather than an error. */ getEntry(id: string): Promise<McpRegistryEntry | undefined>; /** * Get all available entries. * * Lists the built-in catalog, then the custom entries (a custom entry * replaces a built-in one with the same id), then, when remote lookup is * enabled, the servers of each configured registry. A remote entry never * replaces a local one. A registry that cannot be read contributes nothing. */ getAllEntries(): Promise<McpRegistryEntry[]>; /** * Collect local entries and, when remote lookup is on, each registry's * servers. `query` narrows the remote lists with the registry's own * `search` parameter (substring match on server name); `search()` still * applies its full filter afterwards. * * The merged list is cached only when every registry answered, so a * transient failure is not pinned for the whole TTL. */ private collectEntries; /** * Registries the client may query: `official` and `custom` sources with a * usable URL. Other sources are skipped. */ private getRemoteTargets; private fetchRemoteEntry; private fetchRemoteList; /** * GET a JSON document from a registry, bounded by its timeout. A 404 * resolves with an undefined body (a normal "not found"); any other * non-2xx status, a network error, a timeout or a body that is not JSON * rejects. */ private requestJson; /** * Parse a JSON body, refusing to buffer more than * `REMOTE_MAX_RESPONSE_BYTES`. The request timeout bounds duration, not * memory, so the size is checked while reading. */ private readBoundedJson; private reportRemoteError; private readCache; private readRemoteCache; private writeRemoteCache; /** * The client-wide `enableCache: false` is a ceiling: a registry can switch * its own caching off but cannot turn it back on. */ private isRemoteCacheEnabled; private writeCache; /** * Get entries by category */ getByCategory(category: string): Promise<McpRegistryEntry[]>; /** * Get entries by tag */ getByTag(tag: string): Promise<McpRegistryEntry[]>; /** * Get all categories */ getCategories(): Promise<string[]>; /** * Get all tags */ getTags(): Promise<string[]>; /** * Convert registry entry to MCPServerInfo */ toServerInfo(entry: McpRegistryEntry): MCPServerInfo; /** * Add a custom registry entry */ addCustomEntry(entry: McpRegistryEntry): void; /** * Remove a custom registry entry */ removeCustomEntry(id: string): boolean; /** * Add a registry configuration */ addRegistry(config: RegistryConfig): void; /** * Turn remote lookup on or off at runtime, e.g. on the client returned by * `NeuroLink.getMCPRegistryClient()`. Off is the default. Clears the cache * so the next lookup reflects the new setting. */ setRemoteLookup(enabled: boolean): void; /** * Clear the cache */ clearCache(): void; /** * Check if required environment variables are set */ checkRequiredEnvVars(entry: McpRegistryEntry): { ready: boolean; missing: string[]; }; /** * Get installation command for an entry */ getInstallCommand(entry: McpRegistryEntry): string | undefined; /** * Get popular servers */ getPopularServers(limit?: number): Promise<McpRegistryEntry[]>; /** * Get verified servers */ getVerifiedServers(): Promise<McpRegistryEntry[]>; /** * Get statistics */ getStatistics(): Promise<{ totalEntries: number; verifiedEntries: number; categories: number; tags: number; customEntries: number; }>; } /** * Global MCP registry client instance */ export declare const globalMCPRegistryClient: MCPRegistryClient; /** * Quick lookup function for well-known servers */ export declare function getWellKnownServer(id: string): McpRegistryEntry | undefined; /** * Get all well-known servers */ export declare function getAllWellKnownServers(): McpRegistryEntry[];