These helpers create common JSON Schema descriptions for tool arguments and
output. type_from_schema() wraps a complete schema supplied as a list or
JSON string without removing JSON Schema 2020-12 keywords. A complete tool
input schema can be passed directly as arguments = type_from_schema(...)
when it has direct root type = "object".
Usage
type_boolean(description = NULL, required = TRUE)
type_integer(description = NULL, required = TRUE)
type_number(description = NULL, required = TRUE)
type_string(description = NULL, required = TRUE)
type_enum(values, description = NULL, required = TRUE)
type_array(items, description = NULL, required = TRUE)
type_object(
.description = NULL,
...,
.required = TRUE,
.additional_properties = FALSE
)
type_from_schema(text = NULL, path = NULL)
type_ignore()Arguments
- description
Optional argument description.
- required
Whether the argument is listed as required in the parent schema.
FALSEpermits omission but does not set an R default.- values
Allowed enum values.
- items
Type helper describing each array item.
- .description
Optional object description.
- ...
Named properties for object schemas.
- .required
Whether the object itself is listed as required in its parent schema.
- .additional_properties
Whether to allow additional properties.
- text
A JSON Schema as a list or JSON string.
- path
Path to a JSON Schema file. Exactly one of
textorpathmust be supplied.
Details
When $schema is absent, MCP treats schemas as JSON Schema 2020-12. Authors
are responsible for schema validity and for runtime input/output conformance,
domain validation, authorization or access checks, side-effect safety,
output sanitization, and rate limiting where needed. List input preserves the
supplied R list shape: use a named empty list for {} and an unnamed empty
list for [].
Incoming JSON arrays remain R lists. These helpers do not coerce or validate argument values or supply R defaults. If an argument may be omitted, give the R function a default for it.
type_ignore() omits an argument from the advertised schema. It does not
reject a caller-supplied argument or enforce permissions.
Examples
type_string("A label.")
#> $kind
#> [1] "string"
#>
#> $description
#> [1] "A label."
#>
#> $required
#> [1] TRUE
#>
#> attr(,"class")
#> [1] "mcplite_tool_type_string" "mcplite_tool_type"
type_array(type_integer(), description = "Integer values.")
#> $kind
#> [1] "array"
#>
#> $description
#> [1] "Integer values."
#>
#> $required
#> [1] TRUE
#>
#> $items
#> $kind
#> [1] "integer"
#>
#> $description
#> NULL
#>
#> $required
#> [1] TRUE
#>
#> attr(,"class")
#> [1] "mcplite_tool_type_integer" "mcplite_tool_type"
#>
#> attr(,"class")
#> [1] "mcplite_tool_type_array" "mcplite_tool_type"
type_object(
.description = "A labeled score.",
label = type_string(),
score = type_number(required = FALSE)
)
#> $kind
#> [1] "object"
#>
#> $description
#> [1] "A labeled score."
#>
#> $required
#> [1] TRUE
#>
#> $properties
#> $properties$label
#> $kind
#> [1] "string"
#>
#> $description
#> NULL
#>
#> $required
#> [1] TRUE
#>
#> attr(,"class")
#> [1] "mcplite_tool_type_string" "mcplite_tool_type"
#>
#> $properties$score
#> $kind
#> [1] "number"
#>
#> $description
#> NULL
#>
#> $required
#> [1] FALSE
#>
#> attr(,"class")
#> [1] "mcplite_tool_type_number" "mcplite_tool_type"
#>
#>
#> $additional_properties
#> [1] FALSE
#>
#> attr(,"class")
#> [1] "mcplite_tool_type_object" "mcplite_tool_type"
type_from_schema(list(
type = "string",
minLength = 1
))
#> $kind
#> [1] "schema"
#>
#> $description
#> NULL
#>
#> $required
#> [1] TRUE
#>
#> $schema
#> $schema$type
#> [1] "string"
#>
#> $schema$minLength
#> [1] 1
#>
#>
#> attr(,"class")
#> [1] "mcplite_tool_type_schema" "mcplite_tool_type"