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/Composant/GetComposantTool.php
Normal file
59
src/Mcp/Tool/Composant/GetComposantTool.php
Normal file
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Mcp\Tool\Composant;
|
||||
|
||||
use App\Mcp\Tool\McpToolHelper;
|
||||
use App\Repository\ComposantRepository;
|
||||
use Mcp\Capability\Attribute\McpTool;
|
||||
|
||||
#[McpTool(
|
||||
name: 'get_composant',
|
||||
description: 'Get a single composant by ID with all its details, including typeComposant and constructeurs.',
|
||||
)]
|
||||
class GetComposantTool
|
||||
{
|
||||
use McpToolHelper;
|
||||
|
||||
public function __construct(
|
||||
private readonly ComposantRepository $composants,
|
||||
) {}
|
||||
|
||||
public function __invoke(string $composantId): array
|
||||
{
|
||||
$composant = $this->composants->find($composantId);
|
||||
|
||||
if (!$composant) {
|
||||
$this->mcpError('not_found', "Composant not found: {$composantId}");
|
||||
}
|
||||
|
||||
$constructeurs = [];
|
||||
foreach ($composant->getConstructeurs() as $c) {
|
||||
$constructeurs[] = [
|
||||
'id' => $c->getId(),
|
||||
'name' => $c->getName(),
|
||||
];
|
||||
}
|
||||
|
||||
$typeComposant = null;
|
||||
if ($composant->getTypeComposant()) {
|
||||
$typeComposant = [
|
||||
'id' => $composant->getTypeComposant()->getId(),
|
||||
'name' => $composant->getTypeComposant()->getName(),
|
||||
];
|
||||
}
|
||||
|
||||
return $this->jsonResponse([
|
||||
'id' => $composant->getId(),
|
||||
'name' => $composant->getName(),
|
||||
'reference' => $composant->getReference(),
|
||||
'description' => $composant->getDescription(),
|
||||
'prix' => $composant->getPrix(),
|
||||
'typeComposant' => $typeComposant,
|
||||
'constructeurs' => $constructeurs,
|
||||
'createdAt' => $composant->getCreatedAt()->format('Y-m-d H:i:s'),
|
||||
'updatedAt' => $composant->getUpdatedAt()->format('Y-m-d H:i:s'),
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user