Fix return type in abstract methods from self to static (#53)

* Change return type of abstract request methods

* Change return type of `fromParams` method to `static` in request classes

(cherry picked from commit 94799ab66ff60d4b2305aadb6b73aaa4c805221e)

* Make request classes final and update `getParams` return types for improved type safety

(cherry picked from commit d6be496f89cc0e6d30f519792d0dc902685c4178)
This commit is contained in:
Igor Markin 2025-09-09 19:22:29 +03:00 • committed by GitHub
commit 20e789d402
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -21,7 +21,7 @@ use Mcp\Schema\ResourceReference;
*
* @author Kyrian Obikwelu <koshnawaza@gmail.com>
*/
class CompletionCompleteRequest extends Request
final class CompletionCompleteRequest extends Request
{
/**
* @param PromptReference|ResourceReference $ref the prompt or resource to complete
@ -38,7 +38,7 @@ class CompletionCompleteRequest extends Request
return 'completion/complete';
}
protected static function fromParams(?array $params): Request
protected static function fromParams(?array $params): static
{
if (!isset($params['ref']) || !\is_array($params['ref'])) {
throw new InvalidArgumentException('Missing or invalid "ref" parameter for completion/complete.');
@ -57,7 +57,13 @@ class CompletionCompleteRequest extends Request
return new self($ref, $params['argument']);
}
protected function getParams(): ?array
/**
* @return array{
* ref: PromptReference|ResourceReference,
* argument: array{ name: string, value: string }
* }
*/
protected function getParams(): array
{
return [
'ref' => $this->ref,