-
Notifications
You must be signed in to change notification settings - Fork 129
Expand file tree
/
Copy pathPromptReference.php
More file actions
53 lines (48 loc) · 1.55 KB
/
PromptReference.php
File metadata and controls
53 lines (48 loc) · 1.55 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
<?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\Capability\Registry;
use Mcp\Capability\Formatter\PromptResultFormatter;
use Mcp\Schema\Content\PromptMessage;
use Mcp\Schema\Prompt;
/**
* @phpstan-import-type Handler from ElementReference
*
* @author Kyrian Obikwelu <koshnawaza@gmail.com>
*/
class PromptReference extends ElementReference
{
/**
* @param Handler $handler
* @param array<string, class-string|object> $completionProviders
*/
public function __construct(
public readonly Prompt $prompt,
\Closure|array|string $handler,
bool $isManual = false,
public readonly array $completionProviders = [],
bool $isDiscovered = false,
) {
parent::__construct($handler, $isManual, $isDiscovered);
}
/**
* Formats the raw result of a prompt generator into an array of MCP PromptMessages.
*
* @param mixed $promptGenerationResult expected: array of message structures
*
* @return PromptMessage[] array of PromptMessage objects
*
* @throws \RuntimeException if the result cannot be formatted
* @throws \JsonException if JSON encoding fails
*/
public function formatResult(mixed $promptGenerationResult): array
{
return (new PromptResultFormatter())->format($promptGenerationResult);
}
}