import type { ToolDefinition } from '../types/messages.js'; import { McpClient, type McpClientOptions } from './client.js'; import type { McpTransport } from './protocol.js'; /** * One MCP server in a registry: a `command` to run over stdio, or a `url` to reach over HTTP. Any * string may hold `${NAME}` placeholders, filled from the environment when the server connects, so a * configuration file names credentials without containing them. */ export interface McpServerConfig { /** The executable of a local server, run over stdio. */ command?: string; /** Its arguments. */ args?: string[]; /** Environment variables for the process, such as an API token. */ env?: Record; /** Working directory for the process. */ cwd?: string; /** * Which of this process's own environment variables a local server inherits, besides `env`. By * default, only what a process needs to start, never an API key; a list adds variables by name, * `true` passes the whole environment, and `false` nothing but `env`. */ inheritEnv?: boolean | string[]; /** The endpoint of a remote server, reached over HTTP. */ url?: string; /** Headers sent to a remote server, such as authorization. */ headers?: Record; /** * Tools offered to agents, by name; `*` matches any run of characters, so `list_*` allows every * listing tool. Defaults to every tool the server has. */ allowTools?: string[]; /** Tools never offered, in the same pattern syntax. A denied tool stays denied even when allowed. */ denyTools?: string[]; /** Prefix of the tool names agents see, so two servers' `search` stay apart. Defaults to the server's name; `false` keeps names as they are. */ prefix?: string | false; /** How long a request to this server waits. Defaults to 30 seconds. */ timeoutMs?: number; /** `false` keeps the server in the file but out of the registry. */ enabled?: boolean; } /** * A registry's configuration: the servers by name, and named bundles of their tools. `mcpServers` is * accepted in place of `servers`, so the configuration file desktop MCP clients use works as it is. */ export interface McpRegistryConfig { /** The servers, by name. */ servers?: Record; /** The same, under the name desktop MCP clients use. */ mcpServers?: Record; /** * Tool bundles an agent receives by name. Each entry is a server's name, for all its allowed tools, * or `server/tool`, where the tool may be a pattern such as `github/list_*`. */ bundles?: Record; } /** Options for an `McpRegistry`. */ export interface McpRegistryOptions { /** Where `${NAME}` placeholders are read from. Defaults to `process.env`. */ env?: Record; /** Name and version the clients report in the handshake. */ clientInfo?: McpClientOptions['clientInfo']; /** Replaces the global `fetch` for HTTP servers. */ fetch?: typeof globalThis.fetch; /** Builds a server's transport, for a custom transport or tests. Defaults to stdio or HTTP by the configuration. */ transport?: (name: string, config: McpServerConfig) => McpTransport; } /** One server's health, from `McpRegistry.health()`. */ export interface McpServerHealth { /** The server's name. */ name: string; /** Whether it connected and listed its tools. */ ok: boolean; /** How long connecting and listing took, in milliseconds. */ latencyMs: number; /** Tools it offers after the allow and deny lists. */ tools?: number; /** What went wrong, when it is not healthy. */ error?: string; } /** Raised for a configuration the registry cannot use, or a server or bundle it does not know. */ export declare class McpRegistryError extends Error { /** The server concerned, when there is one. */ readonly server?: string | undefined; constructor(message: string, /** The server concerned, when there is one. */ server?: string | undefined); } /** * Many MCP servers behind one configuration. Servers connect on first use and stay connected; each * one's allow and deny lists decide which tools agents see; and `tools()` hands an agent a bundle, * a server, or everything, by name. * * This is the integration catalogue: rather than shipping adapters for every SaaS product, the * package reaches whatever an MCP server exposes, under your policy. */ export declare class McpRegistry { private readonly options; private readonly servers; private readonly bundles; private readonly clients; private readonly toolCache; constructor(config: McpRegistryConfig, options?: McpRegistryOptions); /** A registry from a JSON configuration file. */ static fromFile(path: string, options?: McpRegistryOptions): Promise; /** The enabled servers' names. */ serverNames(): string[]; /** The bundles' names. */ bundleNames(): string[]; /** A server's client, created on first use. It connects on its first request. */ client(name: string): McpClient; /** * Tools for an agent. Each name is a bundle or a server; with none, every enabled server's allowed * tools. A tool named by two entries appears once. Each server's tool list is read once and kept; * `refresh()` reads it again. */ tools(names?: string | readonly string[]): Promise; /** Forgets the tool lists read so far, for servers whose tools change. */ refresh(): void; /** * Connects to every server and lists its tools, in parallel, reporting each one's health. A server * that fails does not fail the check; it is reported unhealthy with the reason. */ health(): Promise; /** Closes every connection. */ close(): Promise; private serverTools; } /** * Checks a registry configuration and returns it, or throws an `McpRegistryError` that names the * server and the field at fault. */ export declare function validateMcpConfig(value: unknown): McpRegistryConfig;