/** * Setup Routes — Auto-install DollhouseMCP to MCP clients * * Uses `install-mcp` (https://github.com/supermemoryai/install-mcp) * to inject server configuration into supported MCP client config files. * * Security: localhost-only binding (enforced by server.ts), rate-limited, * and command arguments are hardcoded — no user-supplied shell input. */ import type { Request, Response } from 'express'; import { type InstallPermissionHookResult, type PermissionHookStatus } from '../../utils/permissionHooks.js'; /** * Create setup handlers (Express 5 compatible — plain handler functions, not Router). */ interface DetectResult { installed: boolean; configPath: string | null; currentConfig?: Record; serverKey?: string; } /** * Parse a TOML config file for a DollhouseMCP server entry. * * Detection prefers the canonical lowercase Codex section name first, then * falls back to older Dollhouse-related section names so stale configs are * still visible in the UI instead of being mistaken for a fresh install. */ export declare function parseTomlConfig(raw: string): Omit; export declare function createSetupRoutes(opts?: { /** Override install-mcp runner. For testing only — prefix signals test-only use. */ _runInstallMcp?: (client: string, version?: string) => Promise; /** Override permission hook installer. For testing only. */ _installPermissionHook?: (client: string) => Promise; /** Override permission hook status reconciler. For testing only. */ _reconcilePermissionHookStatus?: (client: string) => Promise; /** * Override the NVM launcher mitigation applied after a successful install. * For testing only. Without this seam the install handler runs the real * applyNvmLauncherIfNeeded against the real homedir(); on a machine WITH NVM * that patches the developer's real client configs (issue #2338). */ _applyNvmLauncher?: (client: string) => Promise; /** Enable automatic hook asset repair during detect. Defaults off in tests. */ _autoRepairPermissionHooksOnDetect?: boolean; /** Skip the sliding-window rate limiter. For testing only. */ _skipRateLimit?: boolean; }): { installHandler: (req: Request, res: Response) => Promise; openConfigHandler: (req: Request, res: Response) => Promise; versionHandler: (req: Request, res: Response) => Promise; mcpbRedirectHandler: (req: Request, res: Response) => Promise; detectHandler: (req: Request, res: Response) => Promise; getLicenseHandler: (req: Request, res: Response) => Promise; setLicenseHandler: (req: Request, res: Response) => Promise; verifyLicenseHandler: (req: Request, res: Response) => Promise; resendVerificationHandler: (req: Request, res: Response) => Promise; }; /** Result of attempting to apply the NVM launcher mitigation. */ export type NvmLauncherResult = 'applied' | 'not-applicable' | 'failed'; /** * Orchestrates the NVM mitigation: detect → create launcher → patch config → telemetry. * Extracted from installHandler to keep its cognitive complexity within SonarCloud limits. * Returns a result enum rather than throwing so the caller always gets a clean signal. * * @param home - Override home directory (injectable for tests) */ export declare function applyNvmLauncherIfNeeded(client: string, home?: string): Promise; /** * Startup repair + self-heal: reconciles every known JSON-format client config * on each server start. Behaviour depends on whether NVM is installed, matching * the acceptance matrix in https://github.com/DollhouseMCP/mcp-server/issues/2338: * * • NVM present → (re)create the wrapper and point each config at it. Covers a * deleted wrapper, a pre-fix install still on bare `npx`, and a config left * pointing at a dead temp-dir wrapper (regenerates the real one). Healthy * configs re-serialise byte-identically, so this is a no-op for them. * • NVM absent → never create a wrapper, but SELF-HEAL any config whose * command points at a `dollhousemcp-nvm.sh` that no longer exists (e.g. the * #2338 test leak, or a user who removed ~/.dollhouse/bin) back to bare `npx`, * preserving args so the client can launch DollhouseMCP again. * * Fire-and-forget from startWebServer. All errors are swallowed and logged. * * @param home - Override home directory (injectable for tests) * @param configPathResolver - Override config path lookup (injectable for tests). * Return null to skip a client entirely. Defaults to a * home-derived resolver so `home` stays authoritative * — the default must NOT reach the real homedir() when * a fake home is supplied (#2338). */ export declare function repairNvmLauncherOnStartup(home?: string, configPathResolver?: (client: string) => string | null): Promise; /** * Returns true if NVM is installed on this machine (macOS/Linux only). * Checks process.env.NVM_DIR first (handles non-standard install locations), * then falls back to ~/.nvm. * * @param home - Override home directory (defaults to os.homedir(); injectable for tests) */ export declare function isNvmPresent(home?: string): Promise; /** * Creates ~/.dollhouse/bin/dollhousemcp-nvm.sh and returns its path. * * The NVM directory is resolved at generation time and hardcoded into the * script. This is intentional: Claude Desktop does not source the user's * shell profile, so $NVM_DIR would be unset when the wrapper runs. By * embedding the absolute path we guarantee the correct NVM is found. * * The script sources NVM, then checks the active Node major version. If it * is below 18 (the DollhouseMCP minimum), it tries `nvm use node` (highest * installed) then `nvm use --lts` as a fallback. A final version check * writes a warning to stderr if the node is still too old — that warning * will appear in Claude Desktop's error log. * * @param home - Override home directory (injectable for tests) * @param nvmDirOverride - Override the resolved NVM path (injectable for tests) */ export declare function ensureNvmLauncher(home?: string, nvmDirOverride?: string): Promise; /** * Patches the dollhousemcp entry in an MCP client's JSON config to use * the NVM-aware launcher instead of bare `npx`. * * Only acts on JSON-format configs. TOML configs (codex) are skipped. * Silently no-ops if the config file is missing or unreadable. * * @param configPathOverride - Use this path instead of the platform default (injectable for tests) */ export declare function patchConfigForNvmLauncher(client: string, wrapperPath: string, configPathOverride?: string): Promise; export declare function installJsonMcpClientConfig(client: string, version?: string, configPathOverride?: string): Promise; export {}; //# sourceMappingURL=setupRoutes.d.ts.map