import { a as McpServerConfig, b as McpServersConfig } from './config.d-BfJUXxC0.js';
import { a as CapabilityProvider, C as CapabilityKind, b as CapabilityResult } from './capability.d-3C62G8Eq.js';

type McpCapabilityKind = 'tool' | 'resource' | 'prompt';
type McpCapabilityRisk = 'read' | 'write' | 'network' | 'exec';
interface McpCatalogItem {
    id: string;
    serverId: string;
    kind: McpCapabilityKind;
    name: string;
    title?: string;
    summary: string;
    tags?: string[];
    risk?: McpCapabilityRisk;
    annotations?: Record<string, unknown>;
    cachedAt: string;
}
interface McpCapabilityDescriptor extends McpCatalogItem {
    inputSchema?: unknown;
    outputSchema?: unknown;
    promptArgsSchema?: unknown;
    uri?: string;
    mimeType?: string;
}
interface McpServerCatalogSnapshot {
    serverId: string;
    items: McpCatalogItem[];
    descriptors: McpCapabilityDescriptor[];
    updatedAt: string;
}
interface McpCatalogSearchOptions {
    kind?: McpCapabilityKind;
    limit?: number;
}
declare function defaultMcpCacheDir(): string;
declare function createMcpCapabilityId(serverId: string, kind: McpCapabilityKind, name: string): string;
declare function parseMcpCapabilityId(id: string): {
    serverId: string;
    kind: McpCapabilityKind;
    name: string;
};
declare function searchMcpCatalog(items: readonly McpCatalogItem[], query: string, options?: McpCatalogSearchOptions): McpCatalogItem[];
declare function getMcpCachePaths(cacheDir: string, serverId: string): {
    catalogDir: string;
    indexPath: string;
    itemsPath: string;
};

interface McpServerRuntimeDiagnostics {
    serverId: string;
    connect: 'lazy' | 'prewarm' | 'disabled';
    status: 'idle' | 'connecting' | 'ready' | 'error' | 'disabled';
    dirty: boolean;
    lastError?: string;
    cachedAt?: string;
    tools: number;
    resources: number;
    prompts: number;
}
declare class McpServerRuntime {
    private readonly serverId;
    private readonly config;
    private readonly cacheDir;
    private transport?;
    private readonly pending;
    private nextRequestId;
    private initialized;
    private connectPromise?;
    private catalog?;
    private diagnostics;
    constructor(serverId: string, config: McpServerConfig, cacheDir: string);
    getDiagnostics(): McpServerRuntimeDiagnostics;
    prewarmIfNeeded(): Promise<void>;
    /** Load catalog from memory or disk only — never triggers a lazy connection. */
    getCachedCatalog(): Promise<McpServerCatalogSnapshot | undefined>;
    getCatalog(forceRefresh?: boolean): Promise<McpServerCatalogSnapshot>;
    describeCapability(capabilityId: string): Promise<McpCapabilityDescriptor | undefined>;
    callTool(name: string, args: Record<string, unknown>): Promise<{
        content?: string;
        structuredContent?: unknown;
        metadata?: Record<string, unknown>;
    }>;
    readResource(name: string, options: Record<string, unknown>): Promise<{
        content?: string;
        structuredContent?: unknown;
        metadata?: Record<string, unknown>;
    }>;
    getPrompt(name: string, args: Record<string, unknown>): Promise<unknown>;
    refreshCatalog(forceReconnect?: boolean): Promise<void>;
    /** Public teardown — clears everything including the connect lock. */
    dispose(): Promise<void>;
    /** Internal transport teardown — does NOT clear connectPromise so the
     *  retry loop inside doConnect() can safely call it between attempts. */
    private resetTransport;
    private connect;
    private doConnect;
    private listDescriptors;
    private request;
    private notify;
    private handleMessage;
    private failPending;
    private applyCatalogSnapshot;
}

/**
 * `McpCapabilityProvider` — implements the Layer A `CapabilityProvider`
 * contract for an MCP server fleet.
 *
 * FEATURE_082 (v0.7.24): moved from
 * `@kodax-ai/coding/src/capabilities/providers/mcp/provider.ts` to this package.
 * The coding-specific `registerConfiguredMcpCapabilityProvider` adapter (which
 * pulls in `KodaXExtensionRuntime`) lives in
 * `@kodax-ai/coding/src/capabilities/providers/mcp-adapter.ts`.
 */

interface McpProviderOptions {
    cacheDir?: string;
}
declare class McpCapabilityProvider implements CapabilityProvider {
    readonly id = "mcp";
    readonly kinds: CapabilityProvider['kinds'];
    private readonly runtimes;
    private readonly cacheDir;
    /**
     * Construct an MCP capability provider.
     *
     * **Cache-dir capture warning (v0.7.35.1 FEATURE_145)** — when
     * `options.cacheDir` is omitted, this constructor resolves
     * `defaultMcpCacheDir()` ONCE at instantiation time and threads the
     * result into every `McpServerRuntime` it spawns. If a substrate
     * consumer plans to redirect the agent config home via
     * `setAgentConfigHome()` from `@kodax-ai/agent`, that call MUST happen
     * BEFORE constructing this provider. Late calls have no effect on
     * already-constructed runtimes.
     *
     * To bypass the agent-home resolver entirely, pass
     * `options.cacheDir` explicitly — that path wins unconditionally.
     */
    constructor(servers: McpServersConfig | undefined, options?: McpProviderOptions);
    hasActiveServers(): boolean;
    prewarm(): Promise<void>;
    search(query: string, options?: {
        kind?: CapabilityKind;
        limit?: number;
        server?: string;
    }): Promise<unknown[]>;
    describe(id: string): Promise<unknown>;
    execute(id: string, input: Record<string, unknown>): Promise<CapabilityResult>;
    read(id: string, options?: Record<string, unknown>): Promise<CapabilityResult>;
    getPrompt(id: string, args?: Record<string, unknown>): Promise<unknown>;
    getPromptContext(): Promise<string | undefined>;
    getDiagnostics(): Record<string, unknown> | undefined;
    refresh(): Promise<void>;
    dispose(): Promise<void>;
    private collectCatalogItems;
    private listServerDiagnostics;
    private requireRuntime;
}

interface McpTransportEvents {
    /** Called with a complete JSON-RPC message (raw JSON string). */
    onMessage(raw: string): void;
    onError(error: Error): void;
    onClose(reason: string): void;
}
interface McpTransport {
    open(events: McpTransportEvents): Promise<void>;
    /** Send a JSON string. The transport handles framing. */
    send(json: string): Promise<void>;
    close(): Promise<void>;
    readonly connected: boolean;
}
type StdioFraming = 'content-length' | 'ndjson';
interface McpTransportOptions {
    stdioFraming?: StdioFraming;
}
declare function createMcpTransport(config: McpServerConfig, options?: McpTransportOptions): McpTransport;

export { McpCapabilityProvider as b, McpServerRuntime as g, createMcpCapabilityId as k, createMcpTransport as l, defaultMcpCacheDir as m, getMcpCachePaths as n, parseMcpCapabilityId as p, searchMcpCatalog as s };
export type { McpCapabilityDescriptor as M, McpCapabilityKind as a, McpCapabilityRisk as c, McpCatalogItem as d, McpProviderOptions as e, McpServerCatalogSnapshot as f, McpServerRuntimeDiagnostics as h, McpTransport as i, McpTransportEvents as j };
