Safe, non-destructive editing of MCP desktop-client configuration files in Swift.
Documentation | Swift Package Index
MCPClientInstall adds or updates a local MCP server in:
- Claude Desktop, Claude Code, and Cursor JSON configuration
- Codex TOML configuration
It preserves unrelated settings, refuses ambiguous configuration shapes, handles quoted TOML keys and multiline values, retains existing line endings, and can replace files while preserving metadata and leaving a backup.
.package(
url: "https://github.com/adamtheturtle/MCPClientInstall.git",
from: "0.1.0"
)Add the MCPClientInstall product to your target.
import MCPClientInstall
let server = MCPServerSpec(
name: "my-server",
command: "/usr/local/bin/my-server",
arguments: ["--mcp"]
)
// JSON: Claude Desktop, Claude Code, or Cursor
let jsonLocation = MCPDesktopClient.cursor.configurationLocation
// Resolving a checked configuration URL can throw for an unsafe location.
let jsonConfigURL = try jsonLocation.file(relativeTo: homeDirectory)
let root = try MCPClientInstall.existingJSON(at: jsonConfigURL)
let merged = try addingMCPServer(server, toJSON: root)
let data = try MCPClientInstall.prettyJSONData(from: merged.root)
// TOML: Codex
let codexLocation = MCPDesktopClient.codex.configurationLocation
let codexConfigURL = try codexLocation.file(relativeTo: homeDirectory)
let updated = try MCPClientInstall.prepareServerUpdate(
server,
format: .codexTOML,
at: codexConfigURL
)Writing is deliberately separate from merging, so an application can show a diff or ask for confirmation first:
try MCPClientInstall.writeConfig(
data,
to: jsonConfigURL,
backupSuffix: server.backupSuffix
)For a complete prepare, safe replacement, read-back verification, and recoverable backup in one operation:
let result = try MCPClientInstall.installServer(
server,
format: codexLocation.format,
at: codexConfigURL
)
let restored = try MCPClientInstall.restoreBackup(
for: server,
format: codexLocation.format,
at: codexConfigURL,
displacedSuffix: ".my-server-before-restore"
)MCPClientInstall does not silently replace malformed or structurally incompatible configuration. Its file helper refuses symlinks and special files, retains metadata when replacing an existing file, and keeps the previous contents beside the target.
Applications remain responsible for obtaining user consent and filesystem access. The package has no UI and never searches for or modifies configuration on import.
MCPClientInstall depends on swift-toml, including its C++ toml++ parser target,
so consumers need a Swift toolchain with C++ interoperability support.
- Swift 6.2+
- macOS 14+
- Linux with a Swift 6.2 toolchain
The package includes a DocC catalog and is configured for hosted documentation on Swift Package Index.
MIT. See LICENSE.