UNPKG

@dollhousemcp/mcp-server

Version:

DollhouseMCP - A Model Context Protocol (MCP) server that enables dynamic AI persona management from markdown files, allowing Claude and other compatible AI assistants to activate and switch between different behavioral personas.

114 lines 6.07 kB
/** * 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<string, unknown>; 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<DetectResult, 'configPath'>; export declare function createSetupRoutes(opts?: { /** Override install-mcp runner. For testing only — prefix signals test-only use. */ _runInstallMcp?: (client: string, version?: string) => Promise<string>; /** Override permission hook installer. For testing only. */ _installPermissionHook?: (client: string) => Promise<InstallPermissionHookResult>; /** Override permission hook status reconciler. For testing only. */ _reconcilePermissionHookStatus?: (client: string) => Promise<PermissionHookStatus>; /** 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<void>; openConfigHandler: (req: Request, res: Response) => Promise<void>; versionHandler: (req: Request, res: Response) => Promise<void>; mcpbRedirectHandler: (req: Request, res: Response) => Promise<void>; detectHandler: (req: Request, res: Response) => Promise<void>; getLicenseHandler: (req: Request, res: Response) => Promise<void>; setLicenseHandler: (req: Request, res: Response) => Promise<void>; verifyLicenseHandler: (req: Request, res: Response) => Promise<void>; resendVerificationHandler: (req: Request, res: Response) => Promise<void>; }; /** 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<NvmLauncherResult>; /** * Startup repair: re-creates the wrapper and re-patches all known JSON-format * client configs on every server start. Handles two cases: * 1. Wrapper was deleted — recreates it so configs pointing to it keep working. * 2. Pre-existing install (user installed before this fix shipped) — patches * configs that still use bare `npx`. * * 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 the production getConfigPath. */ export declare function repairNvmLauncherOnStartup(home?: string, configPathResolver?: (client: string) => string | null): Promise<void>; /** * 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<boolean>; /** * 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<string>; /** * 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<void>; export declare function installJsonMcpClientConfig(client: string, version?: string, configPathOverride?: string): Promise<string>; export {}; //# sourceMappingURL=setupRoutes.d.ts.map