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