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:
Matthieu
2026-03-16 14:38:55 +01:00
parent 4f1e136dc5
commit 2f173e766d
18 changed files with 1277 additions and 0 deletions

View File

@@ -0,0 +1,59 @@
<?php
declare(strict_types=1);
namespace App\Mcp\Tool\Piece;
use App\Mcp\Tool\McpToolHelper;
use App\Repository\PieceRepository;
use Mcp\Capability\Attribute\McpTool;
#[McpTool(
name: 'get_piece',
description: 'Get a single piece by ID with all its details, including typePiece and constructeurs.',
)]
class GetPieceTool
{
use McpToolHelper;
public function __construct(
private readonly PieceRepository $pieces,
) {}
public function __invoke(string $pieceId): array
{
$piece = $this->pieces->find($pieceId);
if (!$piece) {
$this->mcpError('not_found', "Piece not found: {$pieceId}");
}
$constructeurs = [];
foreach ($piece->getConstructeurs() as $c) {
$constructeurs[] = [
'id' => $c->getId(),
'name' => $c->getName(),
];
}
$typePiece = null;
if ($piece->getTypePiece()) {
$typePiece = [
'id' => $piece->getTypePiece()->getId(),
'name' => $piece->getTypePiece()->getName(),
];
}
return $this->jsonResponse([
'id' => $piece->getId(),
'name' => $piece->getName(),
'reference' => $piece->getReference(),
'description' => $piece->getDescription(),
'prix' => $piece->getPrix(),
'typePiece' => $typePiece,
'constructeurs' => $constructeurs,
'createdAt' => $piece->getCreatedAt()->format('Y-m-d H:i:s'),
'updatedAt' => $piece->getUpdatedAt()->format('Y-m-d H:i:s'),
]);
}
}