-
-
Notifications
You must be signed in to change notification settings - Fork 234
Expand file tree
/
Copy pathBookSearchProcessor.php
More file actions
38 lines (32 loc) · 975 Bytes
/
Copy pathBookSearchProcessor.php
File metadata and controls
38 lines (32 loc) · 975 Bytes
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
<?php
declare(strict_types=1);
namespace App\State\Processor;
use ApiPlatform\Metadata\Operation;
use ApiPlatform\State\ProcessorInterface;
use App\Entity\Book;
use App\Mcp\Input\BookSearch;
use App\Repository\BookRepository;
/**
* Query parameters (filters) are read from the HTTP query string, which MCP tool calls don't have:
* the search is done from the tool arguments instead.
*
* @implements ProcessorInterface<BookSearch, Book[]>
*/
final readonly class BookSearchProcessor implements ProcessorInterface
{
// Keeps the LLM context small
public const int LIMIT = 30;
public function __construct(
private BookRepository $repository,
) {
}
/**
* @param BookSearch $data
*
* @return Book[]
*/
public function process(mixed $data, Operation $operation, array $uriVariables = [], array $context = []): array
{
return $this->repository->search($data->title, $data->author, self::LIMIT);
}
}