/** * CLI Server Management Functions * Handles start, stop, status, restart operations */ interface ServerOptions { port: number; host: string; configPath?: string; } interface McpServerStatus { name: string; type: string; displayName?: string; tags?: Record; connected: boolean; toolsCount: number; resourcesCount: number; error?: string; } export interface SessionInfo { sessionId: string; clientName?: string; clientVersion?: string; protocolVersion?: string; createdAt: string; lastAccessedAt: string; activeSseCount: number; } export interface EnhancedServerStatus { running: boolean; pid?: string; host: string; port: number; message?: string; pidFilePath: string; mcpServers?: McpServerStatus[]; sessions?: SessionInfo[]; } /** * Starts the MCP Hub Lite server with the specified configuration options. * * This function initializes and starts the full MCP Hub Lite server, including: * - Fastify HTTP server with web interface and API * - Automatic connection to enabled MCP servers * - Port conflict detection * - Graceful shutdown handlers * - PID file management * * After successful startup, the process ID is written to a PID file for * process management and monitoring purposes. * * Note: The `configPath` option is accepted for API consistency but is not * currently used by this function. Configuration loading is handled by the * ConfigManager singleton during module initialization. * * @param {ServerOptions} options - Configuration options for server startup * @param {number} options.port - The port number to listen on (e.g., 7788) * @param {string} options.host - The host address to bind to (e.g., 'localhost', '0.0.0.0') * @param {string} [options.configPath] - Optional path to custom configuration file (currently unused) * @returns {Promise} A promise that resolves when the server is successfully started * @throws {Error} If the server fails to start due to port conflicts, permission issues, or configuration errors * * @example * ```typescript * await startServer({ * port: 7788, * host: 'localhost' * }); * console.log(`Server running on http://localhost:7788`); * ``` * * @see {@link runServer} for the full server startup implementation * @see {@link PidManager} for process ID management */ export declare function startServer(options: ServerOptions): Promise; /** * Stops the MCP Hub Lite server gracefully by sending a termination signal. * * This function terminates the running server process by: * - Reading the PID from the PID file (or using provided PID) * - Sending SIGTERM signal to gracefully terminate the process * - Cleaning up the PID file to prevent stale process detection * * If no PID is provided, it reads from the PID file managed by PidManager. * If the PID file doesn't exist or the process is already terminated, * the function handles this gracefully without throwing errors. * * @param pid - Optional specific process ID to stop. If not provided, uses PID from PID file. * @returns {Promise} Resolves when the stop operation completes (regardless of success/failure) * * @example * ```typescript * // Stop the currently running server * await stopServer(); * * // Stop a specific process ID * await stopServer('12345'); * ``` */ export declare function stopServer(pid?: string): Promise; /** * Retrieves the current status of the MCP Hub Lite server. * * This function checks if the server is running by: * - Reading the PID from the PID file (or using provided PID) * - Verifying if the process with that PID is still active * - If running, attempts to fetch additional runtime status via HTTP API * - Returns enhanced status with configuration and runtime information * * The function uses `process.kill(pid, 0)` which doesn't actually kill the process * but checks if a process with the given PID exists and is accessible. * * @param pid - Optional specific process ID to check. If not provided, uses PID from PID file. * @returns {Promise} Enhanced status object with full details * * @example * ```typescript * const status = await getServerStatus(); * if (status.running) { * console.log(`Server running on ${status.host}:${status.port} with PID ${status.pid}`); * } * ``` */ export declare function getServerStatus(pid?: string): Promise; /** * Restarts the MCP Hub Lite server with the same configuration options. * * This function performs a graceful restart by: * - First stopping the currently running server (if any) * - Then starting a new server instance with the provided options * * This is useful for applying configuration changes or recovering from * transient issues without manual intervention. * * @param options - Configuration options for the new server instance * @param {number} options.port - The port number to listen on * @param {string} options.host - The host address to bind to * @param {string} [options.configPath] - Optional path to custom configuration file * @returns {Promise} A promise that resolves when the server is successfully restarted * * @example * ```typescript * await restartServer({ * port: 7788, * host: 'localhost' * }); * ``` */ export declare function restartServer(options: ServerOptions): Promise; /** * Lists all configured MCP servers with their instances. * * This function retrieves all servers managed by the HubManager and * enriches them with their associated instances (if any). Each server * object includes its configuration and an array of active instances. * * This is primarily used by the CLI `list` command to display the * current server configuration to users. * * @returns {Promise} Array of server objects with instances included * * @example * ```typescript * const servers = await listServers(); * servers.forEach(server => { * console.log(`Server: ${server.name}`); * console.log(`Instances: ${server.instances.length}`); * }); * ``` */ export declare function listServers(): Promise<{ instances: { id: string; enabled: boolean; args: string[]; env: Record; headers: Record; tags: Record; index?: number | undefined; displayName?: string | undefined; timestamp?: number | undefined; pid?: number | undefined; startTime?: number | undefined; proxy?: { url: string; } | undefined; }[]; name: string; config: import("../config/config-manager.js").ServerConfig; }[]>; /** * Options for installing a new MCP server. */ export interface InstallServerOptions { name: string; command?: string; url?: string; transport: 'stdio' | 'sse' | 'streamable-http'; args?: string[]; env?: Record; headers?: Record; timeout: number; autoStart: boolean; instanceSelectionStrategy: 'random' | 'round-robin' | 'tag-match-unique'; description?: string; } /** * Installs a new MCP server via the web API. * * This function sends a POST request to the /web/servers endpoint to add a new * server configuration. If the instance selection strategy is not 'random', it * sends an additional PUT request to update the strategy. * * @param options - Server installation options * @param host - Server host address * @param port - Server port number * @returns Promise that resolves when installation completes * @throws Error if the server already exists or the API request fails * * @example * ```typescript * await installServer({ * name: 'github-mcp', * command: 'npx github-mcp', * transport: 'stdio', * env: { API_KEY: 'xxx' }, * timeout: 60, * autoStart: true, * instanceSelectionStrategy: 'random' * }, 'localhost', 7788); * ``` */ export declare function installServer(options: InstallServerOptions, host: string, port: number): Promise; /** * Parses environment variable flags into a key-value object. * * @param envFlags - Array of environment variables in KEY=VALUE format * @returns Record of environment variable key-value pairs * @throws Error if the format is invalid * * @example * ```typescript * parseEnvVars(['API_KEY=xxx', 'DEBUG=true']) * // Returns: { API_KEY: 'xxx', DEBUG: 'true' } * ``` */ export declare function parseEnvVars(envFlags: string[]): Record; /** * Parses HTTP header flags into a key-value object. * * @param headerFlags - Array of headers in "Key: Value" format * @returns Record of header key-value pairs * @throws Error if the format is invalid * * @example * ```typescript * parseHeaders(['Authorization: Bearer xxx', 'Content-Type: application/json']) * // Returns: { Authorization: 'Bearer xxx', 'Content-Type': 'application/json' } * ``` */ export declare function parseHeaders(headerFlags: string[]): Record; export {}; //# sourceMappingURL=server.d.ts.map