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

@ -20,7 +20,7 @@ use Mcp\Schema\JsonRpc\Request;
*
* @author Kyrian Obikwelu <koshnawaza@gmail.com>
*/
class SetLogLevelRequest extends Request
final class SetLogLevelRequest extends Request
{
/**
* @param LoggingLevel $level The level of logging that the client wants to receive from the server. The server
@ -37,7 +37,7 @@ class SetLogLevelRequest extends Request
return 'logging/setLevel';
}
protected static function fromParams(?array $params): self
protected static function fromParams(?array $params): static
{
if (!isset($params['level']) || !\is_string($params['level']) || empty($params['level'])) {
throw new InvalidArgumentException('Missing or invalid "level" parameter for "logging/setLevel".');
@ -46,7 +46,10 @@ class SetLogLevelRequest extends Request
return new self(LoggingLevel::from($params['level']));
}
protected function getParams(): ?array
/**
* @return array{level: value-of<LoggingLevel>}
*/
protected function getParams(): array
{
return [
'level' => $this->level->value,