NexusMCP.Server.Schema (NexusMCP v0.3.0)

Copy Markdown View Source

Converts param type DSL definitions to JSON Schema.

Type DSL

:string               optional string
:string!              required string
:integer              optional integer
:boolean              optional boolean
:number               optional number
:object               optional object
{:string!, "desc"}    required string with description
{:array, :string}     array of strings
{{:array, :string}, "Tags"}  array with description

Summary

Functions

Strips ! from all param types, making everything optional. Useful for update schemas where all fields should be optional.

Converts a keyword list of param definitions to a JSON Schema object.

Converts a single type spec to {json_schema_map, is_required}.

Types

param_type()

@type param_type() ::
  :string
  | :string!
  | :integer
  | :integer!
  | :boolean
  | :boolean!
  | :number
  | :number!
  | :object
  | :object!
  | {:array, atom()}
  | {param_type(), String.t()}

Functions

make_optional(params)

@spec make_optional(keyword()) :: keyword()

Strips ! from all param types, making everything optional. Useful for update schemas where all fields should be optional.

params_to_schema(params)

@spec params_to_schema(keyword()) :: map()

Converts a keyword list of param definitions to a JSON Schema object.

Example

iex> params_to_schema([name: :string!, id: {:string!, "Page ID"}])
%{
  type: "object",
  properties: %{
    "name" => %{type: "string"},
    "id" => %{type: "string", description: "Page ID"}
  },
  required: ["name", "id"]
}

type_to_schema(arg1)

@spec type_to_schema(param_type()) :: {map(), boolean()}

Converts a single type spec to {json_schema_map, is_required}.