feat: MCP tools for events (list/get/create/update/delete/done/ack); EventRules shared by /api and manual

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BCrwHHnGCB5XH968Nxokqw
This commit is contained in:
nikita.hohlov
2026-09-05 06:10:41 -03:00
parent 450c165fce
commit ed45a1d516
18 changed files with 711 additions and 56 deletions

View File

@@ -0,0 +1,72 @@
<?php
namespace App\Mcp\Tools;
use App\Ingest\ManualEvents;
use App\Presenters\EventPresenter;
use Illuminate\Contracts\JsonSchema\JsonSchema;
use Laravel\Mcp\Request;
use Laravel\Mcp\ResponseFactory;
class CreateEvent extends AgentTool
{
protected string $name = 'create_event';
protected string $description = 'Поставить пользователю напоминание (источник manual — как кнопка «Добавить» в инбоксе). `due_at`: `YYYY-MM-DD` (весь день), `YYYY-MM-DDTHH:MM` (по поясу пользователя) или со смещением `+02:00` — только если событие привязано к месту. `fire_at` — день, с которого начинать напоминать; по умолчанию за 30 дней до срока. `after_due`: `keep` — после срока долбить, пока не закроют (по умолчанию), `expire` — тихо истечь. Повторяющееся — отдельное событие на каждое вхождение.';
public function __construct(private readonly ManualEvents $manual) {}
public function schema(JsonSchema $schema): array
{
return self::fields($schema, required: true);
}
public function handle(Request $request): ResponseFactory
{
$fields = $request->validate(self::shape(required: true));
return $this->respond(EventPresenter::forUser($this->manual->create($this->user(), $fields)));
}
/**
* Поля события общие для create_event и update_event. Форматы и смысл
* (fire_at не позже срока, deep_link путь или ссылка) проверяет ManualEvents.
*
* @return array<string,mixed>
*/
public static function fields(JsonSchema $schema, bool $required): array
{
$title = $schema->string()->max(200)->description('Заголовок напоминания');
$dueAt = $schema->string()->description('Срок: YYYY-MM-DD, YYYY-MM-DDTHH:MM или со смещением');
return [
'title' => $required ? $title->required() : $title,
'due_at' => $required ? $dueAt->required() : $dueAt,
'subtitle' => $schema->string()->max(200)->description('Подзаголовок'),
'fire_at' => $schema->string()->description('YYYY-MM-DD, день начала подготовки; не позже дня срока'),
'after_due' => $schema->string()->enum(['keep', 'expire'])->description('Что после срока: keep (по умолчанию) или expire'),
'done_label' => $schema->string()->max(64)->description('Подпись кнопки закрытия, по умолчанию «Сделано»'),
'deep_link' => $schema->string()->description('Куда вести из напоминания: относительный путь или http(s)-ссылка'),
];
}
/**
* Форма аргументов: что передано и какого типа. Остальное EventRules через ManualEvents.
*
* @return array<string,list<string>>
*/
public static function shape(bool $required): array
{
$presence = $required ? 'required' : 'sometimes';
return [
'title' => [$presence, 'string', 'max:200'],
'due_at' => [$presence, 'string'],
'subtitle' => ['sometimes', 'nullable', 'string', 'max:200'],
'fire_at' => ['sometimes', 'nullable', 'string'],
'after_due' => ['sometimes', 'string'],
'done_label' => ['sometimes', 'nullable', 'string'],
'deep_link' => ['sometimes', 'nullable', 'string'],
];
}
}