yera.tools.mcp.schema

Compile MCP JSON Schemas into Yera Struct types.

Symbols

def generation_struct_from_json_schema — Compile MCP arguments for sparse LLM structured generation.
def struct_from_json_schema — Compile an MCP object schema into a dynamic Yera Struct type.
def type_from_json_schema — Compile JSON Schema into a Yera-supported Python type.
def type_from_mcp_output_schema — Compile an MCP tool output schema into its Python return type.

generation_struct_from_json_schema

generation_struct_from_json_schema(
    name: str,
    schema: dict[str, object],
) → type[Struct]

Compile MCP arguments for sparse LLM structured generation.

Non-required properties accept null so strict structured-output providers can express omission. The resulting values must still be reduced and validated through the ordinary execution structure.

Parameters

name
type: str

Name assigned to the generated Struct class.

schema
type: dict[str, object]

MCP JSON Schema describing the tool arguments.

Returns

type: type[Struct]

A dynamic Struct subclass suitable only for argument generation.

struct_from_json_schema

struct_from_json_schema(
    name: str,
    schema: dict[str, object],
) → type[Struct]

Compile an MCP object schema into a dynamic Yera Struct type.

Parameters

name
type: str

Name assigned to the generated Struct class.

schema
type: dict[str, object]

MCP JSON Schema describing the tool arguments.

Returns

type: type[Struct]

A dynamic Struct subclass validating those arguments.

Raises

ValueError

If the root is not an object schema or a property uses an unsupported schema shape.

type_from_json_schema

type_from_json_schema(
    name: str,
    schema: dict[str, object],
) → object

Compile JSON Schema into a Yera-supported Python type.

Unlike tool input compilation, the schema root may describe any supported JSON value rather than requiring an object.

Parameters

name
type: str

Name used for any generated Struct classes.

schema
type: dict[str, object]

JSON Schema to compile.

Returns

type: object

A Python annotation suitable for Yera's coercion infrastructure.

type_from_mcp_output_schema

type_from_mcp_output_schema(
    name: str,
    schema: dict[str, object],
) → object

Compile an MCP tool output schema into its Python return type.

MCP servers represent scalar returns as an object containing one required property named result. This wrapper belongs to the protocol and is not exposed to Python callers.

Parameters

name
type: str

Name used for any generated Struct classes.

schema
type: dict[str, object]

MCP output schema advertised by the server.

Returns

type: object

The unwrapped scalar type or compiled structured result type.