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>
This commit is contained in:
85
src/Mcp/Tool/Machine/UpdateMachineTool.php
Normal file
85
src/Mcp/Tool/Machine/UpdateMachineTool.php
Normal file
@@ -0,0 +1,85 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Mcp\Tool\Machine;
|
||||
|
||||
use App\Mcp\Tool\McpToolHelper;
|
||||
use App\Repository\ConstructeurRepository;
|
||||
use App\Repository\MachineRepository;
|
||||
use App\Repository\SiteRepository;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Mcp\Capability\Attribute\McpTool;
|
||||
use Symfony\Bundle\SecurityBundle\Security;
|
||||
|
||||
#[McpTool(
|
||||
name: 'update_machine',
|
||||
description: 'Update an existing machine. Only provided fields are changed. prix must be a string. Requires ROLE_GESTIONNAIRE.',
|
||||
)]
|
||||
class UpdateMachineTool
|
||||
{
|
||||
use McpToolHelper;
|
||||
|
||||
public function __construct(
|
||||
private readonly MachineRepository $machines,
|
||||
private readonly EntityManagerInterface $em,
|
||||
private readonly Security $security,
|
||||
private readonly SiteRepository $sites,
|
||||
private readonly ConstructeurRepository $constructeurs,
|
||||
) {}
|
||||
|
||||
/**
|
||||
* @param null|string[] $constructeurIds
|
||||
*/
|
||||
public function __invoke(
|
||||
string $machineId,
|
||||
?string $name = null,
|
||||
?string $reference = null,
|
||||
?string $prix = null,
|
||||
?string $siteId = null,
|
||||
?array $constructeurIds = null,
|
||||
): array {
|
||||
$this->requireRole($this->security, 'ROLE_GESTIONNAIRE');
|
||||
|
||||
$machine = $this->machines->find($machineId);
|
||||
|
||||
if (!$machine) {
|
||||
$this->mcpError('not_found', "Machine not found: {$machineId}");
|
||||
}
|
||||
|
||||
if (null !== $name) {
|
||||
$machine->setName($name);
|
||||
}
|
||||
if (null !== $reference) {
|
||||
$machine->setReference($reference);
|
||||
}
|
||||
if (null !== $prix) {
|
||||
$machine->setPrix($prix);
|
||||
}
|
||||
|
||||
if (null !== $siteId) {
|
||||
$site = $this->sites->find($siteId);
|
||||
if (!$site) {
|
||||
$this->mcpError('not_found', "Site not found: {$siteId}");
|
||||
}
|
||||
$machine->setSite($site);
|
||||
}
|
||||
|
||||
if (null !== $constructeurIds) {
|
||||
foreach ($machine->getConstructeurs()->toArray() as $existing) {
|
||||
$machine->removeConstructeur($existing);
|
||||
}
|
||||
foreach ($constructeurIds as $cId) {
|
||||
$c = $this->constructeurs->find($cId);
|
||||
if (!$c) {
|
||||
$this->mcpError('not_found', "Constructeur not found: {$cId}");
|
||||
}
|
||||
$machine->addConstructeur($c);
|
||||
}
|
||||
}
|
||||
|
||||
$this->em->flush();
|
||||
|
||||
return $this->jsonResponse(['id' => $machine->getId(), 'name' => $machine->getName()]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user