/**
 * A single live connection to one external Model Context Protocol server.
 *
 * {@link ServerEndpoint} (the interface) is declared in `./contract`; this module
 * is its one concrete implementation over the official MCP SDK {@link Client}.
 * An endpoint owns exactly one transport, advances through the
 * {@link EndpointPhase} machine, and translates every SDK / transport failure
 * into a discriminated {@link ProtocolFault} so callers branch on a cause class
 * rather than parse message text.
 *
 * Responsibilities, kept deliberately narrow:
 *
 *   - Build the right transport from a {@link ServerConfig} — a
 *     {@link StdioClientTransport} for `stdio`, an {@link SSEClientTransport}
 *     for `sse`.
 *   - Drive the lifecycle: `idle → connecting → ready`, with any failure short-
 *     circuiting to `faulted`; `ready → closing → closed` on a clean shutdown.
 *   - Cache the tool listing after the first successful `listTools()`.
 *   - Surface the raw {@link RemoteCallResult} of an invocation; mapping content
 *     blocks onto the kernel's tool contract is a sibling module's concern.
 */
import type { Transport } from "@modelcontextprotocol/sdk/shared/transport.js";
import type { EndpointPhase, EndpointStatus, RemoteCallResult, RemoteTool, ServerConfig, ServerEndpoint } from "./contract";
/**
 * One connection to one MCP server, over the official SDK {@link Client}.
 *
 * Construct with a {@link ServerConfig}; the transport is chosen from
 * {@link ServerConfig.kind} but not opened until {@link connect}. The endpoint
 * is single-shot: once it reaches a terminal phase (`closed` or `faulted`) it is
 * not reusable.
 */
export declare class ServerEndpointImpl implements ServerEndpoint {
    /** The configuration that defines this endpoint. */
    readonly config: ServerConfig;
    /** Backing field for the public {@link phase} accessor. */
    private _phase;
    /** The SDK client, created lazily on the first {@link connect}. */
    private client?;
    /** In-flight connection, shared by concurrent {@link connect} callers. */
    private opening?;
    /** Memoized tool listing, populated by the first successful {@link listTools}. */
    private toolCache?;
    /** The fault that retired this endpoint, set when {@link _phase} is `faulted`. */
    private fault?;
    /**
     * A pre-built transport injected at construction, used in place of one derived
     * from {@link config}. This is the seam in-process callers (and tests) use to
     * connect an endpoint to a transport they already hold — an
     * {@link InMemoryTransport} client half, say — instead of spawning a process or
     * opening a socket. When present, {@link buildTransport} is bypassed entirely.
     */
    private readonly injectedTransport?;
    constructor(config: ServerConfig, transport?: Transport);
    /** A stable handle for logs and status keys: the server's configured id. */
    get id(): string;
    /** The endpoint's current lifecycle phase. */
    get phase(): EndpointPhase;
    /**
     * Open the transport and initialize the MCP session.
     *
     * Idempotent: a second call while a connection is in flight awaits the same
     * attempt, and a call on an already-`ready` endpoint resolves immediately. A
     * call on a terminal (`closed` / `faulted`) endpoint rejects, since the
     * transport cannot be revived.
     */
    connect(): Promise<void>;
    /**
     * The {@link ServerEndpoint} interface's name for {@link connect}; delegates
     * verbatim so the contract's vocabulary and the prompt's `connect()` both
     * resolve to one implementation.
     */
    open(): Promise<void>;
    /** The single-flight body behind {@link connect}. */
    private doConnect;
    /** Construct the transport implied by {@link ServerConfig.kind}. */
    private buildTransport;
    /**
     * List the tools this server advertises, mapped to {@link RemoteTool}s and
     * cached. The first call performs the round-trip; later calls return the
     * memoized listing. Requires a `ready` endpoint.
     */
    listTools(): Promise<readonly RemoteTool[]>;
    /** A point-in-time projection of this endpoint's tool cache. */
    tools(): readonly RemoteTool[];
    /**
     * Invoke a remote tool by its *unqualified* server-side name. Returns the raw
     * {@link RemoteCallResult}; a result the server flagged `isError` is reported
     * faithfully (`isError: true`) rather than thrown — that is the model's signal,
     * not a transport fault. A genuine transport/protocol failure throws a
     * {@link ProtocolFault}. Requires a `ready` endpoint.
     */
    invoke(name: string, args: unknown): Promise<RemoteCallResult>;
    /** A point-in-time projection of this endpoint's health. */
    status(): EndpointStatus;
    /**
     * Gracefully close the transport. Idempotent and safe in any phase: a never-
     * connected, already-closed, or faulted endpoint closes to a no-op without
     * overwriting a `faulted` terminal state. A close error is swallowed — there
     * is nothing left to do with the connection — but still moves the phase to
     * `closed`.
     */
    close(): Promise<void>;
    /** Return the live client or throw a `not_connected` fault. */
    private requireClient;
    /**
     * Record a fault, transition to `faulted`, and return the {@link ProtocolFault}
     * for the caller to throw. Centralizing this keeps the phase and the stored
     * fault consistent at every failure site.
     */
    private faultFrom;
    /** Coerce an SDK tool input schema into the gateway's {@link JsonSchema}. */
    private normalizeSchema;
    /** The SDK expects a record of arguments; map anything else to an empty one. */
    private normalizeArgs;
}
/**
 * Construct a {@link ServerEndpoint} for one server.
 *
 * Pass a pre-built `transport` to connect over a transport the caller already
 * holds — an in-process {@link InMemoryTransport} client half, for instance —
 * rather than one derived from `config`. Omit it for the normal path, where the
 * endpoint builds the transport implied by `config.kind` on connect.
 */
export declare function createServerEndpoint(config: ServerConfig, transport?: Transport): ServerEndpointImpl;
