feat : update MCP tools with calendar fields and add recurrence tools
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
88
src/Mcp/Tool/Task/UpdateTaskRecurrenceTool.php
Normal file
88
src/Mcp/Tool/Task/UpdateTaskRecurrenceTool.php
Normal file
@@ -0,0 +1,88 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Mcp\Tool\Task;
|
||||
|
||||
use App\Enum\RecurrenceType;
|
||||
use App\Repository\TaskRecurrenceRepository;
|
||||
use App\Service\CalDavService;
|
||||
use DateTimeImmutable;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use InvalidArgumentException;
|
||||
use Mcp\Capability\Attribute\McpTool;
|
||||
use Symfony\Bundle\SecurityBundle\Security;
|
||||
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
|
||||
|
||||
use function sprintf;
|
||||
|
||||
#[McpTool(name: 'update-task-recurrence', description: 'Update an existing task recurrence pattern.')]
|
||||
class UpdateTaskRecurrenceTool
|
||||
{
|
||||
public function __construct(
|
||||
private readonly EntityManagerInterface $entityManager,
|
||||
private readonly TaskRecurrenceRepository $taskRecurrenceRepository,
|
||||
private readonly Security $security,
|
||||
private readonly CalDavService $calDavService,
|
||||
) {}
|
||||
|
||||
public function __invoke(
|
||||
int $recurrenceId,
|
||||
?string $type = null,
|
||||
?int $interval = null,
|
||||
?array $daysOfWeek = null,
|
||||
?int $dayOfMonth = null,
|
||||
?int $weekOfMonth = null,
|
||||
?string $endDate = null,
|
||||
?int $maxOccurrences = null,
|
||||
): string {
|
||||
if (!$this->security->isGranted('ROLE_USER')) {
|
||||
throw new AccessDeniedException('Access denied: ROLE_USER required.');
|
||||
}
|
||||
|
||||
$recurrence = $this->taskRecurrenceRepository->find($recurrenceId);
|
||||
if (null === $recurrence) {
|
||||
throw new InvalidArgumentException(sprintf('TaskRecurrence with ID %d not found.', $recurrenceId));
|
||||
}
|
||||
|
||||
if (null !== $type) {
|
||||
$recurrence->setType(RecurrenceType::from($type));
|
||||
}
|
||||
if (null !== $interval) {
|
||||
$recurrence->setInterval($interval);
|
||||
}
|
||||
if (null !== $daysOfWeek) {
|
||||
$recurrence->setDaysOfWeek($daysOfWeek);
|
||||
}
|
||||
if (null !== $dayOfMonth) {
|
||||
$recurrence->setDayOfMonth($dayOfMonth);
|
||||
}
|
||||
if (null !== $weekOfMonth) {
|
||||
$recurrence->setWeekOfMonth($weekOfMonth);
|
||||
}
|
||||
if (null !== $endDate) {
|
||||
$recurrence->setEndDate(new DateTimeImmutable($endDate));
|
||||
}
|
||||
if (null !== $maxOccurrences) {
|
||||
$recurrence->setMaxOccurrences($maxOccurrences);
|
||||
}
|
||||
|
||||
$this->entityManager->flush();
|
||||
|
||||
foreach ($recurrence->getTasks() as $task) {
|
||||
$this->calDavService->syncTask($task);
|
||||
}
|
||||
$this->entityManager->flush();
|
||||
|
||||
return json_encode([
|
||||
'id' => $recurrence->getId(),
|
||||
'type' => $recurrence->getType()?->value,
|
||||
'interval' => $recurrence->getInterval(),
|
||||
'daysOfWeek' => $recurrence->getDaysOfWeek(),
|
||||
'dayOfMonth' => $recurrence->getDayOfMonth(),
|
||||
'weekOfMonth' => $recurrence->getWeekOfMonth(),
|
||||
'endDate' => $recurrence->getEndDate()?->format('Y-m-d'),
|
||||
'maxOccurrences' => $recurrence->getMaxOccurrences(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user