- 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>
60 lines
1.6 KiB
PHP
60 lines
1.6 KiB
PHP
<?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'),
|
|
]);
|
|
}
|
|
}
|