- 5 tools each: list, get, create, update, delete - McpToolHelper extracted to AbstractApiTestCase for reuse - DashboardStatsToolTest simplified to use base helpers - 22 MCP tests pass Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
43 lines
1.0 KiB
PHP
43 lines
1.0 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Mcp\Tool\Product;
|
|
|
|
use App\Mcp\Tool\McpToolHelper;
|
|
use App\Repository\ProductRepository;
|
|
use Doctrine\ORM\EntityManagerInterface;
|
|
use Mcp\Capability\Attribute\McpTool;
|
|
use Symfony\Bundle\SecurityBundle\Security;
|
|
|
|
#[McpTool(
|
|
name: 'delete_product',
|
|
description: 'Delete a product by ID. Requires ROLE_GESTIONNAIRE.',
|
|
)]
|
|
class DeleteProductTool
|
|
{
|
|
use McpToolHelper;
|
|
|
|
public function __construct(
|
|
private readonly ProductRepository $products,
|
|
private readonly EntityManagerInterface $em,
|
|
private readonly Security $security,
|
|
) {}
|
|
|
|
public function __invoke(string $productId): array
|
|
{
|
|
$this->requireRole($this->security, 'ROLE_GESTIONNAIRE');
|
|
|
|
$product = $this->products->find($productId);
|
|
|
|
if (!$product) {
|
|
$this->mcpError('not_found', "Product not found: {$productId}");
|
|
}
|
|
|
|
$this->em->remove($product);
|
|
$this->em->flush();
|
|
|
|
return $this->jsonResponse(['deleted' => true, 'id' => $productId]);
|
|
}
|
|
}
|