import { T as ToolRegistry } from './registry-CowKS4Hh.js';
import { h as AnthropicToolDefinition } from './types-DjPlsx0H.js';

/**
 * Configuration for a stdio (subprocess) transport.
 *
 * The MCP server is spawned as a child process. Communication happens over
 * the process's stdin/stdout using newline-delimited JSON-RPC messages.
 *
 * @example
 * ```ts
 * const config: StdioTransportConfig = {
 *   type: "stdio",
 *   command: "npx",
 *   args: ["-y", "@modelcontextprotocol/server-filesystem", "/path/to/dir"],
 * };
 * ```
 */
interface StdioTransportConfig {
    type: "stdio";
    /** The executable to spawn (e.g. "node", "npx", "python"). */
    command: string;
    /** Arguments passed to the command. */
    args?: string[];
    /**
     * Additional environment variables merged into the child process's
     * environment. Inherits the current process's env by default.
     */
    env?: Record<string, string>;
}
/**
 * Configuration for an HTTP+SSE transport.
 *
 * The MCP server is a remote HTTP service that accepts JSON-RPC requests
 * via POST and pushes notifications over a Server-Sent Events stream.
 *
 * @example
 * ```ts
 * const config: HttpTransportConfig = {
 *   type: "http",
 *   url: "http://localhost:3000/mcp",
 *   headers: { Authorization: "Bearer <token>" },
 * };
 * ```
 */
interface HttpTransportConfig {
    type: "http";
    /** The base URL of the MCP server's HTTP endpoint. */
    url: string;
    /**
     * HTTP headers sent with every request.
     * Use this for authentication (e.g. `Authorization: Bearer <token>`).
     */
    headers?: Record<string, string>;
}
/** Union of all supported MCP transport configurations. */
type MCPTransportConfig = StdioTransportConfig | HttpTransportConfig;
/**
 * Configuration for constructing an `MCPClient`.
 *
 * `name` and `version` are advertised to the server during the MCP
 * initialization handshake so servers can apply client-specific behaviour.
 */
interface MCPClientConfig {
    /** Human-readable name advertised during the handshake (e.g. "sentinel-ai"). */
    name: string;
    /** SemVer string advertised during the handshake (e.g. "1.0.0"). */
    version: string;
    /** Transport to use when connecting to the MCP server. */
    transport: MCPTransportConfig;
}
/**
 * A tool exposed by an MCP server.
 *
 * `inputSchema` is a JSON Schema object (typically `{ type: "object", properties: … }`)
 * describing the arguments the tool accepts.
 */
interface MCPTool {
    name: string;
    description?: string;
    /** JSON Schema describing the tool's input arguments. */
    inputSchema: Record<string, unknown>;
}
/**
 * A resource exposed by an MCP server.
 *
 * Resources are addressable by URI and can be read by the client.
 */
interface MCPResource {
    /** Unique identifier for the resource (e.g. "file:///path/to/file"). */
    uri: string;
    name: string;
    description?: string;
    mimeType?: string;
}
/** An argument slot declared by an MCP prompt. */
interface MCPPromptArgument {
    name: string;
    description?: string;
    required?: boolean;
}
/** A prompt template exposed by an MCP server. */
interface MCPPrompt {
    name: string;
    description?: string;
    arguments?: MCPPromptArgument[];
}
interface MCPTextContent {
    type: "text";
    text: string;
}
interface MCPImageContent {
    type: "image";
    data: string;
    mimeType: string;
}
interface MCPEmbeddedResource {
    type: "resource";
    resource: {
        uri: string;
        mimeType?: string;
        /** UTF-8 text contents, if the resource is text. */
        text?: string;
        /** Base64-encoded binary contents, if the resource is binary. */
        blob?: string;
    };
}
type MCPContent = MCPTextContent | MCPImageContent | MCPEmbeddedResource;
/**
 * The result of invoking an MCP tool.
 *
 * `isError` is `true` when the tool itself reported a failure (as opposed to
 * a transport-level error, which surfaces as a thrown `MCPToolCallError`).
 */
