MCP PHP SDK

CallToolHandler implements RequestHandlerInterface

FinalYes

A tools/call answers with the tool's output or, under MRTR, with a request for the input it still needs.

Tags
author

Christopher Hertel mail@christopher-hertel.de

Tobias Nyholm tobias.nyholm@gmail.com

Table of Contents

Interfaces

RequestHandlerInterface
Covariant in TResult: a handler only ever produces its result, so one declaring a concrete result type satisfies a collection of handlers typed by the interface every result implements.

Properties

$logger  : LoggerInterface
$referenceHandler  : ReferenceHandlerInterface
$registry  : RegistryInterface
$schemaValidator  : SchemaValidator

Methods

__construct()  : mixed
handle()  : Response<string|int, CallToolResult|InputRequiredResult>|Error
supports()  : bool
isJsonObject()  : bool
Whether a `structuredContent` value encodes as a JSON object — the only shape revisions predating SEP-2106 accept.
summarizeValidationErrors()  : string
validateStructuredContent()  : CallToolResult|null
A tool declaring an `outputSchema` promises every `structuredContent` it sends conforms to it, in every revision. A mismatch is the server's own bug, but it is reported as a tool execution error rather than a protocol error so that the model sees what went wrong.

Properties

$logger read-only

private LoggerInterface $logger = new NullLogger()

Methods

isJsonObject()

Whether a `structuredContent` value encodes as a JSON object — the only shape revisions predating SEP-2106 accept.

private static isJsonObject(mixed $value) : bool
Parameters
$value : mixed
Return values
bool

summarizeValidationErrors()

private static summarizeValidationErrors(array<int, array{pointer: string, keyword: string, message: string}> $validationErrors) : string
Parameters
$validationErrors : array<int, array{pointer: string, keyword: string, message: string}>
Return values
string

validateStructuredContent()

A tool declaring an `outputSchema` promises every `structuredContent` it sends conforms to it, in every revision. A mismatch is the server's own bug, but it is reported as a tool execution error rather than a protocol error so that the model sees what went wrong.

private validateStructuredContent(Tool $tool, CallToolResult $result) : CallToolResult|null
Parameters
$tool : Tool
$result : CallToolResult
Return values
CallToolResult|null —

the error result to send instead, or null when there is nothing to report

On this page

Search results