/** * Problem: * When an upstream process hangs or panics and is recycled, resending client `mcpServers` * with stale ephemeral localhost ports fails because proxy endpoints have moved or closed. * * Solution: * Establishes a dynamic loopback MCP proxy pool that intercepts outbound `mcpServers` URLs, * remaps ephemeral ports to stable virtual endpoints, and rewrites headers across process restarts. */ import { type AcpFix, type CachedSessionMetadata, type UrlRewriter } from "../../core/types.js"; /** * Protocol versions the target MCP server understands. Standard MCP servers embed * `@modelcontextprotocol/sdk`, whose streamable-HTTP transport rejects any request * carrying an `MCP-Protocol-Version` header outside this list with HTTP 400. */ export declare const DEFAULT_SUPPORTED_PROTOCOL_VERSIONS: readonly ["2025-11-25", "2025-06-18", "2025-03-26", "2024-11-05", "2024-10-07"]; export interface McpProxyOptions { /** Versions the upstream accepts. Anything else is rewritten to `fallbackProtocolVersion`. */ supportedProtocolVersions?: readonly string[]; /** Version substituted when the client asks for one the upstream does not support. */ fallbackProtocolVersion?: string; /** * File used to remember the listening port across restarts. Antigravity persists the * MCP server URL into its per-session SQLite database, so a session resumed after a * daemon restart still points at whatever port we used when it was created. */ portFile?: string | null; } /** * A loopback reverse proxy for a single upstream MCP origin. * * Google's `agy_acp_server` ships an MCP client that advertises protocol version * `2026-07-28`, which standard MCP daemons reject with HTTP 400 on every request after * `initialize`. This proxy normalizes that header down to a version the upstream * accepts, turning a hard transport failure into ordinary version negotiation. * * It is origin-bound and forwards the request path and query verbatim, so * `?callerAgentId=...` survives and the client's OAuth discovery probes * (`/.well-known/oauth-protected-resource/...`) reach the real upstream path * instead of being collapsed onto the MCP endpoint. */ export declare class McpProxyServer { private server; private port; private readonly origin; private readonly supportedProtocolVersions; private readonly fallbackProtocolVersion; private readonly portFile; constructor(origin: string, options?: McpProxyOptions); private buildForwardHeaders; private handleProxyResponse; private forwardRequest; /** * Buffering the request body in memory is safe and necessary because MCP JSON-RPC * messages are small (typically <1MB) and buffering allows us to inspect for * notifications (missing `id`) before forwarding or deciding whether to absorb 4xx * responses, while also enabling re-streaming the body to upstream. */ private handleRequest; private listen; /** * Starts the proxy on 127.0.0.1, preferring the port used on the previous run so * that URLs Antigravity persisted for existing sessions keep resolving. */ start(): Promise; getPort(): number | null; /** * Rewrites an upstream MCP URL to route through this proxy, preserving path and query. * * Throws when the proxy is not listening. Returning the original URL here would * silently hand Antigravity a direct upstream connection with no header * normalization, which is exactly the failure this class exists to prevent. */ rewriteUrl(originalUrl: string): string; stop(): Promise; } /** Backward compatibility alias */ export { McpProxyServer as McpProxy }; /** * Process-wide pool of proxies keyed by upstream origin. * * Proxies deliberately outlive individual agent connections: Antigravity writes the * rewritten URL into its session database, so tearing a proxy down when one stream * ends would leave every resumed session pointing at a dead port. */ export declare class McpProxyPool { private readonly proxies; private readonly options; constructor(options?: McpProxyOptions); rewriteUrl(originalUrl: string): Promise; stopAll(): Promise; } /** Shared pool. One proxy per upstream origin for the lifetime of the daemon process. */ export declare const sharedMcpProxyPool: McpProxyPool; export interface McpHeader { name: string; value: string; } export declare function normalizeMcpHeaders(headers: unknown): McpHeader[] | undefined; export declare const MCP_SERVERS_KEY = "mcpServers"; export declare const MCP_SERVERS_ORIGINAL_KEY = "mcpServersOriginal"; export declare function getSessionMcpServers(session: CachedSessionMetadata): unknown[] | undefined; export declare function setSessionMcpServers(session: CachedSessionMetadata, servers: unknown[]): void; export declare function getSessionMcpServersOriginal(session: CachedSessionMetadata): unknown[] | undefined; export declare function setSessionMcpServersOriginal(session: CachedSessionMetadata, servers: unknown[]): void; export declare function rewriteMcpServers(servers: unknown[], proxies?: UrlRewriter): Promise; export declare const staleMcpEndpointsFix: AcpFix; export declare const mcpPortRemappingFix: AcpFix; //# sourceMappingURL=index.d.ts.map