ClaudeWrapper.McpConfig (ClaudeWrapper v0.7.0)

Copy Markdown View Source

Programmatic builder for .mcp.json configuration files.

Builds the JSON structure that the Claude CLI expects for MCP server configuration, then writes it to disk or returns it as a string.

Usage

ClaudeWrapper.McpConfig.new()
|> ClaudeWrapper.McpConfig.add_stdio("my-server", "npx", ["-y", "my-mcp-server"],
  env: %{"API_KEY" => "sk-..."}
)
|> ClaudeWrapper.McpConfig.add_sse("remote", "https://example.com/mcp")
|> ClaudeWrapper.McpConfig.write!("/path/to/project/.mcp.json")

Format

The generated JSON follows the Claude CLI's expected format:

{
  "mcpServers": {
    "server-name": {
      "type": "stdio",
      "command": "npx",
      "args": ["-y", "server-pkg"],
      "env": {"KEY": "value"}
    }
  }
}

Summary

Functions

Add an SSE-based MCP server.

Parse from a decoded JSON map.

Get a server definition by name.

Create a new empty MCP config.

Read and parse an existing .mcp.json file.

Remove a server by name.

List server names.

Encode to the JSON string the CLI expects.

Write the config to a file.

Types

server()

@type server() :: %{
  type: String.t(),
  command: String.t() | nil,
  args: [String.t()],
  env: %{required(String.t()) => String.t()},
  url: String.t() | nil
}

t()

@type t() :: %ClaudeWrapper.McpConfig{servers: %{required(String.t()) => server()}}

Functions

add_sse(config, name, url, opts \\ [])

@spec add_sse(t(), String.t(), String.t(), keyword()) :: t()

Add an SSE-based MCP server.

Options

  • :env - Map of environment variables

add_stdio(config, name, command, args \\ [], opts \\ [])

@spec add_stdio(t(), String.t(), String.t(), [String.t()], keyword()) :: t()

Add a stdio-based MCP server.

Options

  • :env - Map of environment variables

from_map(data)

@spec from_map(map()) :: t()

Parse from a decoded JSON map.

get_server(mcp_config, name)

@spec get_server(t(), String.t()) :: server() | nil

Get a server definition by name.

new()

@spec new() :: t()

Create a new empty MCP config.

read(path)

@spec read(String.t()) :: {:ok, t()} | {:error, term()}

Read and parse an existing .mcp.json file.

remove(config, name)

@spec remove(t(), String.t()) :: t()

Remove a server by name.

server_names(mcp_config)

@spec server_names(t()) :: [String.t()]

List server names.

to_json(config)

@spec to_json(t()) :: String.t()

Encode to the JSON string the CLI expects.

write!(config, path)

@spec write!(t(), String.t()) :: :ok

Write the config to a file.