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:
74
src/Mcp/Tool/Machine/CreateMachineTool.php
Normal file
74
src/Mcp/Tool/Machine/CreateMachineTool.php
Normal file
@@ -0,0 +1,74 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Mcp\Tool\Machine;
|
||||
|
||||
use App\Entity\Machine;
|
||||
use App\Mcp\Tool\McpToolHelper;
|
||||
use App\Repository\ConstructeurRepository;
|
||||
use App\Repository\SiteRepository;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Mcp\Capability\Attribute\McpTool;
|
||||
use Symfony\Bundle\SecurityBundle\Security;
|
||||
|
||||
#[McpTool(
|
||||
name: 'create_machine',
|
||||
description: 'Create a new machine. siteId is required. prix must be a string (e.g. "12.50"). Requires ROLE_GESTIONNAIRE.',
|
||||
)]
|
||||
class CreateMachineTool
|
||||
{
|
||||
use McpToolHelper;
|
||||
|
||||
public function __construct(
|
||||
private readonly EntityManagerInterface $em,
|
||||
private readonly Security $security,
|
||||
private readonly SiteRepository $sites,
|
||||
private readonly ConstructeurRepository $constructeurs,
|
||||
) {}
|
||||
|
||||
/**
|
||||
* @param string[] $constructeurIds
|
||||
*/
|
||||
public function __invoke(
|
||||
string $name,
|
||||
string $siteId,
|
||||
string $reference = '',
|
||||
string $prix = '',
|
||||
array $constructeurIds = [],
|
||||
): array {
|
||||
$this->requireRole($this->security, 'ROLE_GESTIONNAIRE');
|
||||
|
||||
$site = $this->sites->find($siteId);
|
||||
if (!$site) {
|
||||
$this->mcpError('not_found', "Site not found: {$siteId}");
|
||||
}
|
||||
|
||||
$machine = new Machine();
|
||||
$machine->setName($name);
|
||||
$machine->setSite($site);
|
||||
|
||||
if ('' !== $reference) {
|
||||
$machine->setReference($reference);
|
||||
}
|
||||
if ('' !== $prix) {
|
||||
$machine->setPrix($prix);
|
||||
}
|
||||
|
||||
foreach ($constructeurIds as $cId) {
|
||||
$c = $this->constructeurs->find($cId);
|
||||
if (!$c) {
|
||||
$this->mcpError('not_found', "Constructeur not found: {$cId}");
|
||||
}
|
||||
$machine->addConstructeur($c);
|
||||
}
|
||||
|
||||
$this->em->persist($machine);
|
||||
$this->em->flush();
|
||||
|
||||
return $this->jsonResponse([
|
||||
'id' => $machine->getId(),
|
||||
'name' => $machine->getName(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user