/** * Supervises one managed MCP connection and its registered tools. * @module @anht3889/dsh-mcp-mgmt-bundle/manager/connection */ import type { Transport } from '@modelcontextprotocol/sdk/shared/transport.js'; import type { McpConnectionStatus, McpLogEntry, McpServerRecord, McpToolInfo } from '@anht3889/dsh-mcp-mgmt-mcp/types'; import { type ToolContext } from './tools.ts'; /** Dependencies and event sinks for one supervised MCP connection. */ export interface ConnectionHooks { /** The tool registry where discovered MCP tools are registered. */ ctx: ToolContext; /** * Raw tool names to list without registering, resolved by the record owner * for the first generation and replaced by `applyToolSelection`. */ disabledTools: readonly string[]; /** Creates a new transport for each connection generation. */ createTransport?: () => Transport; /** Resolves HTTP credentials when the default transport factory is used. */ resolveHeaders?: () => Promise>; /** Waits before the next connection generation. */ delay?: (milliseconds: number) => Promise; /** Receives each observable connection state transition. */ onStatus(status: McpConnectionStatus): void; /** Receives every tool the server listed, after each discovery pass. */ onTools(tools: McpToolInfo[]): void; /** Receives lifecycle log entries. */ onLog(entry: McpLogEntry): void; } /** Handle that controls a supervised MCP connection. */ export interface ConnectionHandle { /** Stops future reconnects, closes the client, and unregisters its tools. */ stop(): Promise; /** * Re-registers the server's tools against a new selection, keeping the live * transport. A connection that has not finished connecting adopts the * selection in its pending discovery pass instead. * * @param disabledTools - raw tool names to list without registering. * @throws when the connected server fails to re-list its tools, after * closing the client so the supervisor reconnects. */ applyToolSelection(disabledTools: readonly string[]): Promise; } /** * Connects to an MCP server, registers its tools, and reconnects after loss. * * @param record - The durable MCP server configuration. * @param hooks - Tool registry, injectable transport factory, and lifecycle event sinks. * @returns A handle that stops the connection and unregisters its tools. */ export declare function startConnection(record: McpServerRecord, hooks: ConnectionHooks): ConnectionHandle;