import type { AgentRunner } from "@automatalabs/shared-types"; import type { Transport } from "@modelcontextprotocol/server"; /** The maximum time reserved for graceful ACP process teardown before exit is forced. */ export declare const SHUTDOWN_DEADLINE_MS = 5000; export type McpServerShutdownReason = "stdin-close" | "stdin-end" | "transport-close" | "SIGINT" | "SIGTERM"; /** A small server-owned admission gate, kept separate from the MCP transport lifecycle. */ export interface WorkflowServerControl { stopAcceptingWork(): void; /** Release state the serving entry shares across server instances (event subscriptions, the * permission broker). Runs once at shutdown, after the runner is disposed. OPTIONAL: a server * that owns nothing of the kind omits it. */ dispose?(): Promise; } interface ShutdownProcess { stdin: { once(event: "close" | "end", listener: () => void): unknown; removeListener(event: "close" | "end", listener: () => void): unknown; }; once(event: "SIGINT" | "SIGTERM", listener: () => void): unknown; removeListener(event: "SIGINT" | "SIGTERM", listener: () => void): unknown; exit(code?: number): unknown; } export interface McpServerLifecycleOptions { runner: AgentRunner; server: WorkflowServerControl; transport: Transport; process?: ShutdownProcess; deadlineMs?: number; } export interface McpServerLifecycle { shutdown(reason: McpServerShutdownReason): Promise; isShuttingDown(): boolean; } /** * Dispose the concrete ACP runner (and therefore every pooled backend process), racing a hard * deadline. At the deadline the runner's synchronous force-kill path is invoked so a slow * backend shutdown cannot orphan its process tree. Disposal errors are contained: the returned * promise always resolves. */ export declare function disposeRunnerWithDeadline(runner: AgentRunner, deadlineMs?: number): Promise; /** * Own the stdio server's process lifetime. The first termination trigger closes the workflow * admission gate, disposes the concrete ACP runner (and therefore every pooled backend process), * then exits. Disposal errors are intentionally contained: process exit remains guaranteed. */ export declare function installMcpServerLifecycle(options: McpServerLifecycleOptions): McpServerLifecycle; export {}; //# sourceMappingURL=lifecycle.d.ts.map