-
Notifications
You must be signed in to change notification settings - Fork 133
Expand file tree
/
Copy pathElicitRequest.php
More file actions
72 lines (63 loc) · 2.13 KB
/
ElicitRequest.php
File metadata and controls
72 lines (63 loc) · 2.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<?php
/*
* This file is part of the official PHP MCP SDK.
*
* A collaboration between Symfony and the PHP Foundation.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Mcp\Schema\Request;
use Mcp\Exception\InvalidArgumentException;
use Mcp\Schema\Elicitation\ElicitationSchema;
use Mcp\Schema\JsonRpc\Request;
/**
* A request from the server to elicit additional information from the user.
*
* The client will present the message and requested schema to the user, allowing them
* to provide the requested information, decline, or cancel the operation.
*
* @author Johannes Wachter <johannes@sulu.io>
*/
final class ElicitRequest extends Request
{
/**
* @param string $message A human-readable message describing what information is needed
* @param ElicitationSchema $requestedSchema The schema defining the fields to elicit from the user
*/
public function __construct(
public readonly string $message,
public readonly ElicitationSchema $requestedSchema,
) {
}
public static function getMethod(): string
{
return 'elicitation/create';
}
protected static function fromParams(?array $params): static
{
if (!isset($params['message']) || !\is_string($params['message'])) {
throw new InvalidArgumentException('Missing or invalid "message" parameter for elicitation/create.');
}
if (!isset($params['requestedSchema']) || !\is_array($params['requestedSchema'])) {
throw new InvalidArgumentException('Missing or invalid "requestedSchema" parameter for elicitation/create.');
}
return new self(
$params['message'],
ElicitationSchema::fromArray($params['requestedSchema']),
);
}
/**
* @return array{
* message: string,
* requestedSchema: ElicitationSchema,
* }
*/
protected function getParams(): array
{
return [
'message' => $this->message,
'requestedSchema' => $this->requestedSchema,
];
}
}