$inputSchema the tool's JSON Schema, as the server sent it * @param array $annotations the server's own hints (`readOnlyHint`, `destructiveHint`, ...) */ public function __construct( public string $name, public string $description, public array $inputSchema, public array $annotations = [], public ?string $title = null, ) {} public function fingerprint(): string { $canonical = self::canonical([ 'name' => $this->name, 'description' => $this->description, 'inputSchema' => $this->inputSchema, 'annotations' => $this->annotations, ]); $precision = (string) ini_get('serialize_precision'); // phpcs:ignore WordPress.PHP.IniSet.Risky -- serialize_precision decides how json_encode() and serialize() write a float; it is changed for these two calls only and put back in the finally below. ini_set('serialize_precision', '-1'); try { // phpcs:ignore WordPress.WP.AlternativeFunctions.json_encode_json_encode -- The plain function, as php-agents' McpToolDefinition calls it: when json_encode() returns false, wp_json_encode() runs _wp_json_sanity_check() and encodes again, a second path the library does not have. $json = json_encode($canonical, self::JSON_FLAGS); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.serialize_serialize -- Only hashed, never stored or unserialized: the lossless fallback for a definition JSON cannot encode (see the class docblock). return hash('sha256', $json !== false ? $json : serialize($canonical)); } finally { ini_set('serialize_precision', $precision); // phpcs:ignore WordPress.PHP.IniSet.Risky -- Restores the value read above. } } public function destructive(): bool { return ($this->annotations['destructiveHint'] ?? null) === true; } private static function canonical(mixed $value): mixed { if (!is_array($value)) { return $value; } $value = array_map(self::canonical(...), $value); if (!array_is_list($value)) { ksort($value, SORT_STRING); } return $value; } }