Skip to content

McpConfigWriter

Category: Config

Source: mcp_config_writer.dart

Mutates the mcp.servers.* block of config.yaml while preserving the user's comments, formatting, and key order.

Backed by package:yaml_edit, which performs surgical edits on the original YAML source. Every mutation writes the file atomically via tmp + rename, and re-parses the result through [parseMcpConfig] before committing — if the edit would produce an unloadable file, the original is restored and [McpConfigWriteError] is thrown.

Classes

McpConfigWriteError

Thrown when the writer refuses an operation (duplicate id, missing id, or post-mutation re-parse failure).

Constructor

dart
McpConfigWriteError(this.message)

Properties

PropertyTypeDescription
messageString

Methods

String toString()

McpConfigWriter

Constructor

dart
McpConfigWriter(this.configPath)

Properties

PropertyTypeDescription
configPathStringAbsolute path to the user's config.yaml.

Methods

bool hasServer(String id)

Returns true if mcp.servers.<id> exists in the on-disk YAML.

void addServer(McpServerSpec spec, {bool overwrite = false})

Writes a server entry under mcp.servers.<id>. Creates the mcp: and mcp.servers: blocks if missing. Throws if [spec.id] already exists and [overwrite] is false.

Released under the MIT License.