#!/usr/bin/env node
import { EventEmitter } from "node:events";
import { ToolGovernor, ToolPermissionLevel, type GovernanceRule, type ToolGovernancePolicy, type GovernedToolResult, type AuditRecord } from "./governance.js";
export interface McpServerConfig {
    name: string;
    transport: "stdio" | "streamable-http" | "http";
    command?: string;
    args?: string[];
    url?: string;
    env?: Record<string, string>;
    headers?: Record<string, string>;
    startupTimeoutMs?: number;
}
export interface McpDegradedServer {
    name: string;
    consecutiveTimeouts: number;
    lastError: string;
}
export interface McpServerInfo {
    name: string;
    transport: string;
    capabilities: {
        tools?: boolean;
        resources?: boolean;
        prompts?: boolean;
        sampling?: boolean;
    };
    serverInfo?: {
        name: string;
        version: string;
    };
    connected: boolean;
    error?: string;
}
export interface McpTool {
    name: string;
    description: string;
    inputSchema: {
        type: "object";
        properties: Record<string, unknown>;
        required?: string[];
    };
    _serverName?: string;
}
export interface McpResource {
    uri: string;
    name: string;
    description: string;
    mimeType?: string;
    _serverName?: string;
}
export interface McpPrompt {
    name: string;
    description: string;
    arguments?: Array<{
        name: string;
        description: string;
        required?: boolean;
    }>;
    _serverName?: string;
}
interface PermissionPolicy {
    allowServers: string[] | null;
    denyServers: string[];
    requireConsentFor: string[];
    maxToolCallDepth: number;
    toolAllowPatterns?: string[] | null;
    toolDenyPatterns?: string[];
    governance?: Partial<ToolGovernancePolicy>;
    permissionRules?: GovernanceRule[];
    defaultToolPermission?: ToolPermissionLevel;
}
export declare class McpHost extends EventEmitter {
    private servers;
    private aggregatedTools;
    private aggregatedResources;
    private aggregatedPrompts;
    private permissionPolicy;
    private initialized;
    private toolGovernor;
    private permissionResolver;
    private auditSalt;
    private degradedServers;
    private preflightConcurrency;
    private resourceExhausted;
    constructor(permissionPolicy?: Partial<PermissionPolicy>, options?: {
        preflightConcurrency?: number;
    });
    /**
     * Register a new MCP server definition. Does not connect immediately.
     * Call connectServer() to establish the connection.
     */
    registerServer(config: McpServerConfig): string;
    /**
     * Connect to a registered server and perform the MCP initialize handshake.
     */
    connectServer(name: string): Promise<McpServerInfo>;
    /**
     * Connect all registered servers with bounded concurrency.
     */
    connectAll(): Promise<Array<{
        name: string;
        ok: boolean;
        error?: string;
    }>>;
    /** Get servers that have been marked degraded due to consecutive timeouts. */
    getDegradedServers(): McpDegradedServer[];
    /** Whether the host has entered resource-exhaustion degraded mode. */
    isResourceExhausted(): boolean;
    /**
     * Disconnect and remove a server.
     */
    removeServer(name: string): Promise<void>;
    /**
     * List all registered servers.
     */
    listServers(): McpServerInfo[];
    getServerInfo(name: string): McpServerInfo;
    private aggregateCapabilities;
    listTools(): Promise<{
        tools: McpTool[];
    }>;
    callTool(name: string, args: Record<string, unknown>, serverHint?: string): Promise<unknown>;
    /**
     * Governed tool call with full governance pipeline:
     * permission check → raw call → secret redaction → compression → audit
     */
    governedCallTool(name: string, args: Record<string, unknown>, serverHint?: string): Promise<GovernedToolResult>;
    /** Get the tool governor instance */
    getToolGovernor(): ToolGovernor;
    /** Get the audit logger */
    getAuditLog(): AuditRecord[];
    /** Get audit log for a specific tool */
    getAuditLogForTool(toolName: string): AuditRecord[];
    /** Get audit log for a specific server */
    getAuditLogForServer(serverName: string): AuditRecord[];
    /** Get error audit records */
    getAuditErrors(): AuditRecord[];
    /** Update governance policy at runtime */
    updateGovernancePolicy(update: Partial<ToolGovernancePolicy>): void;
    listResources(): Promise<{
        resources: McpResource[];
    }>;
    readResource(uri: string, serverHint?: string): Promise<unknown>;
    listPrompts(): Promise<{
        prompts: McpPrompt[];
    }>;
    getPrompt(name: string, args?: Record<string, string>, serverHint?: string): Promise<unknown>;
    private checkPermission;
    close(): Promise<void>;
}
export declare function getOrCreateHost(): McpHost;
export declare function resetHost(): void;
export {};
