import { Client } from "@modelcontextprotocol/client"; import { type ElicitUi } from "./elicitation.js"; import type { ServerFilter } from "./config-ladder.js"; export type LogFn = (level: "info" | "warn" | "error", message: string) => void; export type ResolvedConnection = { /** Base URL including /mcp, WITHOUT any token path (e.g. http://127.0.0.1:9741/mcp). */ baseUrl: string; /** Env var holding the inbound bearer token (read at connect time), if any. */ bearerTokenEnv?: string; /** Explicit token already present in the configured URL path (user override). */ urlToken?: string; }; export type ConnectionState = "disconnected" | "connecting" | "connected" | "failed"; export type ToolSummary = { name: string; description?: string; inputSchema?: unknown; }; export type PromptArgument = { name: string; description?: string; required?: boolean; }; export type PromptSummary = { name: string; title?: string; description?: string; arguments?: PromptArgument[]; }; export type ResourceSummary = { uri: string; name?: string; description?: string; mimeType?: string; _meta?: Record; }; /** Optional callbacks fired by the connection (set from index.ts wiring). */ export type ConnectionHooks = { /** tools/list_changed arrived — caches invalidated; refresh derived surfaces. */ onToolsChanged?: () => void; /** connection state transitioned — refresh footer/status surfaces. */ onStateChange?: (state: ConnectionState) => void; /** Stage 2: the combiner announced a widget UI URL while an agent tool call * is held in flight — the client should open it (gated by uiAutoOpen). */ onWidgetUrl?: (url: string) => void; }; /** Build the tokened endpoint URL: /mcp/ (combiner's URL form). */ export declare function tokenedUrl(baseUrl: string, token: string): string; export declare class CombinerConnection { private conn; private readonly log; /** Latest dialog-capable UI, refreshed each session_start. */ private elicitUi; private prompts; private promptsFetchedAt; private resources; private resourcesFetchedAt; private token; private client; private connecting; private tools; private toolsFetchedAt; private hooks; state: ConnectionState; lastError: string | undefined; constructor(conn: ResolvedConnection, log: LogFn); /** Bind lifecycle hooks (tools changed / state transitions). */ setHooks(hooks: ConnectionHooks): void; /** Effective grouping token for this session (explicit URL token wins). */ get sessionToken(): string | undefined; /** Bind the UI slice used by elicitation (called from session_start). */ bindUi(ui: ElicitUi): void; /** Swap connection inputs (base URL / bearer env) when a session re-resolves a * different combiner URL (e.g. a worktree branch pinning its own combiner). * No-op when nothing changed; otherwise drops the client for a fresh connect. */ rebind(conn: ResolvedConnection): boolean; /** Set the grouping token for this session; resets any open connection. */ setToken(token: string): void; /** Drop the connection + caches (session reset / shutdown). Never throws. */ reset(reason: string): Promise; /** Effective token: explicit URL token wins over the minted session token. */ private effectiveToken; /** Connect (idempotent, single-flight). Throws with a human message on failure. */ ensureConnected(): Promise; /** tools/list, cached until invalidated (list_changed / reset / reconnect). */ listTools(force?: boolean): Promise; /** prompts/list, cached alongside tools (combiner namespaces `_`). */ listPrompts(force?: boolean): Promise; /** prompts/get through the combiner. */ getPrompt(name: string, args: Record): Promise; /** resources/list, cached alongside tools/prompts. */ listResources(force?: boolean): Promise; /** resources/read through the combiner. */ readResource(uri: string): Promise; /** callTool with a single stale-session retry: on transport/stale errors we reset * and reconnect once (the combiner may have bounced; handover keeps our token). */ callTool(name: string, args: Record | undefined): Promise; /** Control-plane origin for the combiner's REST routes (/health, /sessions/*). */ controlOrigin(): string; /** The interactive-UI URL for a resource (the combiner's UI host serves the * widget for THIS session's token), or empty when no token is set. */ uiUrlFor(resourceUri: string): string; /** Headers for control-plane calls: the same inbound bearer as /mcp (the combiner * gates its mutating routes — /sessions*, /handover* — with it; /health is open * but presenting anyway is harmless). */ private controlHeaders; /** POST the project-derived server filter for our token. The combiner accepts * pending filters pre-connect, so this is safe before the first connect. */ applyFilter(filter: ServerFilter): Promise; /** GET /health — the control-plane health snapshot. */ health(): Promise; } //# sourceMappingURL=connection.d.ts.map