/**
 * MCP stdio transport.
 *
 * Implements JSON-RPC 2.0 over subprocess stdin/stdout.
 * Messages are newline-delimited JSON.
 */
import type { MCPRequestOptions, MCPStdioServerConfig, MCPTransport } from "../../mcp/types.js";
/** Subprocess argv and platform-derived spawn flags for an MCP stdio server. */
export interface StdioSpawnCommand {
    cmd: string[];
    /**
     * Hide the Windows console window for the direct child.
     *
     * Windows uses this only when the OMP host has no console to share. When
     * the host is running inside a terminal, `windowsHide: true` maps to
     * `CREATE_NO_WINDOW`, which strips that inheritable console from hidden
     * `cmd.exe` / PowerShell wrapper chains. Their console grandchildren then
     * allocate fresh visible conhost windows during startup or reconnects
     * (#3567).
     */
    windowsHide?: boolean;
    /**
     * Run the subprocess in its own session.
     *
     * POSIX: `true`. Detach → `setsid`, so the MCP process tree has no
     * controlling terminal and terminal job-control signals (Ctrl+Z SIGTSTP,
     * background-read SIGTTIN) cannot stop stdio servers such as
     * `chrome-devtools-mcp` and leave our read loop blocked on silent pipes.
     *
     * Windows: `false`. There is no SIGTSTP/SIGTTIN to escape, and Windows
     * wrapper chains must stay in the OMP console session so nested console
     * grandchildren keep stdout routed through our pipe (#3544).
     */
    detached: boolean;
}
/** Inputs used to resolve platform-specific stdio spawn behavior. */
export interface ResolveStdioSpawnOptions {
    cwd: string;
    env: Record<string, string | undefined>;
    hostHasInheritableConsole?: boolean;
    platform?: NodeJS.Platform;
}
/**
 * Resolve the subprocess argv used to launch an MCP stdio server.
 *
 * On Windows, our PATH/PATHEXT walk may return `null` for a bare command
 * (e.g. `npx`) — `Bun.env.PATH` empty under a restricted parent process,
 * UNC/network mounts that reject `fs.access`, locked-down shells. The
 * legacy fallback handed `Bun.spawn` the bare name, but `CreateProcess`
 * only appends `.exe` for extensionless names — `.cmd`/`.bat` are never
 * tried, so `npx` (which exists only as `npx.cmd` on Windows) crashes the
 * subprocess immediately. When the resolver can't pin the command down,
 * route through `cmd.exe /d /s /c` so Windows's own PATHEXT lookup runs.
 */
export declare function resolveStdioSpawnCommand(config: MCPStdioServerConfig, options: ResolveStdioSpawnOptions): Promise<StdioSpawnCommand>;
/** Minimal write surface of `Subprocess.stdin` we need for framed sends. */
interface FrameSink {
    write(chunk: string): unknown;
    flush(): unknown;
}
/**
 * Write a newline-delimited JSON-RPC frame to the subprocess's stdin sink,
 * swallowing both synchronous throws and asynchronous rejections so the caller
 * can decide how to react.
 *
 * Bun's `FileSink.write()`/`flush()` can fail two ways once the read end of the
 * pipe has been closed by a subprocess that exited between read-loop ticks:
 *   - a synchronous throw (most reliably observed on Windows), and
 *   - a *rejected Promise* returned from `write()`/`flush()`, i.e. the EPIPE is
 *     surfaced asynchronously (note the `processTicksAndRejections` frame in the
 *     stack traces on #1710 and the follow-up report).
 *
 * A sibling `async` method's `try/catch` only catches the synchronous case; an
 * un-awaited rejected Promise escapes as a fatal unhandled rejection. So we both
 * catch the throw and neutralize any returned promise's rejection.
 *
 * Returns `true` when the frame was accepted synchronously, `false` when the
 * sink threw — callers signal transport closure on `false`. An asynchronous
 * failure cannot be reflected in the return value; it is neutralized here and
 * the dead transport is detected by the read loop / request timeout instead.
 */
export declare function writeFrame(stdin: FrameSink, frame: string): boolean;
/**
 * Stdio transport for MCP servers.
 * Spawns a subprocess and communicates via stdin/stdout.
 */
export declare class StdioTransport implements MCPTransport {
    #private;
    private config;
    onClose?: () => void;
    onError?: (error: Error) => void;
    onNotification?: (method: string, params: unknown) => void;
    onRequest?: (method: string, params: unknown) => Promise<unknown>;
    constructor(config: MCPStdioServerConfig);
    get connected(): boolean;
    /**
     * Start the subprocess and begin reading.
     */
    connect(): Promise<void>;
    request<T = unknown>(method: string, params?: Record<string, unknown>, options?: MCPRequestOptions): Promise<T>;
    notify(method: string, params?: Record<string, unknown>): Promise<void>;
    close(): Promise<void>;
}
/**
 * Create and connect a stdio transport.
 */
export declare function createStdioTransport(config: MCPStdioServerConfig): Promise<StdioTransport>;
export {};
