/** * Navidrome MCP Server - Port-as-lock acquire/attach * Copyright (C) 2025 * SPDX-License-Identifier: AGPL-3.0-or-later */ import type { Server } from 'node:http'; import type { Config } from '../config.js'; /** * The configured TCP port is the lock. The process that binds it owns the web server, and every * later process confirms the owner through `/healthz` and attaches. */ export type AcquireResult = { mode: 'owner'; url: string; server: Server; } | { mode: 'attached'; url: string; }; /** * `foreign` covers every answer other than our signature or ECONNREFUSED, so a hung listener * counts as a port conflict and never blocks startup. */ export type ProbeOutcome = 'ours' | 'refused' | 'foreign'; export type WebEndpoint = Pick; /** `lan` is whether the owner's bind accepts LAN connections. An owner older than the field leaves it out. */ interface HealthAnswer { outcome: ProbeOutcome; lan?: boolean; } /** `secure` is the scheme the owner answered on, or the preferred one when no owner answered. */ interface OwnerAnswer extends HealthAnswer { secure: boolean; } /** `port` and `secure` are the endpoint whose answer decided the outcome. */ export interface WebOwnerProbe extends OwnerAnswer { port: number; } export interface AcquireDeps { probe: (port: number, bindHost: string, preferSecure: boolean) => Promise; bind: (server: Server, port: number, host: string) => Promise<'ok' | 'eaddrinuse'>; } export declare function probeHealthz(port: number, bindHost: string, secure: boolean): Promise; /** * A running player fixed its scheme at its own start, and settings.json may have gained or lost the * TLS pair since, so a foreign answer on the preferred scheme is retried on the other one. */ export declare function probeOwner(port: number, bindHost: string, preferSecure: boolean): Promise; /** * The MCP keeps its startup endpoint, but a spawned or re-run web player binds the endpoint that * settings.json holds now, so the saved endpoint is probed second. */ export declare function probeWebOwner(startup: WebEndpoint, readSaved: () => WebEndpoint | null): Promise; /** The MCP teardown path keys off this, since the owner quits mpv whether or not it is attached. */ export declare function webOwnerPresent(startup: WebEndpoint, readSaved: () => WebEndpoint | null): Promise; export declare function portConflictMessage(port: number): string; /** `makeServer` runs only when a bind is attempted, so an attaching process builds no server. */ export declare function acquireOrAttach(config: Config, makeServer: () => Server, deps?: AcquireDeps): Promise; export {}; //# sourceMappingURL=acquire.d.ts.map