fix: idempotent config writes - don't overwrite existing entries or add URL duplicates
Problem
When add-mcp is called with -y (e.g. from automation tools like skillpm), it auto-detects agents and writes to all of them. On repeated runs this causes:
-
Existing entries overwritten - custom args, auth config, or other user modifications are lost. For example, a
workiqentry with custom args gets its args array replaced, losing extra arguments the user had added. -
URL duplicates - if a URL is already configured under a different name (e.g.
powerbi-remotewith customcopilotTokenAuthentication),add-mcpadds a new bare entry for the same URL without checking. -
Unnecessary reformatting - the entire config section is replaced via
jsonc.modify, reformatting all sibling entries even when only one new entry is being added.
Fix
src/installer.ts
- Before writing, read existing config and check if the server name already exists -> skip
- Check if any existing entry has the same URL -> skip
InstallResultgains an optionalskippedfield so callers can distinguish a fresh install from a no-op
src/formats/json.ts
- Changed from "merge everything + replace entire section" to "only add entries not present by name"
- Uses per-entry
jsonc.modifyat the[configKey, serverName]path instead of replacing the wholeconfigKeysection
src/formats/toml.ts
- Same skip-existing-entries logic for TOML configs (Codex)
Tests
4 new tests in tests/installer.test.ts:
- Skips when server name already exists
- Skips when URL already exists under a different name
- Does not overwrite existing entry args
- Preserves existing entries when adding new ones
All 24 installer tests pass. All 79 total tests pass.