54 lines
1.9 KiB
PHP
54 lines
1.9 KiB
PHP
<?php
|
|
|
|
namespace App\Mcp\Tools;
|
|
|
|
use App\Mcp\Support\KanbanGitMcp;
|
|
use Illuminate\Contracts\JsonSchema\JsonSchema;
|
|
use Illuminate\JsonSchema\Types\Type;
|
|
use Laravel\Mcp\Request;
|
|
use Laravel\Mcp\Response;
|
|
use Laravel\Mcp\ResponseFactory;
|
|
use Laravel\Mcp\Server\Attributes\Description;
|
|
use Laravel\Mcp\Server\Attributes\Name;
|
|
use Laravel\Mcp\Server\Tool;
|
|
use Laravel\Mcp\Server\Tools\Annotations\IsReadOnly;
|
|
|
|
#[Name('get_ticket')]
|
|
#[Description('Get a visible ticket by exactly one of numeric ticket_id or exact full ticket_key (e.g. KAN-67), with project, status, type, priority, assignee, author, field values, and worklog data.')]
|
|
#[IsReadOnly]
|
|
class GetTicket extends Tool
|
|
{
|
|
public function __construct(
|
|
private readonly KanbanGitMcp $kanbanGitMcp,
|
|
) {}
|
|
|
|
public function handle(Request $request): Response|ResponseFactory
|
|
{
|
|
$validated = $request->validate([
|
|
'ticket_id' => ['required_without:ticket_key', 'prohibits:ticket_key', 'integer'],
|
|
'ticket_key' => ['required_without:ticket_id', 'prohibits:ticket_id', 'string', 'regex:/^[A-Z0-9]+-[1-9][0-9]*$/'],
|
|
]);
|
|
|
|
$user = $this->kanbanGitMcp->user($request);
|
|
$ticket = isset($validated['ticket_id'])
|
|
? $this->kanbanGitMcp->ticketForRead($user, (int) $validated['ticket_id'])
|
|
: $this->kanbanGitMcp->ticketForKey($user, $validated['ticket_key']);
|
|
|
|
return Response::structured([
|
|
'data' => $this->kanbanGitMcp->ticketPayload($ticket),
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* @return array<string, Type>
|
|
*/
|
|
public function schema(JsonSchema $schema): array
|
|
{
|
|
return [
|
|
'ticket_id' => $schema->integer()
|
|
->description('Ticket ID. Supply exactly one of ticket_id or ticket_key.'),
|
|
'ticket_key' => $schema->string()->description('Exact full ticket key, e.g. KAN-67. Supply exactly one of ticket_id or ticket_key.'),
|
|
];
|
|
}
|
|
}
|