# `ClaudeWrapper.McpConfig`
[🔗](https://github.com/genagent/claude_wrapper_ex/blob/main/lib/claude_wrapper/mcp_config.ex#L1)

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

# `server`

```elixir
@type server() :: %{
  type: String.t(),
  command: String.t() | nil,
  args: [String.t()],
  env: %{required(String.t()) =&gt; String.t()},
  url: String.t() | nil,
  headers: %{required(String.t()) =&gt; String.t()}
}
```

# `t`

```elixir
@type t() :: %ClaudeWrapper.McpConfig{servers: %{required(String.t()) =&gt; server()}}
```

# `add_http`

```elixir
@spec add_http(t(), String.t(), String.t(), keyword()) :: t()
```

Add an HTTP-based MCP server (the CLI's primary remote transport).

## Options

  * `:env` - Map of environment variables
  * `:headers` - Map of HTTP headers (e.g. `%{"Authorization" => "Bearer ..."}`)

# `add_sse`

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

Add an SSE-based MCP server.

## Options

  * `:env` - Map of environment variables
  * `:headers` - Map of HTTP headers (e.g. `%{"Authorization" => "Bearer ..."}`)

# `add_stdio`

```elixir
@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`

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

Parse from a decoded JSON map.

# `get_server`

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

Get a server definition by name.

# `new`

```elixir
@spec new() :: t()
```

Create a new empty MCP config.

# `read`

```elixir
@spec read(String.t()) :: {:ok, t()} | {:error, ClaudeWrapper.Error.t()}
```

Read and parse an existing `.mcp.json` file.

Returns `{:error, %ClaudeWrapper.Error{kind: :io}}` when the file
cannot be read and `{:error, %ClaudeWrapper.Error{kind: :json}}` when
its contents are not valid JSON.

# `remove`

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

Remove a server by name.

# `server_names`

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

List server names.

# `to_json`

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

Encode to the JSON string the CLI expects.

# `write!`

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

Write the config to a file.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
