Files
Inventory/src/Mcp/Tool/Composant/DeleteComposantTool.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.1 KiB
PHP

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