import { type McpConfig, type Platform } from '../config/mcpConfig'; import { type AgentId } from '../agents/registry'; /** * Per-target MCP install state. * * missing — file doesn't exist on disk. * empty — file exists but no expected server entry is present. * (covers unparseable JSON, missing `mcpServers`/`servers` key, * and an explicitly empty server map.) * partial — only some of the expected server names are present. * Happens when mcp.yaml grew (new server added) but the user * has not re-run `mswai mcp` / `mswai update`. * drift — all expected names are present but at least one value * differs from what mcp.yaml + the current vars would produce. * (Codex TOML target never reports drift; values aren't compared.) * ok — all expected servers present with identical values. * * `status` treats `ok` + `drift` as installed; `missing` / `empty` / `partial` * are reported as not installed for the Unity Maker popup contract. */ export type McpTargetState = 'missing' | 'empty' | 'partial' | 'drift' | 'ok'; export interface McpInstallOptions { cwd: string; agents: AgentId[]; vars: Record; /** Override platform — used by tests to exercise both Windows and macOS. */ platform?: Platform; dryRun: boolean; /** Pre-loaded config; skip reading from disk (used by tests). */ config?: McpConfig; /** Explicit preserveExisting override. Default: `MSWAI_ENV !== 'prod'`. * `mswai mcp` (user-initiated red-button flow) passes `false` so the * generated file always reflects the supplied --mcp-url. `update` leaves * this undefined to keep the dev/prod auto behavior. */ preserveExisting?: boolean; /** When true, agent targets whose MCP config file does not yet exist are * skipped (no create). Used by `update` so MCP files are only refreshed * in workspaces where the user has already opted into MCP via * `mswai mcp`. Default: false (create when missing — `mswai mcp` flow). */ onlyExisting?: boolean; } export interface McpAgentWrite { agent: AgentId; path: string; action: 'created' | 'dry-run'; } export interface McpAgentSkip { agent: AgentId; reason: string; } export interface McpInstallResult { /** Server names that produced output for the current platform. */ servers: string[]; /** Agents that received an mcp.json. */ written: McpAgentWrite[]; /** Agents skipped because their MCP target is not yet supported. */ skippedAgents: McpAgentSkip[]; /** True when mcp.yaml is empty or no server has a variant for the current platform. */ noServers: boolean; } /** Serialize server map with the root key appropriate for each agent. * - Claude Code / Cursor / Antigravity use `mcpServers` * - VS Code (copilot) uses `servers` (changed in VS Code 1.99) * - Antigravity additionally renames HTTP `url` → `serverUrl` */ export declare function mcpJsonForAgent(serverMap: Record, agent: AgentId): string; export interface MergeMcpJsonOptions { /** Names that were in mcp.yaml previously but no longer are. They get * stripped from the file even when their values are non-default — these * are the entries `mswai` itself installed and is now retiring. */ removeNames?: string[]; /** When true, existing entries with the same name as a new entry keep their * current value (only missing servers get added). Hard escape hatch for * `mswai update --mcp-keep`. * * Note: deprecation removal still applies regardless of this flag — only * the add/replace path branches on it. */ preserveExisting?: boolean; /** Smart merge dataset: per-server specs built with platform defaults * stripped (placeholders left as literal `{KEY}`). When provided, the * merge applies per-leaf rules instead of whole-server overwrite: * * - Leaves whose unresolved version contains a `{KEY}` placeholder * were filled by a platform default. Preserve the existing value * when it diverges from the default (user replaced it, e.g. real * MSW_MCP_TOKEN). Otherwise emit the default. * - Structural / `--mcp-var`-supplied leaves always overwrite. * - Existing keys not in the proposed spec are preserved (user-added * fields like `env`, `disabled`, custom `cwd`). * * Ignored when `preserveExisting` is also set — preserveExisting wins. */ smartMergeUnresolved?: Record; } /** * Merge mcp server entries into an existing JSON file. * * Default behavior: our server keys overwrite conflicts; other existing keys * (including unrelated entries the user added) are preserved. * * With `preserveExisting`, only missing names are added — existing entries * keep their current value. With `removeNames`, the listed names are stripped * before the merge. */ export declare function mergeIntoMcpJson(existing: string, serverMap: Record, agent: AgentId, options?: MergeMcpJsonOptions): string; /** * Inspect an MCP JSON target (Claude Code / Cursor / GitHub Copilot) and * classify its install state against the expected server map. * * Empty / partial files no longer collapse into `drift` — this distinction is * what lets `status` report mcp=false for "file exists but no usable servers" * and for "only 1 of 2 expected servers present" cases. */ export declare function mcpJsonContainsServers(filePath: string, serverMap: Record, agent: AgentId): McpTargetState; export interface McpServerConflict { name: string; existing: string; proposed: string; } /** * Enumerate per-server conflicts between the on-disk JSON file and what * mcp.yaml would produce now. A "conflict" means the server exists on both * sides with a non-identical spec — i.e. the user (or a previous mswai run * with different vars) wrote a value that diverges from today's build. * * Used by `mswai update` to drive the interactive keep/overwrite prompt. * Returns [] when there are no conflicts. */ export declare function jsonMcpConflicts(existing: string, serverMap: Record, agent: AgentId): McpServerConflict[]; /** * Same as jsonMcpConflicts but for .codex/config.toml. Compares each * `[mcp_servers.X]` section's text content against what * `buildCodexMcpToml({ X: spec })` would emit. */ export declare function codexMcpConflicts(existing: string, serverMap: Record): McpServerConflict[]; /** Serialize the mcp_servers entries for .codex/config.toml. */ export declare function buildCodexMcpToml(serverMap: Record): string; /** * Merge mcp_servers sections into existing .codex/config.toml content. * * Default behavior: existing sections for the same server names are replaced; * other content (non-MCP Codex settings, unrelated `mcp_servers.*` sections) * is preserved. * * With `preserveExisting`, sections that are already present keep their * current content — only missing names get appended. With `removeNames`, the * listed sections are stripped first. */ export declare function patchCodexToml(existing: string, serverMap: Record, options?: MergeMcpJsonOptions): string; /** True when all given server names have a [mcp_servers.X] header in the TOML content. */ export declare function codexTomlHasServers(content: string, serverNames: string[]): boolean; /** * Inspect the Codex TOML target and classify its install state. * * The TOML format doesn't carry enough structure for cheap value-level * comparison, so this function only distinguishes `missing` / `empty` / * `partial` / `ok` — never `drift`. */ export declare function codexTomlContainsServers(filePath: string, serverNames: string[]): McpTargetState; /** Build the resolved server map for the current platform. * User-supplied `vars` override per-platform defaults from `mcp.yaml`. * With `opts.skipDefaults`, platform defaults are NOT folded in — unsupplied * keys remain as literal `{KEY}` placeholders. update's smart merge uses * this variant to identify which leaves came from defaults vs --mcp-var. */ export declare function buildMcpJson(config: McpConfig, platform: Platform, vars: Record, opts?: { skipDefaults?: boolean; }): { serverMap: Record; serverNames: string[]; } | null; export declare function installMcp(opts: McpInstallOptions): McpInstallResult;