Add support for icons and website url (#141)
This commit is contained in:
parent
660f150361
commit
5804ba9773
1 changed files with 279 additions and 22 deletions
|
|
@ -16,14 +16,21 @@ use Mcp\Exception\InvalidArgumentException;
|
|||
/**
|
||||
* Describes the name and version of an MCP implementation.
|
||||
*
|
||||
* @phpstan-import-type IconData from Icon
|
||||
*
|
||||
* @author Kyrian Obikwelu <koshnawaza@gmail.com>
|
||||
*/
|
||||
class Implementation implements \JsonSerializable
|
||||
{
|
||||
/**
|
||||
* @param ?Icon[] $icons
|
||||
*/
|
||||
public function __construct(
|
||||
public readonly string $name = 'app',
|
||||
public readonly string $version = 'dev',
|
||||
public readonly ?string $description = null,
|
||||
public readonly ?array $icons = null,
|
||||
public readonly ?string $websiteUrl = null,
|
||||
) {
|
||||
}
|
||||
|
||||
|
|
@ -31,6 +38,9 @@ class Implementation implements \JsonSerializable
|
|||
* @param array{
|
||||
* name: string,
|
||||
* version: string,
|
||||
* description?: string,
|
||||
* icons?: IconData[],
|
||||
* websiteUrl?: string,
|
||||
* } $data
|
||||
*/
|
||||
public static function fromArray(array $data): self
|
||||
|
|
@ -42,13 +52,30 @@ class Implementation implements \JsonSerializable
|
|||
throw new InvalidArgumentException('Invalid or missing "version" in Implementation data.');
|
||||
}
|
||||
|
||||
return new self($data['name'], $data['version'], $data['description'] ?? null);
|
||||
if (isset($data['icons'])) {
|
||||
if (!\is_array($data['icons'])) {
|
||||
throw new InvalidArgumentException('Invalid "icons" in Implementation data; expected an array.');
|
||||
}
|
||||
|
||||
$data['icons'] = array_map(Icon::fromArray(...), $data['icons']);
|
||||
}
|
||||
|
||||
return new self(
|
||||
$data['name'],
|
||||
$data['version'],
|
||||
$data['description'] ?? null,
|
||||
$data['icons'] ?? null,
|
||||
$data['websiteUrl'] ?? null,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array{
|
||||
* name: string,
|
||||
* version: string,
|
||||
* description?: string,
|
||||
* icons?: Icon[],
|
||||
* websiteUrl?: string,
|
||||
* }
|
||||
*/
|
||||
public function jsonSerialize(): array
|
||||
|
|
@ -62,6 +89,14 @@ class Implementation implements \JsonSerializable
|
|||
$data['description'] = $this->description;
|
||||
}
|
||||
|
||||
if (null !== $this->icons) {
|
||||
$data['icons'] = $this->icons;
|
||||
}
|
||||
|
||||
if (null !== $this->websiteUrl) {
|
||||
$data['websiteUrl'] = $this->websiteUrl;
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue