1<?php
2
3namespace App\Mcp\Tools;
4
5use App\Actions\SearchFlights;
6use Illuminate\JsonSchema\JsonSchema;
7use Laravel\Mcp\Request;
8use Laravel\Mcp\Response;
9use Laravel\Mcp\Server\Tool;
10
11class Search extends Tool
12{
13 protected string $description = 'Search for available flights for the user between two dates.';
14
15 public function schema(JsonSchema $schema): array
16 {
17 return [
18 'query' => $schema->string()
19 ->description('The query to search for flights')
20 ->required(),
21 'from' => $schema->string()
22 ->description('ISO 8601 formatted date string for the search start date')
23 ->required(),
24 'to' => $schema->string()
25 ->description('ISO 8601 formatted date string for the search end date')
26 ->required(),
27 ];
28 }
29
30 public function handle(Request $request, SearchFlights $search): Response
31 {
32 // Validate will return an error if any input values are invalid
33 $validated = $request->validate([
34 'query' => 'required|string|min:1',
35 'from' => 'required|datetime',
36 'to' => 'required|datetime',
37 ]);
38
39 $details = $this->search
40 ->query($validated['query'])
41 ->from($validated['from'])
42 ->to($validated['to']);
43
44 if ($details->unsuccessful()) {
45 return Response::error('Failed to search for flights. Work with the user to correct any errors and retry. Error details: '.$details->error());
46 }
47
48 return Response::text('All done! Share ALL of these details with the user: '.$details->results());
49 }
50}
<?php
namespace App\Mcp\Tools;
use App\Actions\SearchFlights;
use Illuminate\JsonSchema\JsonSchema;
use Laravel\Mcp\Request;
use Laravel\Mcp\Response;
use Laravel\Mcp\Server\Tool;
class Search extends Tool
{
protected string $description = 'Search for available flights for the user between two dates.';
public function schema(JsonSchema $schema): array
{
return [
'query' => $schema->string()
->description('The query to search for flights')
->required(),
'from' => $schema->string()
->description('ISO 8601 formatted date string for the search start date')
->required(),
'to' => $schema->string()
->description('ISO 8601 formatted date string for the search end date')
->required(),
];
}
public function handle(Request $request, SearchFlights $search): Response
{
// Validate will return an error if any input values are invalid
$validated = $request->validate([
'query' => 'required|string|min:1',
'from' => 'required|datetime',
'to' => 'required|datetime',
]);
$details = $this->search
->query($validated['query'])
->from($validated['from'])
->to($validated['to']);
if ($details->unsuccessful()) {
return Response::error('Failed to search for flights. Work with the user to correct any errors and retry. Error details: '.$details->error());
}
return Response::text('All done! Share ALL of these details with the user: '.$details->results());
}
}