MCP PHP SDK

Tool implements JsonSerializable

Definition for a tool the client can call.

Tags
phpstan-import-type

ToolAnnotationsData from ToolAnnotations

phpstan-import-type

IconData from Icon

author

Kyrian Obikwelu koshnawaza@gmail.com

Table of Contents

Interfaces

JsonSerializable

Properties

$annotations  : ToolAnnotations|null
$description  : string|null
$icons  : array<string|int, mixed>|null
$inputSchema  : array<string|int, mixed>
$meta  : array<string|int, mixed>|null
$name  : string
$outputSchema  : array<string|int, mixed>|null

Methods

__construct()  : mixed
fromArray()  : self
jsonSerialize()  : ToolOutputSchema}
normalizeSchemaProperties()  : array<string, mixed>
Normalize schema properties: convert an empty properties array to stdClass.

Properties

$description read-only

public string|null $description

$icons read-only

public array<string|int, mixed>|null $icons = null

$inputSchema read-only

public array<string|int, mixed> $inputSchema

$meta read-only

public array<string|int, mixed>|null $meta = null

$name read-only

public string $name

$outputSchema read-only

public array<string|int, mixed>|null $outputSchema = null

Methods

__construct()

public __construct(string $name, ToolInputSchema $inputSchema, string|null $description, ToolAnnotations|null $annotations[, array<string|int, Icon>|null $icons = null ][, array<string, mixed>|null $meta = null ][, ToolOutputSchema|null $outputSchema = null ]) : mixed
Parameters
$name : string

the name of the tool

$inputSchema : ToolInputSchema

a JSON Schema object (as a PHP array) defining the expected 'arguments' for the tool

$description : string|null

A human-readable description of the tool. This can be used by clients to improve the LLM's understanding of available tools. It can be thought of like a "hint" to the model.

$annotations : ToolAnnotations|null

optional additional tool information

$icons : array<string|int, Icon>|null = null

optional icons representing the tool

$meta : array<string, mixed>|null = null

Optional metadata

$outputSchema : ToolOutputSchema|null = null

optional JSON Schema object (as a PHP array) defining the expected output structure

fromArray()

public static fromArray(ToolData $data) : self
Parameters
$data : ToolData
Return values
self

jsonSerialize()

public jsonSerialize() : ToolOutputSchema}
Return values
ToolOutputSchema}

normalizeSchemaProperties()

Normalize schema properties: convert an empty properties array to stdClass.

private static normalizeSchemaProperties(array<string, mixed> $schema) : array<string, mixed>
Parameters
$schema : array<string, mixed>
Return values
array<string, mixed>

        
On this page

Search results