MCP PHP SDK

TitledEnumSchemaDefinition extends AbstractSchemaDefinition

FinalYes

Schema definition for single-select enum fields with titled options (SEP-1330).

Uses the oneOf pattern with const/title pairs instead of enum/enumNames. Produces: {"type": "string", "oneOf": [{"const": "value", "title": "Label"}, ...]}

Tags
see
https://github.com/modelcontextprotocol/modelcontextprotocol/issues/1330

Table of Contents

Properties

$default  : string|null
$description  : string|null
$oneOf  : array<string|int, mixed>
$title  : string

Methods

__construct()  : mixed
fromArray()  : self
jsonSerialize()  : array<string, mixed>
buildBaseJson()  : array<string, mixed>
Build the base JSON structure with type, title, and optional description.
validateTitle()  : void
Validate that title exists and is a string in the data array.

Properties

Methods

__construct()

public __construct(string $title, array<int, array{const: string, title: string}> $oneOf[, string|null $description = null ][, string|null $default = null ]) : mixed
Parameters
$title : string

Human-readable title for the field

$oneOf : array<int, array{const: string, title: string}>

Array of const/title pairs

$description : string|null = null

Optional description/help text

$default : string|null = null

Optional default value (must match a const)

fromArray()

public static fromArray(array{title: string, oneOf: list, description?: string, default?: string} $data) : self
Parameters
$data : array{title: string, oneOf: list, description?: string, default?: string}
Return values
self

buildBaseJson()

Build the base JSON structure with type, title, and optional description.

protected buildBaseJson(string $type) : array<string, mixed>
Parameters
$type : string
Return values
array<string, mixed>

validateTitle()

Validate that title exists and is a string in the data array.

protected static validateTitle(array<string, mixed> $data, string $schemaType) : void
Parameters
$data : array<string, mixed>
$schemaType : string
Tags
throws
InvalidArgumentException

        
On this page

Search results