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:
93
src/Mcp/Tool/Piece/UpdatePieceTool.php
Normal file
93
src/Mcp/Tool/Piece/UpdatePieceTool.php
Normal file
@@ -0,0 +1,93 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Mcp\Tool\Piece;
|
||||
|
||||
use App\Mcp\Tool\McpToolHelper;
|
||||
use App\Repository\ConstructeurRepository;
|
||||
use App\Repository\ModelTypeRepository;
|
||||
use App\Repository\PieceRepository;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Mcp\Capability\Attribute\McpTool;
|
||||
use Symfony\Bundle\SecurityBundle\Security;
|
||||
|
||||
#[McpTool(
|
||||
name: 'update_piece',
|
||||
description: 'Update an existing piece. Only provided fields are changed. prix must be a string. Requires ROLE_GESTIONNAIRE.',
|
||||
)]
|
||||
class UpdatePieceTool
|
||||
{
|
||||
use McpToolHelper;
|
||||
|
||||
public function __construct(
|
||||
private readonly PieceRepository $pieces,
|
||||
private readonly EntityManagerInterface $em,
|
||||
private readonly Security $security,
|
||||
private readonly ModelTypeRepository $modelTypes,
|
||||
private readonly ConstructeurRepository $constructeurs,
|
||||
) {}
|
||||
|
||||
/**
|
||||
* @param null|string[] $constructeurIds
|
||||
*/
|
||||
public function __invoke(
|
||||
string $pieceId,
|
||||
?string $name = null,
|
||||
?string $reference = null,
|
||||
?string $description = null,
|
||||
?string $prix = null,
|
||||
?string $modelTypeId = null,
|
||||
?array $constructeurIds = null,
|
||||
): array {
|
||||
$this->requireRole($this->security, 'ROLE_GESTIONNAIRE');
|
||||
|
||||
$piece = $this->pieces->find($pieceId);
|
||||
|
||||
if (!$piece) {
|
||||
$this->mcpError('not_found', "Piece not found: {$pieceId}");
|
||||
}
|
||||
|
||||
if (null !== $name) {
|
||||
$piece->setName($name);
|
||||
}
|
||||
if (null !== $reference) {
|
||||
$piece->setReference($reference);
|
||||
}
|
||||
if (null !== $description) {
|
||||
$piece->setDescription($description);
|
||||
}
|
||||
if (null !== $prix) {
|
||||
$piece->setPrix($prix);
|
||||
}
|
||||
|
||||
if (null !== $modelTypeId) {
|
||||
if ('' === $modelTypeId) {
|
||||
$piece->setTypePiece(null);
|
||||
} else {
|
||||
$modelType = $this->modelTypes->find($modelTypeId);
|
||||
if (!$modelType) {
|
||||
$this->mcpError('not_found', "ModelType not found: {$modelTypeId}");
|
||||
}
|
||||
$piece->setTypePiece($modelType);
|
||||
}
|
||||
}
|
||||
|
||||
if (null !== $constructeurIds) {
|
||||
foreach ($piece->getConstructeurs()->toArray() as $existing) {
|
||||
$piece->removeConstructeur($existing);
|
||||
}
|
||||
foreach ($constructeurIds as $cId) {
|
||||
$c = $this->constructeurs->find($cId);
|
||||
if (!$c) {
|
||||
$this->mcpError('not_found', "Constructeur not found: {$cId}");
|
||||
}
|
||||
$piece->addConstructeur($c);
|
||||
}
|
||||
}
|
||||
|
||||
$this->em->flush();
|
||||
|
||||
return $this->jsonResponse(['id' => $piece->getId(), 'name' => $piece->getName()]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user