Files
Inventory/src/Mcp/Tool/Machine/DeleteMachineTool.php
Matthieu 2f173e766d feat(mcp) : add CRUD tools for Pieces, Composants, Machines
- 5 tools each: list, get, create, update, delete
- Piece: includes typePiece, constructeurs, prix (string)
- Composant: includes typeComposant, constructeurs, prix (string)
- Machine: includes site (required), constructeurs
- 40 MCP tests pass total

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-16 14:38:55 +01:00

43 lines
1.0 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Mcp\Tool\Machine;
use App\Mcp\Tool\McpToolHelper;
use App\Repository\MachineRepository;
use Doctrine\ORM\EntityManagerInterface;
use Mcp\Capability\Attribute\McpTool;
use Symfony\Bundle\SecurityBundle\Security;
#[McpTool(
name: 'delete_machine',
description: 'Delete a machine by ID. Requires ROLE_GESTIONNAIRE.',
)]
class DeleteMachineTool
{
use McpToolHelper;
public function __construct(
private readonly MachineRepository $machines,
private readonly EntityManagerInterface $em,
private readonly Security $security,
) {}
public function __invoke(string $machineId): array
{
$this->requireRole($this->security, 'ROLE_GESTIONNAIRE');
$machine = $this->machines->find($machineId);
if (!$machine) {
$this->mcpError('not_found', "Machine not found: {$machineId}");
}
$this->em->remove($machine);
$this->em->flush();
return $this->jsonResponse(['deleted' => true, 'id' => $machineId]);
}
}