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,55 @@
<?php
declare(strict_types=1);
namespace App\Mcp\Tool\Machine;
use App\Mcp\Tool\McpToolHelper;
use App\Repository\MachineRepository;
use Mcp\Capability\Attribute\McpTool;
#[McpTool(
name: 'list_machines',
description: 'List machines with pagination. Filterable by name or reference.',
)]
class ListMachinesTool
{
use McpToolHelper;
public function __construct(
private readonly MachineRepository $machines,
) {}
public function __invoke(int $page = 1, int $limit = 30, string $search = ''): array
{
$p = $this->paginationParams($page, $limit);
$countQb = $this->machines->createQueryBuilder('m')
->select('COUNT(m.id)')
;
$qb = $this->machines->createQueryBuilder('m')
->select('m.id', 'm.name', 'm.reference', 'm.prix')
->orderBy('m.name', 'ASC')
;
if ('' !== $search) {
$countQb->andWhere('LOWER(m.name) LIKE LOWER(:search) OR LOWER(m.reference) LIKE LOWER(:search)')
->setParameter('search', "%{$search}%")
;
$qb->andWhere('LOWER(m.name) LIKE LOWER(:search) OR LOWER(m.reference) LIKE LOWER(:search)')
->setParameter('search', "%{$search}%")
;
}
$total = (int) $countQb->getQuery()->getSingleScalarResult();
$items = $qb->setFirstResult($p['offset'])
->setMaxResults($p['limit'])
->getQuery()
->getArrayResult()
;
return $this->paginatedResponse($items, $total, $p['page'], $p['limit']);
}
}