Skip to content

Commit 2516d4c

Browse files
committed
Make request classes final and update getParams return types for improved type safety
(cherry picked from commit d6be496)
1 parent 207befd commit 2516d4c

16 files changed

+79
-28
lines changed

src/Schema/JsonRpc/Request.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ public function jsonSerialize(): array
9797
}
9898

9999
/**
100-
* @return array<string, mixed>|null
100+
* @return array<non-empty-string, mixed>|null
101101
*/
102102
abstract protected function getParams(): ?array;
103103
}

src/Schema/Request/CallToolRequest.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
*
2020
* @author Kyrian Obikwelu <[email protected]>
2121
*/
22-
class CallToolRequest extends Request
22+
final class CallToolRequest extends Request
2323
{
2424
/**
2525
* @param string $name the name of the tool to invoke
@@ -58,7 +58,10 @@ protected static function fromParams(?array $params): static
5858
);
5959
}
6060

61-
protected function getParams(): ?array
61+
/**
62+
* @return array{name: string, arguments: array<string, mixed>}
63+
*/
64+
protected function getParams(): array
6265
{
6366
return [
6467
'name' => $this->name,

src/Schema/Request/CompletionCompleteRequest.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
*
2222
* @author Kyrian Obikwelu <[email protected]>
2323
*/
24-
class CompletionCompleteRequest extends Request
24+
final class CompletionCompleteRequest extends Request
2525
{
2626
/**
2727
* @param PromptReference|ResourceReference $ref the prompt or resource to complete
@@ -57,7 +57,13 @@ protected static function fromParams(?array $params): static
5757
return new self($ref, $params['argument']);
5858
}
5959

60-
protected function getParams(): ?array
60+
/**
61+
* @return array{
62+
* ref: PromptReference|ResourceReference,
63+
* argument: array{ name: string, value: string }
64+
* }
65+
*/
66+
protected function getParams(): array
6167
{
6268
return [
6369
'ref' => $this->ref,

src/Schema/Request/CreateSamplingMessageRequest.php

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
*
2424
* @author Kyrian Obikwelu <[email protected]>
2525
*/
26-
class CreateSamplingMessageRequest extends Request
26+
final class CreateSamplingMessageRequest extends Request
2727
{
2828
/**
2929
* @param SamplingMessage[] $messages the messages to send to the model
@@ -86,7 +86,19 @@ protected static function fromParams(?array $params): static
8686
);
8787
}
8888

89-
protected function getParams(): ?array
89+
/**
90+
* @return array{
91+
* messages: SamplingMessage[],
92+
* maxTokens: int,
93+
* preferences?: ModelPreferences,
94+
* systemPrompt?: string,
95+
* includeContext?: string,
96+
* temperature?: float,
97+
* stopSequences?: string[],
98+
* metadata?: array<string, mixed>
99+
* }
100+
*/
101+
protected function getParams(): array
90102
{
91103
$params = [
92104
'messages' => $this->messages,

src/Schema/Request/GetPromptRequest.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
*
2020
* @author Kyrian Obikwelu <[email protected]>
2121
*/
22-
class GetPromptRequest extends Request
22+
final class GetPromptRequest extends Request
2323
{
2424
/**
2525
* @param string $name the name of the prompt to get
@@ -55,7 +55,10 @@ protected static function fromParams(?array $params): static
5555
return new self($params['name'], $arguments);
5656
}
5757

58-
protected function getParams(): ?array
58+
/**
59+
* @return array{name: string, arguments?: array<string, mixed>}
60+
*/
61+
protected function getParams(): array
5962
{
6063
$params = ['name' => $this->name];
6164

src/Schema/Request/InitializeRequest.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
*
2222
* @author Kyrian Obikwelu <[email protected]>
2323
*/
24-
class InitializeRequest extends Request
24+
final class InitializeRequest extends Request
2525
{
2626
/**
2727
* @param string $protocolVersion The latest version of the Model Context Protocol that the client supports. The client MAY decide to support older versions as well.
@@ -59,7 +59,10 @@ protected static function fromParams(?array $params): static
5959
return new self($params['protocolVersion'], $capabilities, $clientInfo);
6060
}
6161

62-
protected function getParams(): ?array
62+
/**
63+
* @return array{protocolVersion: string, capabilities: ClientCapabilities, clientInfo: Implementation}
64+
*/
65+
protected function getParams(): array
6366
{
6467
return [
6568
'protocolVersion' => $this->protocolVersion,

src/Schema/Request/ListPromptsRequest.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
*
1919
* @author Kyrian Obikwelu <[email protected]>
2020
*/
21-
class ListPromptsRequest extends Request
21+
final class ListPromptsRequest extends Request
2222
{
2323
/**
2424
* If provided, the server should return results starting after this cursor.
@@ -40,6 +40,9 @@ protected static function fromParams(?array $params): static
4040
return new self($params['cursor'] ?? null);
4141
}
4242

43+
/**
44+
* @return array{cursor:string}|null
45+
*/
4346
protected function getParams(): ?array
4447
{
4548
$params = [];

src/Schema/Request/ListResourceTemplatesRequest.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
*
1919
* @author Kyrian Obikwelu <[email protected]>
2020
*/
21-
class ListResourceTemplatesRequest extends Request
21+
final class ListResourceTemplatesRequest extends Request
2222
{
2323
/**
2424
* @param string|null $cursor An opaque token representing the current pagination position.
@@ -40,6 +40,9 @@ protected static function fromParams(?array $params): static
4040
return new self($params['cursor'] ?? null);
4141
}
4242

43+
/**
44+
* @return array{cursor:string}|null
45+
*/
4346
protected function getParams(): ?array
4447
{
4548
$params = [];

src/Schema/Request/ListResourcesRequest.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
*
1919
* @author Kyrian Obikwelu <[email protected]>
2020
*/
21-
class ListResourcesRequest extends Request
21+
final class ListResourcesRequest extends Request
2222
{
2323
/**
2424
* @param string|null $cursor An opaque token representing the current pagination position.
@@ -40,6 +40,9 @@ protected static function fromParams(?array $params): static
4040
return new self($params['cursor'] ?? null);
4141
}
4242

43+
/**
44+
* @return array{cursor:string}|null
45+
*/
4346
protected function getParams(): ?array
4447
{
4548
$params = [];

src/Schema/Request/ListRootsRequest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
*
2525
* @author Kyrian Obikwelu <[email protected]>
2626
*/
27-
class ListRootsRequest extends Request
27+
final class ListRootsRequest extends Request
2828
{
2929
public function __construct(
3030
) {

0 commit comments

Comments
 (0)