|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace KLP\KlpMcpServer\Services\ToolService\Annotation; |
| 4 | + |
| 5 | +class ToolAnnotation |
| 6 | +{ |
| 7 | + /** |
| 8 | + * @var string A human-readable title for the tool, useful for UI display |
| 9 | + */ |
| 10 | + private string $title; |
| 11 | + |
| 12 | + /** |
| 13 | + * @var bool If true, indicates the tool does not modify its environment |
| 14 | + */ |
| 15 | + private bool $readOnlyHint; |
| 16 | + |
| 17 | + /** |
| 18 | + * @var bool If true, the tool may perform destructive updates (only meaningful when readOnlyHint is false) |
| 19 | + */ |
| 20 | + private bool $destructiveHint; |
| 21 | + |
| 22 | + /** |
| 23 | + * @var bool If true, calling the tool repeatedly with the same arguments has no additional effect (only meaningful when readOnlyHint is false); |
| 24 | + */ |
| 25 | + private bool $idempotentHint; |
| 26 | + |
| 27 | + /** |
| 28 | + * @var bool If true, the tool may interact with an “open world” of external entities; |
| 29 | + */ |
| 30 | + private bool $openWorldHint; |
| 31 | + |
| 32 | + public function __construct( |
| 33 | + ?string $title = null, |
| 34 | + ?bool $readOnlyHint = null, |
| 35 | + ?bool $destructiveHint = null, |
| 36 | + ?bool $idempotentHint = null, |
| 37 | + ?bool $openWorldHint = null |
| 38 | + ) |
| 39 | + { |
| 40 | + $this->title = $title ?? '-'; |
| 41 | + $this->readOnlyHint = $readOnlyHint ?? false; |
| 42 | + $this->destructiveHint = $destructiveHint ?? true; |
| 43 | + $this->idempotentHint = $idempotentHint ?? false; |
| 44 | + $this->openWorldHint = $openWorldHint ?? true; |
| 45 | + } |
| 46 | + |
| 47 | + public function getTitle(): string |
| 48 | + { |
| 49 | + return $this->title; |
| 50 | + } |
| 51 | + |
| 52 | + public function isReadOnlyHint(): bool |
| 53 | + { |
| 54 | + return $this->readOnlyHint; |
| 55 | + } |
| 56 | + |
| 57 | + public function setReadOnlyHint(bool $readOnlyHint): void |
| 58 | + { |
| 59 | + $this->readOnlyHint = $readOnlyHint; |
| 60 | + } |
| 61 | + |
| 62 | + public function isDestructiveHint(): bool |
| 63 | + { |
| 64 | + return $this->destructiveHint; |
| 65 | + } |
| 66 | + |
| 67 | + public function isIdempotentHint(): bool |
| 68 | + { |
| 69 | + return $this->idempotentHint; |
| 70 | + } |
| 71 | + |
| 72 | + public function isOpenWorldHint(): bool |
| 73 | + { |
| 74 | + return $this->openWorldHint; |
| 75 | + } |
| 76 | + |
| 77 | + public function toArray(): array |
| 78 | + { |
| 79 | + return [ |
| 80 | + 'title' => $this->title, |
| 81 | + 'readOnlyHint' => $this->isReadOnlyHint(), |
| 82 | + 'destructiveHint' => $this->isDestructiveHint(), |
| 83 | + 'idempotentHint' => $this->isIdempotentHint(), |
| 84 | + 'openWorldHint' => $this->isOpenWorldHint(), |
| 85 | + ]; |
| 86 | + } |
| 87 | +} |
0 commit comments