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,allOforder and the first branch that names a property wins. - A branch that is a local
$refinto the root's$defsordefinitionsis followed. - A key stays required when the root requires it, when an
allOfbranch requires it, or when every branch of ananyOf(or every branch of aoneOf) requires it. A key that only someanyOf/oneOfbranches require is dropped fromrequired, 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.
Summary
Types
Functions
Returns the constraint that flatten/1 removes, as a sentence for the tool description, or nil when the schema has no top-level combinator.
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.
Returns the required property names of a flattened schema.