interface MCPToolCallResult {
    content: MCPContent[];
    isError?: boolean;
}
interface MCPResourceContent {
    uri: string;
    mimeType?: string;
    /** Present when the resource is UTF-8 text. */
    text?: string;
    /** Present when the resource is binary (base64-encoded). */
    blob?: string;
}
interface MCPReadResourceResult {
    contents: MCPResourceContent[];
}

declare class MCPClient {
    private readonly config;
    private sdkClient;
    private _connected;
    constructor(config: MCPClientConfig);
    /** `true` after a successful `connect()` and before `close()`. */
    get connected(): boolean;
    /** The client name advertised during the handshake. */
    get name(): string;
    /**
     * Establishes the connection to the MCP server and performs the
     * initialization handshake (capability negotiation).
     *
     * Must be called exactly once before any other method. Calling `connect()`
     * on an already-connected client is a no-op.
     *
     * @throws {MCPConnectionError} if the transport cannot be established or
     *   the server rejects the client's hello.
     */
    connect(): Promise<void>;
    /**
     * Discovers the tools available on the connected MCP server.
     *
     * @throws {MCPNotConnectedError} if called before `connect()`.
     */
    listTools(): Promise<MCPTool[]>;
    /**
     * Invokes a tool on the connected MCP server.
     *
     * Returns the tool's result including its content blocks. If the tool
     * reports a failure (result.isError === true), that is returned normally —
     * the tool did run, it just indicated an error in its output.
     *
     * @throws {MCPNotConnectedError} if called before `connect()`.
     * @throws {MCPToolCallError} if the transport or RPC layer fails.
     */
    callTool(name: string, args: Record<string, unknown>): Promise<MCPToolCallResult>;
    /**
     * Discovers the resources available on the connected MCP server.
     *
     * @throws {MCPNotConnectedError} if called before `connect()`.
     */
    listResources(): Promise<MCPResource[]>;
    /**
     * Reads the contents of a resource by its URI.
     *
     * @throws {MCPNotConnectedError} if called before `connect()`.
     * @throws {MCPResourceError} if the transport or RPC layer fails.
     */
    readResource(uri: string): Promise<MCPReadResourceResult>;
    /**
     * Discovers the prompt templates available on the connected MCP server.
     *
     * @throws {MCPNotConnectedError} if called before `connect()`.
     */
    listPrompts(): Promise<MCPPrompt[]>;
    /**
     * Closes the connection to the MCP server.
     *
     * Safe to call multiple times — subsequent calls are no-ops.
     */
    close(): Promise<void>;
    private assertConnected;
}

/**
 * Bridges MCP server tools into agent-kit's tool system.
 *
 * Create a bridge around your `ToolRegistry`, register one or more MCP
 * clients, then use the bridge's `toAnthropicTools()` when building the
 * tools list for a Claude call. When Claude returns a tool_use block for
 * an MCP tool, route it through `callMcpTool()` (or the
 * `dispatchMcpToolUse` helper).
 *
 * ```ts
 * const registry = new ToolRegistry("business");
 * const bridge = new ToolRegistryBridge(registry);
 *
 * const mcpClient = new MCPClient({ name: "fs", version: "1.0.0", transport: ... });
 * await mcpClient.connect();
 * await bridge.registerMcpServer(mcpClient);
 *
 * // Pass to Claude — merges native tools + MCP tools
 * const tools = bridge.toAnthropicTools();
 *
 * // Dispatch an MCP tool_use block from Claude
 * if (bridge.hasMcpTool(toolName)) {
 *   const result = await bridge.callMcpTool(toolName, input);
 * }
 * ```
 */
