Tool
Tool
class ToolProperties
name
the tool name the client calls
public readonly string $nameType: string
inputSchema
JSON Schema describing the accepted arguments
public readonly array $inputSchemaType: array
handler
the callable that executes the tool
private readonly \Closure $handlerType: Closure
signature
reflection over the handler, used to bind named arguments
private readonly \ReflectionFunctionAbstract $signatureType: ReflectionFunctionAbstract
description
what the tool does
public readonly string $descriptionType: string
title
human-readable name for display
public readonly string $titleType: string
annotations
behavioural hints for clients
public readonly array $annotationsType: array
outputSchema
JSON Schema describing the structured result
public readonly array $outputSchemaType: array
Methods
__construct
public __construct(string $name, array $inputSchema, \Closure $handler, \ReflectionFunctionAbstract $signature, string $description, string $title, array $annotations, array $outputSchema): voidParameters
| Parameter | Type | Description |
|---|---|---|
$name | string | the tool name the client calls |
$inputSchema | array | JSON Schema describing the accepted arguments |
$handler | Closure | the callable that executes the tool |
$signature | ReflectionFunctionAbstract | reflection over the handler, used to bind named arguments |
$description | string | what the tool does |
$title | string | human-readable name for display |
$annotations | array | behavioural hints for clients |
$outputSchema | array | JSON Schema describing the structured result |
fromMethod
Builds a tool from an attributed controller method.
public fromMethod(object $controller, \ReflectionMethod $method, ToolAttribute $attribute): selfReturns: self
Parameters
| Parameter | Type | Description |
|---|---|---|
$controller | object | the server instance the method is called on |
$method | ReflectionMethod | the attributed method |
$attribute | Hazaar\MCP\Attribute\Tool | the attribute instance carrying the tool metadata |
fromCallable
Builds a tool from an arbitrary callable registered at runtime.
public fromCallable(string $name, callable $handler, ?array $inputSchema, ?string $description): selfReturns: self
The schema is optional: when omitted it is derived from the callable's signature, exactly as it would be for an attributed method.
Parameters
| Parameter | Type | Description |
|---|---|---|
$name | string | the tool name |
$handler | callable | the callable to execute |
$inputSchema | array | JSON Schema for the arguments, or null to derive it |
$description | string | what the tool does |
toArray
Returns the tool definition as published by tools/list.
public toArray(): arrayReturns: array
invoke
Binds the supplied arguments to the handler's signature and executes it.
public invoke(array $arguments): mixedReturns: mixed
Parameters
| Parameter | Type | Description |
|---|---|---|
$arguments | array | the named arguments from tools/call |
coerce
Converts a JSON-decoded argument into the type the parameter declares.
private coerce(\ReflectionParameter $parameter, mixed $value): mixedReturns: mixed
JSON's type system is narrower than PHP's, and models are inconsistent about quoting numbers, so numeric strings are accepted where a number is wanted. Anything genuinely mismatched is rejected rather than silently coerced, since a wrong-typed argument that reaches the tool body produces a far more confusing failure.
Parameters
| Parameter | Type | Description |
|---|---|---|
$parameter | ReflectionParameter | |
$value | mixed |
coerceEnum
Resolves a scalar argument to a backed enum case.
private coerceEnum(string $class, string $name, mixed $value): mixedReturns: mixed
Parameters
| Parameter | Type | Description |
|---|---|---|
$class | string | |
$name | string | |
$value | mixed |
Generated by Hazaar API Doc Generator on Sun, 23 Aug 2026 10:49:44 +0000