Add meta to addPrompt and addResourceTemplate methods and null coalesce nullable properties (#149)

This commit is contained in:
Bujar Begisholli - C24 2025-11-14 17:11:38 +01:00 • committed by GitHub
commit 7a58ab3f5a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 30 additions and 19 deletions

View file

@ -149,14 +149,14 @@ final class ArrayLoader implements LoaderInterface
} }
$resource = new Resource( $resource = new Resource(
$data['uri'], uri: $data['uri'],
$name, name: $name,
$description, description: $description,
$data['mimeType'], mimeType: $data['mimeType'] ?? null,
$data['annotations'], annotations: $data['annotations'] ?? null,
$data['size'], size: $data['size'] ?? null,
$data['icons'], icons: $data['icons'] ?? null,
$data['meta'], meta: $data['meta'] ?? null,
); );
$registry->registerResource($resource, $data['handler'], true); $registry->registerResource($resource, $data['handler'], true);
@ -189,12 +189,12 @@ final class ArrayLoader implements LoaderInterface
} }
$template = new ResourceTemplate( $template = new ResourceTemplate(
$data['uriTemplate'], uriTemplate: $data['uriTemplate'],
$name, name: $name,
$description, description: $description,
$data['mimeType'], mimeType: $data['mimeType'] ?? null,
$data['annotations'], annotations: $data['annotations'] ?? null,
$data['meta'], meta: $data['meta'] ?? null,
); );
$completionProviders = $this->getCompletionProviders($reflection); $completionProviders = $this->getCompletionProviders($reflection);
$registry->registerResourceTemplate($template, $data['handler'], $completionProviders, true); $registry->registerResourceTemplate($template, $data['handler'], $completionProviders, true);
@ -246,7 +246,13 @@ final class ArrayLoader implements LoaderInterface
!$param->isOptional() && !$param->isDefaultValueAvailable(), !$param->isOptional() && !$param->isDefaultValueAvailable(),
); );
} }
$prompt = new Prompt($name, $description, $arguments, $data['icons'], $data['meta']); $prompt = new Prompt(
name: $name,
description: $description,
arguments: $arguments,
icons: $data['icons'] ?? null,
meta: $data['meta'] ?? null
);
$completionProviders = $this->getCompletionProviders($reflection); $completionProviders = $this->getCompletionProviders($reflection);
$registry->registerPrompt($prompt, $data['handler'], $completionProviders, true); $registry->registerPrompt($prompt, $data['handler'], $completionProviders, true);

View file

@ -379,7 +379,8 @@ final class Builder
/** /**
* Manually registers a resource template handler. * Manually registers a resource template handler.
* *
* @param Handler $handler * @param Handler $handler
* @param array<string, mixed>|null $meta
*/ */
public function addResourceTemplate( public function addResourceTemplate(
\Closure|array|string $handler, \Closure|array|string $handler,
@ -388,6 +389,7 @@ final class Builder
?string $description = null, ?string $description = null,
?string $mimeType = null, ?string $mimeType = null,
?Annotations $annotations = null, ?Annotations $annotations = null,
?array $meta = null,
): self { ): self {
$this->resourceTemplates[] = compact( $this->resourceTemplates[] = compact(
'handler', 'handler',
@ -396,6 +398,7 @@ final class Builder
'description', 'description',
'mimeType', 'mimeType',
'annotations', 'annotations',
'meta',
); );
return $this; return $this;
@ -404,16 +407,18 @@ final class Builder
/** /**
* Manually registers a prompt handler. * Manually registers a prompt handler.
* *
* @param Handler $handler * @param Handler $handler
* @param ?Icon[] $icons * @param ?Icon[] $icons
* @param array<string, mixed>|null $meta
*/ */
public function addPrompt( public function addPrompt(
\Closure|array|string $handler, \Closure|array|string $handler,
?string $name = null, ?string $name = null,
?string $description = null, ?string $description = null,
?array $icons = null, ?array $icons = null,
?array $meta = null,
): self { ): self {
$this->prompts[] = compact('handler', 'name', 'description', 'icons'); $this->prompts[] = compact('handler', 'name', 'description', 'icons', 'meta');
return $this; return $this;
} }