declare class ToolRegistryBridge {
    private readonly _registry;
    private readonly mcpTools;
    constructor(registry: ToolRegistry);
    /** Access the underlying `ToolRegistry` for native tool operations. */
    get registry(): ToolRegistry;
    /**
     * Discovers all tools on the connected MCP server and registers them with
     * the bridge. Existing registrations for the same tool name are overwritten
     * (last-registered wins), which matches the behaviour of hot-reloading an
     * MCP server after it has updated its tool list.
     *
     * @returns The number of tools registered from this server.
     *
     * @throws if `client.listTools()` fails (the client must be connected).
     */
    registerMcpServer(client: MCPClient): Promise<number>;
    /**
     * Returns `true` if a tool with the given name was registered from an MCP
     * server. Use this to route `tool_use` blocks from Claude to `callMcpTool`
     * vs the native tool dispatcher.
     */
    hasMcpTool(toolName: string): boolean;
    /**
     * Returns all registered MCP tool names.
     */
    mcpToolNames(): string[];
    /**
     * Invokes a named MCP tool.
     *
     * @throws {MCPNotConnectedError} if the backing client is not connected.
     * @throws {MCPToolCallError} if the transport or RPC layer fails.
     */
    callMcpTool(toolName: string, args: Record<string, unknown>): Promise<MCPToolCallResult>;
    /**
     * Returns all tools (native registry tools + MCP server tools) in the shape
     * the Anthropic SDK's `messages.create({ tools })` parameter expects.
     *
     * Native tools use their Zod schema (converted to JSON Schema by the
     * registry). MCP tools use their server-side JSON Schema directly — so
     * Claude sees accurate parameter descriptions without any Zod round-trip.
     */
    toAnthropicTools(): AnthropicToolDefinition[];
}
/**
 * Shape of a `tool_use` content block returned by Claude, limited to the
 * fields needed by the dispatcher.
 */
interface MCPToolUseBlock {
    type: "tool_use";
    id: string;
    name: string;
    input: unknown;
}
/**
 * Shape of the `tool_result` block returned to Claude.
 */
interface MCPToolResultBlock {
    type: "tool_result";
    tool_use_id: string;
    content: string;
    is_error?: boolean;
}
/**
 * Dispatches a single `tool_use` block targeting an MCP tool and returns a
 * `tool_result` block ready to append to the message thread.
 *
 * Handles MCP-reported errors (`isError: true` in the result) and
 * transport-level exceptions. Transport exceptions are caught and returned as
 * `is_error: true` tool_result blocks — matching the behaviour of the native
 * `dispatchToolUse` helper — so Claude can recover gracefully on the next turn.
 *
 * ```ts
 * if (bridge.hasMcpTool(block.name)) {
 *   const toolResult = await dispatchMcpToolUse(bridge, block);
 *   messages.push({ role: "user", content: [toolResult] });
 * }
 * ```
 */
declare function dispatchMcpToolUse(bridge: ToolRegistryBridge, block: MCPToolUseBlock): Promise<MCPToolResultBlock>;

/**
 * Thrown when an `MCPClient` method is called before `connect()` has
 * completed successfully.
 *
 * @example
 * ```ts
 * const client = new MCPClient(config);
 * // Calling listTools() before connect() throws:
 * await client.listTools(); // → MCPNotConnectedError
 * ```
 */
declare class MCPNotConnectedError extends Error {
    readonly clientName: string;
    constructor(clientName: string);
}
/**
 * Thrown when the MCP initialization handshake fails — transport could not
 * be established or the server rejected the client's hello.
 */
declare class MCPConnectionError extends Error {
    readonly clientName: string;
    constructor(clientName: string, message: string, options?: {
        cause?: unknown;
    });
}
/**
 * Thrown when a tool invocation fails at the transport or protocol level.
 *
 * Note: if the tool itself returns `isError: true` in its result, the
 * response is returned normally — no error is thrown. `MCPToolCallError`
 * only surfaces transport / RPC errors.
 */
declare class MCPToolCallError extends Error {
    readonly toolName: string;
    readonly clientName: string;
    constructor(toolName: string, clientName: string, message: string, options?: {
        cause?: unknown;
    });
}
/**
 * Thrown when a resource read fails at the transport or protocol level.
 */
