# `ConduitMcp.DSL.SchemaBuilder`
[🔗](https://github.com/nyo16/conduit_mcp/blob/v0.10.1/lib/conduit_mcp/dsl/schema_builder.ex#L1)

Builds JSON Schema and NimbleOptions schemas from DSL parameter definitions.

This module converts the accumulated parameter definitions from the DSL
into both JSON Schema format (for MCP client validation) and NimbleOptions
schemas (for runtime server-side validation).

## Dual Schema Generation

The module now generates two types of schemas:

1. **JSON Schema** - Used by MCP clients for input validation and introspection
2. **NimbleOptions Schema** - Used for runtime server-side parameter validation

Both schemas are generated from the same DSL parameter definitions but serve
different purposes in the validation pipeline.

# `build_dual_prompt_schemas`

Builds dual schemas for prompt definitions.

# `build_dual_schemas`

Builds both JSON Schema and NimbleOptions validation schema from tool definition.

Returns a map containing both schema types for comprehensive validation.

## Examples

    iex> tool_def = %{name: "greet", params: [...]}
    iex> ConduitMcp.DSL.SchemaBuilder.build_dual_schemas(tool_def)
    %{
      json_schema: %{"name" => "greet", "inputSchema" => %{...}},
      nimble_options_schema: [name: [type: :string, required: true], ...]
    }

# `build_input_schema`

Builds a JSON Schema input schema from parameter definitions.

# `build_nimble_options_prompt_schema`

Builds a NimbleOptions validation schema for prompt arguments.

# `build_nimble_options_schema`

Builds a NimbleOptions validation schema from tool definition.

Converts DSL parameter definitions into a NimbleOptions schema format
that can be used for runtime parameter validation with type coercion
and advanced constraints.

## Examples

    iex> tool_def = %{
    ...>   name: "calculate",
    ...>   params: [
    ...>     %{name: :a, type: :integer, opts: [required: true, min: 0]},
    ...>     %{name: :b, type: :integer, opts: [required: true, min: 0]}
    ...>   ]
    ...> }
    iex> ConduitMcp.DSL.SchemaBuilder.build_nimble_options_schema(tool_def)
    [
      a: [type: :integer, required: true, min: 0],
      b: [type: :integer, required: true, min: 0]
    ]

# `build_prompt_schema`

Builds a prompt schema from DSL definition.

# `build_resource_schema`

Builds a resource schema from DSL definition.

Used for `resources/list` (static URIs only).

# `build_resource_template_schema`

Builds a resource-template schema from a templated DSL definition.

Used for `resources/templates/list` (URIs with `{param}` placeholders).
Emits `uriTemplate` instead of `uri` per MCP spec.

# `build_tool_schema`

Builds a complete tool schema from DSL definition.

## Example

    iex> tool_def = %{
    ...>   name: "greet",
    ...>   description: "Greets someone",
    ...>   params: [
    ...>     %{name: :name, type: :string, description: "Name", opts: [required: true]},
    ...>     %{name: :age, type: :number, description: "Age", opts: []}
    ...>   ],
    ...>   handler: {:fn, fn _conn, p -> {:ok, p} end}
    ...> }
    iex> ConduitMcp.DSL.SchemaBuilder.build_tool_schema(tool_def)
    %{
      "name" => "greet",
      "description" => "Greets someone",
      "inputSchema" => %{
        "type" => "object",
        "properties" => %{
          "name" => %{"type" => "string", "description" => "Name"},
          "age" => %{"type" => "number", "description" => "Age"}
        },
        "required" => ["name"]
      }
    }

# `compile_prompt_validation_schemas`

Compiles validation schemas for all prompts in a server module.

# `compile_tool_validation_schemas`

Compiles validation schemas for all tools in a server module.

This function is used during the `@before_compile` hook to generate
validation schemas for all tools defined in the DSL.

## Examples

    iex> tools = [
    ...>   %{name: "greet", params: [...]},
    ...>   %{name: "calc", params: [...]}
    ...> ]
    iex> ConduitMcp.DSL.SchemaBuilder.compile_tool_validation_schemas(tools)
    %{
      "greet" => [name: [type: :string, required: true], ...],
      "calc" => [a: [type: :integer, min: 0], ...]
    }

# `generate_validation_lookup_functions`

Generates compile-time validation schema lookup functions.

This creates the AST for functions that will be injected into the
server module to provide fast schema lookups at runtime.

Returns quoted AST that defines:
- `__validation_schema_for_tool__/1`
- `__validation_schema_for_prompt__/1`

# `templated?`

Returns true when the given resource definition's URI contains a `{param}`
template placeholder.

# `to_resource_template_schema`

Converts a static resource JSON schema (with `"uri"`) into a resource-template
schema (with `"uriTemplate"`). Other keys are preserved.

# `validate_all_schemas`

Validates all schemas in a tool/prompt definition list.

Used during compile time to catch schema generation errors early.
Returns `:ok` if all schemas are valid, or `{:error, details}` if any are invalid.

# `validate_nimble_options_schema`

Validates that a NimbleOptions schema is properly formed.

This is used during compile time to ensure the generated schema
is valid for NimbleOptions validation.

---

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