ConduitMcp.Validation.SchemaConverter (ConduitMCP v0.9.5)

Copy Markdown View Source

Converts DSL parameter definitions to NimbleOptions validation schemas.

This module takes parameter definitions from the ConduitMCP DSL and converts them into NimbleOptions schemas for runtime validation. It handles type mapping, constraint extraction, and validation rule compilation.

Type Mapping

DSL types are mapped to NimbleOptions types as follows:

  • :string -> :string
  • :integer -> :integer
  • :number -> :number (float)
  • :boolean -> :boolean
  • :object -> :map (with nested validation)
  • :array -> {:list, type} where type is the item type
  • {:array, item_type} -> {:list, converted_item_type}

Validation Options

DSL options are converted to NimbleOptions validation rules:

  • required: true -> required: true
  • enum: [...] -> in: [...]
  • default: value -> default: value
  • min: value -> min: value
  • max: value -> max: value
  • min_length: value -> min_length: value
  • max_length: value -> max_length: value
  • validator: function -> validator: function

Summary

Functions

Compiles a complete tool definition to a NimbleOptions validation schema.

Converts a list of DSL parameter definitions to a NimbleOptions schema.

Enhanced error formatter for NimbleOptions validation errors.

Validates a NimbleOptions schema definition.

Functions

compile_validation_schema(map)

Compiles a complete tool definition to a NimbleOptions validation schema.

Takes a tool definition with parameters and converts it to a schema that can be used for runtime validation.

dsl_params_to_nimble_options(params)

Converts a list of DSL parameter definitions to a NimbleOptions schema.

Examples

iex> params = [
...>   %{name: :name, type: :string, opts: [required: true]},
...>   %{name: :age, type: :integer, opts: [min: 0, max: 150]}
...> ]
iex> ConduitMcp.Validation.SchemaConverter.dsl_params_to_nimble_options(params)
[
  name: [type: :string, required: true],
  age: [type: :integer, min: 0, max: 150]
]

format_detailed_errors(error, original_params)

Enhanced error formatter for NimbleOptions validation errors.

Takes a NimbleOptions.ValidationError and converts it to detailed error information suitable for MCP responses.

validate_schema(schema)

Validates a NimbleOptions schema definition.

Checks if the generated schema is valid for NimbleOptions. Used during compile time to catch schema generation errors.