declare class MCPResourceError extends Error {
    readonly uri: string;
    readonly clientName: string;
    constructor(uri: string, clientName: string, message: string, options?: {
        cause?: unknown;
    });
}

type index_HttpTransportConfig = HttpTransportConfig;
type index_MCPClient = MCPClient;
declare const index_MCPClient: typeof MCPClient;
type index_MCPClientConfig = MCPClientConfig;
type index_MCPConnectionError = MCPConnectionError;
declare const index_MCPConnectionError: typeof MCPConnectionError;
type index_MCPContent = MCPContent;
type index_MCPEmbeddedResource = MCPEmbeddedResource;
type index_MCPImageContent = MCPImageContent;
type index_MCPNotConnectedError = MCPNotConnectedError;
declare const index_MCPNotConnectedError: typeof MCPNotConnectedError;
type index_MCPPrompt = MCPPrompt;
type index_MCPPromptArgument = MCPPromptArgument;
type index_MCPReadResourceResult = MCPReadResourceResult;
type index_MCPResource = MCPResource;
type index_MCPResourceContent = MCPResourceContent;
type index_MCPResourceError = MCPResourceError;
declare const index_MCPResourceError: typeof MCPResourceError;
type index_MCPTextContent = MCPTextContent;
type index_MCPTool = MCPTool;
type index_MCPToolCallError = MCPToolCallError;
declare const index_MCPToolCallError: typeof MCPToolCallError;
type index_MCPToolCallResult = MCPToolCallResult;
type index_MCPToolResultBlock = MCPToolResultBlock;
type index_MCPToolUseBlock = MCPToolUseBlock;
type index_MCPTransportConfig = MCPTransportConfig;
type index_StdioTransportConfig = StdioTransportConfig;
type index_ToolRegistryBridge = ToolRegistryBridge;
declare const index_ToolRegistryBridge: typeof ToolRegistryBridge;
declare const index_dispatchMcpToolUse: typeof dispatchMcpToolUse;
declare namespace index {
  export { type index_HttpTransportConfig as HttpTransportConfig, index_MCPClient as MCPClient, type index_MCPClientConfig as MCPClientConfig, index_MCPConnectionError as MCPConnectionError, type index_MCPContent as MCPContent, type index_MCPEmbeddedResource as MCPEmbeddedResource, type index_MCPImageContent as MCPImageContent, index_MCPNotConnectedError as MCPNotConnectedError, type index_MCPPrompt as MCPPrompt, type index_MCPPromptArgument as MCPPromptArgument, type index_MCPReadResourceResult as MCPReadResourceResult, type index_MCPResource as MCPResource, type index_MCPResourceContent as MCPResourceContent, index_MCPResourceError as MCPResourceError, type index_MCPTextContent as MCPTextContent, type index_MCPTool as MCPTool, index_MCPToolCallError as MCPToolCallError, type index_MCPToolCallResult as MCPToolCallResult, type index_MCPToolResultBlock as MCPToolResultBlock, type index_MCPToolUseBlock as MCPToolUseBlock, type index_MCPTransportConfig as MCPTransportConfig, type index_StdioTransportConfig as StdioTransportConfig, index_ToolRegistryBridge as ToolRegistryBridge, index_dispatchMcpToolUse as dispatchMcpToolUse };
}

export { type HttpTransportConfig as H, MCPClient as M, type StdioTransportConfig as S, ToolRegistryBridge as T, type MCPClientConfig as a, MCPConnectionError as b, type MCPContent as c, type MCPEmbeddedResource as d, type MCPImageContent as e, MCPNotConnectedError as f, type MCPPrompt as g, type MCPPromptArgument as h, type MCPReadResourceResult as i, type MCPResource as j, type MCPResourceContent as k, MCPResourceError as l, type MCPTextContent as m, type MCPTool as n, MCPToolCallError as o, type MCPToolCallResult as p, type MCPToolResultBlock as q, type MCPToolUseBlock as r, type MCPTransportConfig as s, dispatchMcpToolUse as t, index as u };
