# `MingaClaudeBridge.MCP.Schema`
[🔗](https://github.com/jsmestad/minga-claude-bridge/blob/main/lib/minga_claude_bridge/mcp/schema.ex#L1)

Prepares tool input schemas for Claude Code's MCP client.

Claude Code drops an MCP tool whose input schema has a top-level `anyOf`, `oneOf`, or `allOf`, because the Anthropic API does not accept those at the root. `flatten/1` turns such a schema into one object schema, the same way pi-claude-bridge and Claude Code's own normalizer do:

  * Properties are merged. Root properties win over branch properties, then branches are read in `anyOf`, `oneOf`, `allOf` order and the first branch that names a property wins.
  * A branch that is a local `$ref` into the root's `$defs` or `definitions` is followed.
  * A key stays required when the root requires it, when an `allOf` branch requires it, or when every branch of an `anyOf` (or every branch of a `oneOf`) requires it. A key that only some `anyOf`/`oneOf` branches require is dropped from `required`, because it holds only for one branch.
  * The result always has `"type" => "object"` and a `"properties"` map.

Flattening loses the "one of these groups" constraint. `constraint_note/1` restates it in Claude Code's wording, for the tool description, so the model's first call is likely to pass Minga's validation against the full schema. Minga still validates arguments against the original schema; the bridge only checks the flattened shape (see `MingaClaudeBridge.MCP`).

Schemas use string keys, as decoded from JSON.

# `t`

```elixir
@type t() :: %{optional(String.t()) =&gt; term()}
```

A JSON Schema with string keys.

# `constraint_note`

```elixir
@spec constraint_note(term()) :: String.t() | nil
```

Returns the constraint that `flatten/1` removes, as a sentence for the tool description, or `nil` when the schema has no top-level combinator.

# `flatten`

```elixir
@spec flatten(term()) :: t()
```

Returns an object schema without top-level combinators.

A schema with no top-level combinator keeps every field and only gains `"type" => "object"` and an empty `"properties"` map when they are missing. A value that is not a map becomes an empty object schema.

# `required`

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

Returns the `required` property names of a flattened schema.

---

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