import type { McpAuthInfo } from './auth.js';
/** `config/mcp.ts` → `sessions`: how many MCP sessions an endpoint keeps, and for how long. */
export interface McpSessionLimits {
    /** Live sessions per endpoint, all callers together. Past it, `initialize` answers `503`. Default 1000. */
    max?: number;
    /**
     * Live sessions per caller (one token's client and actor). Past it, that caller's least recently
     * used session is closed to make room, so a client that never closes its sessions bounds itself
     * without locking itself out. Default 16.
     */
    maxPerPrincipal?: number;
    /** A session nobody used for this long (ms) is closed. Default 30 minutes. */
    idleTimeoutMs?: number;
}
export declare const DEFAULT_MCP_SESSION_LIMITS: Required<McpSessionLimits>;
/** Validates and fills {@link McpSessionLimits}; throws naming the bad field. */
export declare function resolveMcpSessionLimits(limits: McpSessionLimits | undefined): Required<McpSessionLimits>;
/**
 * Who a session belongs to: the token's client and the actor it resolved. A session id is a bearer
 * capability on its own, so every later request on it must come from the same principal.
 */
export declare function mcpPrincipalOf(auth: McpAuthInfo): string;
/** What the pool needs of a transport: closing it (its `onclose` then calls {@link McpSessionPool.delete}). */
export interface ClosableTransport {
    close(): Promise<void>;
}
/** Why a session lookup or a new session was refused. */
export type McpSessionRefusal = 'unknown' | 'other-principal' | 'full';
/**
 * The live sessions of one MCP endpoint: bound to the principal that opened them, capped per
 * principal and overall, and closed after `idleTimeoutMs` without use. In memory, per process.
 */
export declare class McpSessionPool<T extends ClosableTransport> {
    #private;
    readonly limits: Required<McpSessionLimits>;
    constructor(limits?: McpSessionLimits, options?: {
        now?: () => number;
    });
    get size(): number;
    /** Sessions held by `principal`. */
    countOf(principal: string): number;
    /**
     * The session's transport, for its own principal only (and marked used). `other-principal` when
     * the id is live but was opened by someone else.
     */
    get(sessionId: string, principal: string): T | McpSessionRefusal;
    /**
     * Make room for a new session of `principal` and register it under `sessionId`: idle sessions go
     * first, then the principal's least recently used one when it is at its cap. `full` when every
     * slot of the endpoint is held by live sessions.
     */
    open(sessionId: string, principal: string, transport: T): true | 'full';
    /** Forget `sessionId` (when it still holds `transport`): the transport closed. */
    delete(sessionId: string, transport?: T): void;
    /** Close every session idle past `idleTimeoutMs`. */
    sweep(): void;
    /** Sweep on a timer (unref'd: it never keeps the process alive). */
    startSweeping(): void;
    /** Stop the timer and close every session. */
    closeAll(): Promise<void>;
}
//# sourceMappingURL=session-pool.d.ts.map