import { Server } from '@modelcontextprotocol/sdk/server/index.js'; import type { Transport } from '@modelcontextprotocol/sdk/shared/transport.js'; import type { PluginMcpServer } from '../types.js'; import type { TrustedCaller } from '../../../types.js'; export declare function resolveGatewayEnvironment(env?: NodeJS.ProcessEnv, startPid?: number): NodeJS.ProcessEnv; export interface GatewayTrustedTurnIdentity { caller?: TrustedCaller; turnId?: string; dispatchAttempt?: number; } export type GatewayTrustedTurnIdentityProvider = () => GatewayTrustedTurnIdentity | undefined; export interface McpGatewayDiagnostic { pluginId: string; serverName: string; status: 'connected' | 'failed'; transport: PluginMcpServer['transport']; error?: string; tools?: number; prompts?: number; resources?: number; } export interface McpGatewayDiagnosticsFile { schemaVersion: 1; sessionId?: string; pluginIds: string[]; generatedAt: string; servers: McpGatewayDiagnostic[]; } interface GatewayInputLifecycle { readonly readableEnded?: boolean; readonly destroyed?: boolean; once(event: 'end' | 'close', listener: () => void): unknown; } export declare function bindGatewayInputLifecycle(input: GatewayInputLifecycle, closeGateway: () => Promise, onError?: (error: unknown) => void): () => Promise; export declare class PluginMcpGateway { readonly server: Server; private readonly env; private readonly trustedTurnIdentity?; private readonly pluginIds; private readonly descriptors; private readonly diagnostics; private connections; private initializePromise?; private toolRoutes; private promptRoutes; private resourceRoutes; private resourceTemplateRoutes; constructor(pluginIds?: string[], env?: NodeJS.ProcessEnv, opts?: { trustedTurnIdentity?: GatewayTrustedTurnIdentityProvider; }); connect(transport: Transport): Promise; close(): Promise; private closeDownstreams; private persistDiagnostics; private ensureInitialized; private initializeDownstreams; private connectDownstream; private registerReverseHandlers; private requestOptions; private trustedTurnMeta; private withTrustedTurnMeta; private httpHeaders; private capable; private refreshTools; private refreshPrompts; private refreshResources; private mapDownstreamUri; private resolveResourceRoute; private registerHandlers; } export declare function runMcpGateway(): Promise; /** Newline-framed stdio relay from a CLI-native MCP launcher to the trusted * worker-side Gateway that SURVIVES host replacement. No plugin metadata or * credentials are loaded here. * * Why not a byte pipe: the worker-side Gateway host dies with the worker on * every daemon restart/upgrade, and the CLI process (in a persistent tmux/zmx * pane) lives on with this relay as its MCP server. A single-shot pipe forced * the worker to kill the surviving pane ("cold-resume") just to refresh the * MCP plumbing — interrupting whatever turn the CLI was executing. Instead the * relay: * 1. frames both directions as newline-delimited JSON (the MCP stdio * framing), buffering client lines while the Gateway is unreachable; * 2. reconnects to the SAME deterministic socket path with backoff, re-reads * the rotated auth token per attempt; * 3. replays the captured `initialize` request + `notifications/initialized` * on the fresh Gateway connection (each host connection is a brand-new * MCP server that expects the handshake), swallowing the replayed * response iff the client already saw the original one — the client * never re-initializes and must not receive a duplicate response id. * Requests in flight across a disconnect lose their responses; the client's * own MCP timeout surfaces those as failed tool calls, which is the honest * outcome. */ export declare function runReconnectingMcpRelay(socketPath: string, opts?: { input?: NodeJS.ReadableStream; output?: NodeJS.WritableStream; env?: NodeJS.ProcessEnv; }): Promise; export {}; //# sourceMappingURL=gateway.d.ts.map