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:
parent
4b667327e7
commit
20e789d402
1 changed files with 97 additions and 46 deletions
|
|
@ -23,7 +23,7 @@ use Mcp\Schema\ModelPreferences;
|
|||
*
|
||||
* @author Kyrian Obikwelu <koshnawaza@gmail.com>
|
||||
*/
|
||||
class CreateSamplingMessageRequest extends Request
|
||||
final class CreateSamplingMessageRequest extends Request
|
||||
{
|
||||
/**
|
||||
* @param SamplingMessage[] $messages the messages to send to the model
|
||||
|
|
@ -59,7 +59,7 @@ class CreateSamplingMessageRequest extends Request
|
|||
return 'sampling/createMessage';
|
||||
}
|
||||
|
||||
protected static function fromParams(?array $params): Request
|
||||
protected static function fromParams(?array $params): static
|
||||
{
|
||||
if (!isset($params['messages']) || !\is_array($params['messages'])) {
|
||||
throw new InvalidArgumentException('Missing or invalid "messages" parameter for sampling/createMessage.');
|
||||
|
|
@ -86,7 +86,19 @@ class CreateSamplingMessageRequest extends Request
|
|||
);
|
||||
}
|
||||
|
||||
protected function getParams(): ?array
|
||||
/**
|
||||
* @return array{
|
||||
* messages: SamplingMessage[],
|
||||
* maxTokens: int,
|
||||
* preferences?: ModelPreferences,
|
||||
* systemPrompt?: string,
|
||||
* includeContext?: string,
|
||||
* temperature?: float,
|
||||
* stopSequences?: string[],
|
||||
* metadata?: array<string, mixed>
|
||||
* }
|
||||
*/
|
||||
protected function getParams(): array
|
||||
{
|
||||
$params = [
|
||||
'messages' => $this->messages,
|
||||
|
|
|
|||
Loading…
Reference in a new issue