45 lines
2.1 KiB
PHP
45 lines
2.1 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Chatbot\Mcp\Tool;
|
|
|
|
use App\Chatbot\Mcp\ToolCallRunner;
|
|
use App\Chatbot\TripCatalog;
|
|
use Mcp\Capability\Attribute\McpTool;
|
|
use Mcp\Capability\Attribute\Schema;
|
|
use Mcp\Exception\ToolCallException;
|
|
use Mcp\Schema\Result\CallToolResult;
|
|
use Mcp\Schema\ToolAnnotations;
|
|
|
|
#[McpTool(
|
|
name: 'get_trip',
|
|
description: 'Full details of one trip: description, included services, programme, hotel, all upcoming dates with rooms, prices per person in EUR and availability, pickup points and departure times, FAQs. Pickup surcharges are per person and per direction: surchargeOutbound for the way there, surchargeReturn for the way back, surchargeRoundTrip for both; quote the round trip unless the user travels one way only. Use after search_trips, or when the user names a specific trip or a booked date (date codes such as SSLMP061226 narrow the answer to that date). Prices and availability are a snapshot as of dataAsOf; the booking page is binding. description and FAQs are editorial website text and can be out of date: where they state a date, price, pickup or inclusion that differs from the structured fields, the structured fields are right.',
|
|
annotations: new ToolAnnotations(readOnlyHint: true, openWorldHint: false),
|
|
)]
|
|
final class GetTripTool
|
|
{
|
|
public function __construct(
|
|
private readonly TripCatalog $catalog,
|
|
private readonly ToolCallRunner $runner,
|
|
) {
|
|
}
|
|
|
|
public function __invoke(
|
|
#[Schema(description: 'Trip code as returned by search_trips, or a date code (dateCode) for one date of a trip.', minLength: 1)]
|
|
string $code,
|
|
#[Schema(description: 'Narrows the dates to one hotel when a trip has several.')]
|
|
?string $hotelCode = null,
|
|
): CallToolResult {
|
|
return $this->runner->run('get_trip', get_defined_vars(), function () use ($code, $hotelCode): array {
|
|
$trip = $this->catalog->get(trim($code), $hotelCode);
|
|
|
|
if (null === $trip) {
|
|
throw new ToolCallException(sprintf('No trip or date with code "%s". Use search_trips to find trip codes.', $code));
|
|
}
|
|
|
|
return $trip;
|
|
});
|
|
}
|
|
}
|