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:
59
src/Mcp/Tool/Piece/GetPieceTool.php
Normal file
59
src/Mcp/Tool/Piece/GetPieceTool.php
Normal 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'),
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user