Contents

adamtheturtle/mcpclientinstall

Safe, non-destructive editing of MCP desktop-client configuration files in Swift.

Installation

.package(
    url: "https://github.com/adamtheturtle/MCPClientInstall.git",
    from: "0.1.0"
)

Add the MCPClientInstall product to your target.

Usage

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"
)

Safety

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.

Requirements

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

Documentation

The package includes a DocC catalog and is configured for hosted documentation on Swift Package Index.

License

MIT. See LICENSE.

Package Metadata

Repository: adamtheturtle/mcpclientinstall

Default branch: main

README: README.md