Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/Schema/JsonRpc/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ abstract public static function getMethod(): string;
/**
* @param RequestData $data
*/
public static function fromArray(array $data): self
public static function fromArray(array $data): static
{
if (($data['jsonrpc'] ?? null) !== MessageInterface::JSONRPC_VERSION) {
throw new InvalidArgumentException('Invalid or missing "jsonrpc" version for Request.');
Expand Down Expand Up @@ -68,7 +68,7 @@ public static function fromArray(array $data): self
/**
* @param array<string, mixed>|null $params
*/
abstract protected static function fromParams(?array $params): self;
abstract protected static function fromParams(?array $params): static;

public function getId(): string|int
{
Expand Down Expand Up @@ -97,7 +97,7 @@ public function jsonSerialize(): array
}

/**
* @return array<string, mixed>|null
* @return array<non-empty-string, mixed>|null
*/
abstract protected function getParams(): ?array;
}
9 changes: 6 additions & 3 deletions src/Schema/Request/CallToolRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
*
* @author Kyrian Obikwelu <[email protected]>
*/
class CallToolRequest extends Request
final class CallToolRequest extends Request
{
/**
* @param string $name the name of the tool to invoke
Expand All @@ -36,7 +36,7 @@ public static function getMethod(): string
return 'tools/call';
}

protected static function fromParams(?array $params): Request
protected static function fromParams(?array $params): static
{
if (!isset($params['name']) || !\is_string($params['name'])) {
throw new InvalidArgumentException('Missing or invalid "name" parameter for tools/call.');
Expand All @@ -58,7 +58,10 @@ protected static function fromParams(?array $params): Request
);
}

protected function getParams(): ?array
/**
* @return array{name: string, arguments: array<string, mixed>}
*/
protected function getParams(): array
{
return [
'name' => $this->name,
Expand Down
12 changes: 9 additions & 3 deletions src/Schema/Request/CompletionCompleteRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
*
* @author Kyrian Obikwelu <[email protected]>
*/
class CompletionCompleteRequest extends Request
final class CompletionCompleteRequest extends Request
{
/**
* @param PromptReference|ResourceReference $ref the prompt or resource to complete
Expand All @@ -38,7 +38,7 @@ public static function getMethod(): string
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.');
Expand All @@ -57,7 +57,13 @@ protected static function fromParams(?array $params): 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,
Expand Down
18 changes: 15 additions & 3 deletions src/Schema/Request/CreateSamplingMessageRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
*
* @author Kyrian Obikwelu <[email protected]>
*/
class CreateSamplingMessageRequest extends Request
final class CreateSamplingMessageRequest extends Request
{
/**
* @param SamplingMessage[] $messages the messages to send to the model
Expand Down Expand Up @@ -59,7 +59,7 @@ public static function getMethod(): string
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.');
Expand All @@ -86,7 +86,19 @@ protected static function fromParams(?array $params): 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,
Expand Down
9 changes: 6 additions & 3 deletions src/Schema/Request/GetPromptRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
*
* @author Kyrian Obikwelu <[email protected]>
*/
class GetPromptRequest extends Request
final class GetPromptRequest extends Request
{
/**
* @param string $name the name of the prompt to get
Expand All @@ -36,7 +36,7 @@ public static function getMethod(): string
return 'prompts/get';
}

protected static function fromParams(?array $params): Request
protected static function fromParams(?array $params): static
{
if (!isset($params['name']) || !\is_string($params['name']) || empty($params['name'])) {
throw new InvalidArgumentException('Missing or invalid "name" parameter for prompts/get.');
Expand All @@ -55,7 +55,10 @@ protected static function fromParams(?array $params): Request
return new self($params['name'], $arguments);
}

protected function getParams(): ?array
/**
* @return array{name: string, arguments?: array<string, mixed>}
*/
protected function getParams(): array
{
$params = ['name' => $this->name];

Expand Down
9 changes: 6 additions & 3 deletions src/Schema/Request/InitializeRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
*
* @author Kyrian Obikwelu <[email protected]>
*/
class InitializeRequest extends Request
final class InitializeRequest extends Request
{
/**
* @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.
Expand All @@ -40,7 +40,7 @@ public static function getMethod(): string
return 'initialize';
}

protected static function fromParams(?array $params): Request
protected static function fromParams(?array $params): static
{
if (!isset($params['protocolVersion'])) {
throw new InvalidArgumentException('protocolVersion is required');
Expand All @@ -59,7 +59,10 @@ protected static function fromParams(?array $params): Request
return new self($params['protocolVersion'], $capabilities, $clientInfo);
}

protected function getParams(): ?array
/**
* @return array{protocolVersion: string, capabilities: ClientCapabilities, clientInfo: Implementation}
*/
protected function getParams(): array
{
return [
'protocolVersion' => $this->protocolVersion,
Expand Down
7 changes: 5 additions & 2 deletions src/Schema/Request/ListPromptsRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*
* @author Kyrian Obikwelu <[email protected]>
*/
class ListPromptsRequest extends Request
final class ListPromptsRequest extends Request
{
/**
* If provided, the server should return results starting after this cursor.
Expand All @@ -35,11 +35,14 @@ public static function getMethod(): string
return 'prompts/list';
}

protected static function fromParams(?array $params): Request
protected static function fromParams(?array $params): static
{
return new self($params['cursor'] ?? null);
}

/**
* @return array{cursor:string}|null
*/
protected function getParams(): ?array
{
$params = [];
Expand Down
7 changes: 5 additions & 2 deletions src/Schema/Request/ListResourceTemplatesRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*
* @author Kyrian Obikwelu <[email protected]>
*/
class ListResourceTemplatesRequest extends Request
final class ListResourceTemplatesRequest extends Request
{
/**
* @param string|null $cursor An opaque token representing the current pagination position.
Expand All @@ -35,11 +35,14 @@ public static function getMethod(): string
return 'resources/templates/list';
}

protected static function fromParams(?array $params): Request
protected static function fromParams(?array $params): static
{
return new self($params['cursor'] ?? null);
}

/**
* @return array{cursor:string}|null
*/
protected function getParams(): ?array
{
$params = [];
Expand Down
7 changes: 5 additions & 2 deletions src/Schema/Request/ListResourcesRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*
* @author Kyrian Obikwelu <[email protected]>
*/
class ListResourcesRequest extends Request
final class ListResourcesRequest extends Request
{
/**
* @param string|null $cursor An opaque token representing the current pagination position.
Expand All @@ -35,11 +35,14 @@ public static function getMethod(): string
return 'resources/list';
}

protected static function fromParams(?array $params): Request
protected static function fromParams(?array $params): static
{
return new self($params['cursor'] ?? null);
}

/**
* @return array{cursor:string}|null
*/
protected function getParams(): ?array
{
$params = [];
Expand Down
4 changes: 2 additions & 2 deletions src/Schema/Request/ListRootsRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
*
* @author Kyrian Obikwelu <[email protected]>
*/
class ListRootsRequest extends Request
final class ListRootsRequest extends Request
{
public function __construct(
) {
Expand All @@ -35,7 +35,7 @@ public static function getMethod(): string
return 'roots/list';
}

protected static function fromParams(?array $params): Request
protected static function fromParams(?array $params): static
{
return new self();
}
Expand Down
7 changes: 5 additions & 2 deletions src/Schema/Request/ListToolsRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*
* @author Kyrian Obikwelu <[email protected]>
*/
class ListToolsRequest extends Request
final class ListToolsRequest extends Request
{
/**
* @param string|null $cursor An opaque token representing the current pagination position.
Expand All @@ -35,11 +35,14 @@ public static function getMethod(): string
return 'tools/list';
}

protected static function fromParams(?array $params): Request
protected static function fromParams(?array $params): static
{
return new self($params['cursor'] ?? null);
}

/**
* @return array{cursor:string}|null
*/
protected function getParams(): ?array
{
$params = [];
Expand Down
4 changes: 2 additions & 2 deletions src/Schema/Request/PingRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@
*
* @author Kyrian Obikwelu <[email protected]>
*/
class PingRequest extends Request
final class PingRequest extends Request
{
public static function getMethod(): string
{
return 'ping';
}

protected static function fromParams(?array $params): Request
protected static function fromParams(?array $params): static
{
return new self();
}
Expand Down
11 changes: 7 additions & 4 deletions src/Schema/Request/ReadResourceRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@
*
* @author Kyrian Obikwelu <[email protected]>
*/
class ReadResourceRequest extends Request
final class ReadResourceRequest extends Request
{
/**
* @param string $uri the URI of the resource to read
* @param non-empty-string $uri the URI of the resource to read
*/
public function __construct(
public readonly string $uri,
Expand All @@ -34,7 +34,7 @@ public static function getMethod(): string
return 'resources/read';
}

protected static function fromParams(?array $params): Request
protected static function fromParams(?array $params): static
{
if (!isset($params['uri']) || !\is_string($params['uri']) || empty($params['uri'])) {
throw new InvalidArgumentException('Missing or invalid "uri" parameter for resources/read.');
Expand All @@ -43,7 +43,10 @@ protected static function fromParams(?array $params): Request
return new self($params['uri']);
}

protected function getParams(): ?array
/**
* @return array{uri: non-empty-string}
*/
protected function getParams(): array
{
return [
'uri' => $this->uri,
Expand Down
11 changes: 7 additions & 4 deletions src/Schema/Request/ResourceSubscribeRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@
*
* @author Kyrian Obikwelu <[email protected]>
*/
class ResourceSubscribeRequest extends Request
final class ResourceSubscribeRequest extends Request
{
/**
* @param string $uri the URI of the resource to subscribe to
* @param non-empty-string $uri the URI of the resource to subscribe to
*/
public function __construct(
public readonly string $uri,
Expand All @@ -35,7 +35,7 @@ public static function getMethod(): string
return 'resources/subscribe';
}

protected static function fromParams(?array $params): Request
protected static function fromParams(?array $params): static
{
if (!isset($params['uri']) || !\is_string($params['uri']) || empty($params['uri'])) {
throw new InvalidArgumentException('Missing or invalid "uri" parameter for resources/subscribe.');
Expand All @@ -44,7 +44,10 @@ protected static function fromParams(?array $params): Request
return new self($params['uri']);
}

protected function getParams(): ?array
/**
* @return array{uri: non-empty-string}
*/
protected function getParams(): array
{
return ['uri' => $this->uri];
}
Expand Down
Loading